User Tools

Site Tools


Site Tools

Script to reverse back to ethx NIC names

#!/bin/bash
 
interfaces=($(ip addr | grep -i broadcast | awk -F ':' '{ print $2 }' | tr -d ' \t'))
macadresses=($(ip addr | grep -i ether | awk -F ' ' '{ print $2 }'))
numberofinterfaces=$(ip addr | grep -i ether | awk -F ' ' '{ print $2 }' | wc -l)
 
sed -i 's/\ rhgb\ quiet/\ net.ifnames=0\ rhgb\ quiet/g' /etc/default/grub
grub2-mkconfig -o /boot/grub2/grub.cfg
 
rm -f /etc/udev/rules.d/70-persistent-net.rules
for (( ethnum=0; ethnum<$numberofinterfaces; ethnum++))
do
  echo 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="'${macadresses[$ethnum]}'", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth'$ethnum'"' >> /etc/udev/rules.d/70-persistent-net.rules
  mv /etc/sysconfig/network-scripts/ifcfg-${interfaces[$ethnum]} /etc/sysconfig/network-scripts/ifcfg-eth$ethnum
  sed -i "s/${interfaces[$ethnum]}/eth$ethnum/g" /etc/sysconfig/network-scripts/ifcfg-eth$ethnum
done