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.
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:
And in both the contents is the same and it looks like:
Code:
# Please read /usr/share/doc/initscripts-*/sysconfig.txt
# for the documentation of these parameters.
GATEWAY=10.10.10.254
TYPE=Ethernet
DEVICE=eth0:2
BOOTPROTO=none
NETMASK=255.0.0.0
IPADDR=10.10.10.10.
USERCTL=no
IPV6INIT=no
ONPARENT=yes
PEERDNS=yes
Well, I want, I need to create a network alias not by hand, not by using an interactive program like "system-config-network", but using a non-interactive, command line based program.
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.
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).
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.