Last active
January 4, 2016 20:49
-
-
Save ilyaevseev/4d4299da2f2eaa1f43ee to your computer and use it in GitHub Desktop.
Under Linux, changing a NIC macaddress causes creation of empty eth1 and failure of all eth0-related settings. This init script renames eth1 back to eth0. Works under Redhat/CentOS.
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/sh | |
# | |
# fixeth0 Rebind NIC from eth1 to eth0 | |
# | |
# chkconfig: 2345 09 91 | |
# description: After changing single NIC, automatically rebind it from eth1 back to eth0. | |
### BEGIN INIT INFO | |
# Provides: fixeth0 | |
# Required-Start: $local_fs | |
# Required-Stop: $local_fs | |
# Short-Description: Rebind NIC from eth1 to eth0 | |
# Description: After changing single NIC, automatically rebind it from eth1 back to eth0. | |
### END INIT INFO | |
# Based on http://superuser.com/a/598166 | |
INSTALL_ME_SO=' | |
wget -O /etc/init.d/fixeth0 https://gist.github.com/ilyaevseev/4d4299da2f2eaa1f43ee/raw/c33f71788ee103c35e4e013571781fcc99b851e3/fixeth0.sh && | |
chmod +x /etc/init.d/fixeth0 && | |
chkconfig fixeth0 --add && | |
chkconfig fixeth0 on | |
' | |
test "$1" = "start" || exit 0 | |
config="/etc/udev/rules.d/70-persistent-net.rules" | |
ethcfg="/etc/sysconfig/network-scripts/ifcfg-eth" | |
test -s /sys/class/net/eth0/address || exit # eth0 is live? exit.. | |
grep -q 'eth1' "$config" || exit # no udev record for eth1? exit.. | |
test -s "${ethcfg}1" && exit # eth1 has network config? exit.. | |
sed -i '/eth0/d' "$config" | |
sed -i 's/eth1/eth0/g' "$config" | |
MACADDR=`awk -F',' '/eth0/ {print $4}' "$config" | awk -F'"' '{print $2}'` | |
#echo MACADDR = $MACADDR | |
sed -ie 's/HWADDR=".*"/HWADDR="'$MACADDR'"/' "${ethcfg}0" | |
/sbin/start_udev | |
#/sbin/service network restart | |
## END ## |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment