ip addr add on boot

Latest response

I am using "ip addr add 30.1.1.200/24 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?

Responses

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).

 

Dear

 

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.

 

 

/etc/sysconfig/network-scripts/

 

2. vi ifcfg-eth0

 

                set ONBOOT=yes

 

  save+exit

 

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?
https://access.redhat.com/kb/docs/DOC-8695

 

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.

 

Cheers!

This works well:

 

#!/bin/sh
#
# add secondary IP addresses to dev rhevm

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

Thanks