LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices


Reply
  Search this Thread
Old 09-15-2009, 01:41 PM   #1
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,499
Blog Entries: 2

Rep: Reputation: 68
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 ?

Last edited by marozsas; 09-15-2009 at 01:44 PM.
 
Old 09-15-2009, 04:02 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
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.
 
Old 09-16-2009, 06:38 AM   #3
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,499

Original Poster
Blog Entries: 2

Rep: Reputation: 68
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,
 
Old 09-16-2009, 09:12 AM   #4
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
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.
 
Old 09-16-2009, 09:27 AM   #5
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,499

Original Poster
Blog Entries: 2

Rep: Reputation: 68
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,
 
Old 09-16-2009, 01:31 PM   #6
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to add multiple ip address to an interface rasanth Linux - Networking 1 03-07-2007 04:10 PM
How to automatically add an address to the address book in Thunderbird royeo Linux - Newbie 2 09-04-2006 03:51 PM
Add a new Ip address to the NIC hcclnoodles Linux - Networking 4 08-19-2004 10:43 AM
Add another IP address to an Interface hcclnoodles Linux - Software 1 08-19-2004 02:50 AM
RH9, How to add another IP Address in CLI praefex Linux - Networking 3 11-19-2003 11:59 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat

All times are GMT -5. The time now is 04:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration