how to add a new IP address ?
Hi,
Using system-config-network I can add a new IP address (network alias) to a RH/CentOS machine, for example, eth0:1. This procedure creates at least, 3 files: Code:
/etc/sysconfig/network-scripts/ifcfg-eth0:1 Code:
# Please read /usr/share/doc/initscripts-*/sysconfig.txt Alternatively, I can create the proper file on the 3 locations above but I was wondering if there are a right interface (API) to do that. I found system-config-network-cmd but looks like it can only list/export. I was not able to import anything using it neither find a manual page of it. any thoughts ? PS: And after creating this alias, I want to activate it. What is the procedure to activate such network alias ? |
Actually you can do it just by populating the file in /etc/sysconfig/network-scripts: /etc/sysconfig/network-scripts/ifcfg-eth0:1
I added 30 aliases to a box without creating the files in the other two directories and they been running fine. You would have to script it to add the information to each file. All you need in each of the files is: DEVICE=eth0:<alias> IPADDR=x.x.x.x ONBOOT=yes So eth0:1 would be (for example): DEVICE=eth0:1 IPADDR=192.168.9.10 ONBOOT=yes And eth0:2 would be (for example): DEVICE=eth0:1 IPADDR=192.168.9.11 ONBOOT=yes To bring up an interface you just type "ifup <interface>" (e.g. ifup eth0:1. Note that the aliases will only work if the primary interface is up. Scripting it to write each of those files should be fairly easy. |
Thanks for the hint about creating the file in just one location, jlightner !
I will do that. In fact I already did, but in openSuSE, and now I am migrating to CentOS and I need to redo. In openSuSE is similar. I need to create a single file at /etc/sysconfig/network/ifcfg-eth-id-${mac} where $mac is the MAC address of the interface I want to bound the IP. It is a shame this is not a standard or it not have a standard program to do that, like "service" or "chkconfig" to start and configure services at boot time. Anyway, thanks for the help, |
There is a service - It's called "network". However it restarts everything not just your new aliases. ifup is designed to start one interface (ifdown stops one) at a time. Those are scripts by the way so you can look at them to see what they do and maybe even come up with a derivative that does what you want.
"service network restart" - For obvious reasons its best to do that from the console though on occasion it has actually been fast enough to work from within an ssh session into the box. |
I just figure out the 3 files are in fact, hard links.
And the 3 files (hard links) are necessary, otherwise it will broke "system-config-network" with the message "eth0:1, Device not specified or alias not a number!" (at least in CentOS 5.3). cheers, |
Probably required just for that utility - I never use it myself. Thanks for the info - now I'll know to go ahead and make the links even if I don't use them.
|
All times are GMT -5. The time now is 01:18 AM. |