Created
September 25, 2017 08:37
-
-
Save Disassembler0/3be534e31eadc8b5434c2b90bc07d66e to your computer and use it in GitHub Desktop.
Simple NIC setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function get_ipv4 { | |
ip address show ${1} | grep 'inet ' | awk '{print $2}' | cut -d/ -f1 | |
} | |
function get_mac { | |
ip address show ${1} | grep 'link/ether' | awk '{print $2}' | |
} | |
echo "List of network interfaces found in the system:" | |
for IFACE in $(ls /sys/class/net | grep -v lo); do | |
echo "${IFACE} - MAC: $(get_mac ${IFACE}) - IP: $(get_ipv4 ${IFACE})" | |
done | |
echo | |
echo "Enter the interface name to use as primary (eg. eth2 or ens33) and press [Enter]:" | |
read IFACE | |
cat <<EOF >/etc/network/interfaces | |
auto lo | |
iface lo inet loopback | |
auto ${IFACE} | |
iface ${IFACE} inet dhcp | |
iface ${IFACE} inet6 auto | |
EOF | |
echo "Restarting DHCP client..." | |
systemctl restart networking | |
echo "Done. New IP of interface ${IFACE} is $(get_ipv4 ${IFACE})" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment