Showing posts with label virtual ip. Show all posts
Showing posts with label virtual ip. Show all posts

Monday, January 16, 2012

Ubuntu 11.10 Virtual NIC IP Workaround

The normal way of adding virtual nic ip is by setting it in /etc/network/interfaces, like the following:

auto eth0:0
iface eth0:0 inet static
address 192.168.0.111
netmask 255.255.255.0
broadcast 192.168.0.255
gateway 192.168.0.1

Unfortunately, there is a known bug which prevent such configuration to work. Take a look here.

The first workaround that I figured out is by using /etc/rc.local script.
Add the following lines before exit(0) inside that script:
#################################
sleep 4  # This due to concurrency, set some delay in order for the networking to be set up properly first
ifconfig eth0:0 192.168.0.111 netmask 255.255.255.0 broadcast 192.168.0.255
# or use below command to replace above ifconfig command
# ip addr add 192.168.0.111 dev eth0
#################################

The second workaround is, IMHO, better. No sleep hack necessary, since upstart script is used instead of rc.local script.
Create /etc/init/network-interface-virtual.conf (or use different name as you like), with the following lines inside:
#################################
description "configure virtual network device"
respawn
console none

start on (net-device-up IFACE=eth0)
stop on runlevel [!12345]

script
exec ip addr add 192.168.0.111 dev eth0
# or use ifconfig command below
# ifconfig eth0:0 192.168.0.111 netmask 255.255.255.0 broadcast 192.168.0.255
end script
#################################

Reboot your system if necessary and everything is set and the virtual nic ip is ready to use. Oh, one more thing. There is also a bug (I think), which makes the virtual nic ip not showing with the ifconfig -a command. Just ping the virtual ip address to test whether it's up or not.