ip addr add on boot

Latest response

I am using "ip addr add dev eth0" to add an IP address to an ethernet device in order to listen on a second address.   This works fine. 


The question is: how do I setup this on boot?


The options I understand are:


1) /etc/rc.local - put the ip addr add command here

2) create an ifcfg-eth0:0 alias


Neither of these seems to be exactly what I have been looking for.   I would have thought that ifcfg-eth0 could have had some variable like IPADDR_SECOND or something.


Anyone know what is the best way to do this?


With RedHat, you create file in /etc/sysconfig/network-scripts for each interface, virtual interface, bonded interface and/or VLAN'ed interface. 


For example to set up the first IP alias on eth0 (eth0:1) you'd set up /etc/sysconfig/ifcfg-eth0:1. You'd make sure that your DEVICE parameter was set to "eth0:1" and then add your other parameters as appropriate (e.g. NETMASK, BROADCAST, etc.). You can then use the ifup/ifdown commands to manipulate the interface (which is, essentially, what RedHat does at init state changes such as bootup or shutdown).




So far I understand fro your question is you IP address is not working on boot. If not may be I could not get the question clearly.





2. vi ifcfg-eth0


                set ONBOOT=yes




Hope it will work.

Hello Paul .

Besides option 1 and 2 that you already pointed you could use ifup-post .

Check this out.

- How do I run a script or program immediately after my network interface goes up?


This is almost samy thing of add 'ip' command to rc.local, but the good thing is if you need to restart the network the second IP will be up too.



This works well:


# add secondary IP addresses to dev rhevm

if [ "$1" = "rhevm" ]; then
  exec /sbin/ip addr add   dev ${1}
  exec /sbin/ip addr add   dev ${1}