[SOLVED] How to get persistent network settings when changing hardware
Red HatThis forum is for the discussion of Red Hat Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How to get persistent network settings when changing hardware
I have a situation where we spare hard drives for a group of computers. These computers are all basically the same, so the spare hard drives are all from the same image.
The only tricky part is the network settings. The normal way of configuring them is to use the system-config-network utility. The problem is, the configured devices are tied to MAC addresses. When a spare drive is inserted into one of the computers, it sees NICs with different MACs, so creates new devices. In the Network utility, you see that the old devices became eth0.bak, eth1.bak, etc. The new eth0, eth1 then have default configurations.
I would like to be able to put a spare drive in any computer without the end user having to go in and set up all the network settings every time. So does anyone have any suggestions?
The only solution I have come up with is this. I disable the network service. I then add the following lines in /etc/rc.d/rc.local for each NIC:
ifconfig eth0 xxx.xxx.xxx.xxx umask xxx.xxx.xxx.xxx
ifconfig eth0 up
This works because the new devices are always still eth0, eth1, etc. The drawbacks are that unless you know its there, you have no idea how the network is being configured. Also, if an IP address needs to change, a regular user does not have permissions to change it.
On my Debian system, udev creates rules for the network cards under /etc/udev/rule.d/70-persistent-net.rules
Code:
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.
# PCI device 0x8086:/sys/devices/pci0000:00/0000:00:19.0 (e1000e)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="xx:xx:xx:xx:xx:xx", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
So if I were to bring a clone of my HDD to an identical system, udev would see that eth0 is already taken by another MAC, and assign eth1 to the new MAC. So upon boot maybe you could remove the existing rule?
I'm not sure that will help. It's not so much the device name that is the problem, but the fact that it creates a new device, and that new device then has default settings instead of my configured ones. Essentially, I need it to update the /etc/sysconfig/network-scripts/ifcfg-eth0 file with a new MAC, instead of creating a new file with default settings. Or, maybe if there was a way to alter the default config?
Then, yourMacAddrScript must look like the line assigning the MAC to $HWADDR. Not sure how to find the MAC using a script that must run before the ethernet startup/configuration runs, but ethttool might help. Whatever it is, it just has to generate the one line in yourMacAddrScript. Getting the script to run before the network configuration happens should be simple enough using the standard startup scripting system.
theNbombr, right track, but it's actually easier than that. After tinkering around today, I figured out that the ifcfg-eth0 file doesn't need the HWADDDR= line at all! If you comment it out, then it just works with whatever eth0 is, no matter what eth0's MAC is. I can move the drive to a different computer, and it still works, because it doesn't create a new ifcfg-eth0 file, because it doesn't care what the MAC is!
Taking it a step further, this is can be done from the system-config-network utility as well. On the "Hardware Device" tab for eth0, just uncheck "Bind to MAC Address". (This deletes the HWADDR line from the ifcfg file).
I think this is the "right" way to do it, and is much simpler than I imagined. I just didn't know about it!
I haven't found them to be arbitrary. The hardware I'm working with has 4 ethernet ports. They seem to always be eth0 to eth3, in physical order, on each machine.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.