ip addr add on boot
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).
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!