configuring more than one ip for an inteface pemanently (linux)

Hi
does anybody know how we can add more than one ip for NIC(in Redhat Linux 7.2)?
i usually do it by using this command
ifconfig eth0 add <ip addresss> netmask <..............> up

or ;

ip address add 192.168.20.1/24 dev eth0

or
adding it manually to file in /etc/sysconfig/network-scripts
but their is no ifcfg-eth0 !!!!!
-------------------------------------------------------------
and it works cuz i can ping it from another machine

BUT when i reboot the machine all of the are gone.
I'm looking for way that these IPs can remain on the interface even after
reboot or shut down

is there anyone who can help me up?

Which vendor/version of Linux? Under RedHat the information goes into a config file in /etc/sysconfig/network-scripts.

thanx

i found the file in /etc/sysconfig/networking/devices/ifcfg-eth0

and here i can add the new ip and after reboot everything is ok.

but i don't know how i can have it changed without rebooting and
more important that that i want to add more than one ip for this
interface.
Can anyone help me up?

What you need to do is to add an alias to the interface, in order to do that, do the following. First go to the file /etc/sysconfig/networking/devices/ifcfg-eth0 and add the following lines:

DEVICE=eth0:1
ONBOOT=yes
BOOTPROTO=static
IPADDR= xxx.xxx.xxx.xxx
NETMASK=xxx.xxx.xxx.xxx
GATEWAY=xxx.xxx.xxx.xxx
TYPE=Ethernet
USERCTL=no
NETWORK=xxx.xxx.xxx.xxx
BROADCAST=xxx.xxx.xxx.xxx
PEERDNS=no
Where xxx.xxx.xxx.xxx put the apropriate addresses for your computer. After doing so go to the directory /etc/rc.d/init.d and type ./network stop; ./network start. That will initiate the new configurations. You can add as many IP addresses as you want by just doing the procedures above and changing the DEVICE:eth0:x from 1 to 2,3,... etc. and also by changing the IP address.

Thank you very much

It really worked . and the idea is very reasonble.
You know what I did to have more than 2 IPs?

I put the following commands in the start up (rc.local):
ip address add x.x.x.x/x dev eth0

and it works but it's a bit .... I don't like it.

Thanks anyway

You re wellcome. You can also add an alias to your interface with ifconfig. You can write ifconfig eth0:x <IP ADDRESS> netmask <NETMASK>. But then you must add with route a default gateway to your routing table for the new IP address.

Thank YOU again
yeah I tried it ,cool ....

But it is not perminantt after network stop / start
They'll be gone.

Could you please tell me why the hell do we have so many places to
assign IPs,gateways,... and which one's the main file or ....

thanx

Yeah after network stop and start the configurations are all gone. That's probably because ifconfig uses ioctl. I made a simple programm that uses ioctl for changing the IP, I can give it to you if you want, but after rebooting the new configurations are gone.
To tell you the truth I do not know why there are so many files doing the same thing. Probably because these configurations are vendor dependent. (Especially red hat tends to change everything, I still don't understand why they do not provide the kernel source code in /usr/src/linux)

The RedHat team uses a tool called linuxconf to configure the system, which is a control panel for all system services. Under te section Config/Networking/Server Tasks there is a line named IP Aliases for virtual hosts, where you can select the interface for which you want to make an alias. All you have to do is to add the IP address and the netmask and you're done. Changes are active just after reboot.

hi,
I have the same request on a SUN server, Can I do that safely ? :stuck_out_tongue:
but where is the magic file to modify ?

Yeah if you read the command above i think they work but maybe with a little bit of difference (see the man pages)
but the file you're looking for it to edit manually is not called (eth0)
I've forgotten the real name but ...
It should be something like prg0 or ....

ok thx, the /etc/sysconfig/networking/devices/ifcfg-eth0 files doesn't exist on my OS that's why i found an other way to resolv it.

for my Sun Server with Solaris 8 :

I added an entry in /etc/hosts
xxx.xxx.xxx.xxx 'hostname'2

I already had the /etc/hostname.eri0
I created /etc/hostname.eri0:1
with in this file the 'hostname'2

and it's working :smiley:

there is another very good tool on redhat linux to configure your networking. "netconf" it's very simple to use.