Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Automatically configures netctl to use wired DHCP with a chosen interface.
#!/bin/bash
interfaces=$(ip link | cut -d ":" -f 1-2 | sed 'n; d')
echo -e "Available Interfaces:\n$interfaces"
read -p "Please choose an interface: " choice
if [ "$choice" -ge 1 -a "$choice" -le $(echo "$interfaces" | wc -l) ]; then
interface=$(echo "$interfaces" | sed "${choice}q;d" | cut -d ":" -f 2 | sed 's/ //g')
sed "s/eth0/$interface/g" /etc/netctl/examples/ethernet-dhcp > /etc/netctl/ethernet-dhcp
echo "Now enabling the $interface interface..."
netctl start ethernet-dhcp
if [ $? -eq 0 ]; then
echo "Success!"
else
echo "An error occurred. Check the file '/etc/netctl/ethernet-dhcp' for issues."
fi
else
echo "Please enter the number prefixing the desired interface."
fi
@mohwazn

This comment has been minimized.

Copy link

mohwazn commented Sep 3, 2017

#0592544345

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.