LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Red Hat (https://www.linuxquestions.org/questions/red-hat-31/)
-   -   how to add a new IP address ? (https://www.linuxquestions.org/questions/red-hat-31/how-to-add-a-new-ip-address-755415/)

marozsas 09-15-2009 01:41 PM

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
/etc/sysconfig/networking/devices/ifcfg-eth0:1
/etc/sysconfig/networking/profiles/default/ifcfg-eth0:1

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 ?

MensaWater 09-15-2009 04:02 PM

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.

marozsas 09-16-2009 06:38 AM

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,

MensaWater 09-16-2009 09:12 AM

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.

marozsas 09-16-2009 09:27 AM

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,

MensaWater 09-16-2009 01:31 PM

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.