network fixes for centos 7

centos 7 has a couple of changes that make it a pain in the neck for seasoned system administrators. first, it does not come with the venerable ifconfig command, and second, it uses an arcane naming convention for the network interfaces that make automation difficult. instead of the usual eth0, eth1, etc. names, the interfaces have names like en0p3. o joy.

fix the network interface name

this involves two changes and a reboot. (sigh). the following assumes that one wants to restore the traditional name, eth0.

  • create a rule file for udev:

mac=`cat /sys/class/net/e*/address`  # should be something like: 08:00:27:46:ba:b8
cat > /etc/udev/rules.d/70-persistent-net.rules <<EOM
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="$mac", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
  • create a network config for the new interface:

cd /etc/sysconfig/network-scripts
sed '/^NAME=/s/=.*/=eth0/;/^ONBOOT/s/no/yes/' ifcfg-enp03 > ifcfg-eth0
  • turn off the weird kernel naming feature. this must be done at boot, so one must modify the grub configuration. note that while i’m there, i also get rid of the silly default params:

mv /etc/default/grub /etc/default/  # backup
sed '/GRUB_CMDLINE_LINUX/s/=.*/="net.ifnames=0"/' /etc/default/ > /etc/default/grub
grub2-mkconfig -o /boot/grub2/grub.cfg
  • reboot

install some familiar tools (like ifconfig)

after the reboot, we should have networking, so yum should now work…

yum install -y net-tools
yum install -y vim