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. 

Ubuntu 11.10 and Realtek (RTL8111/RTL8168) NIC driver problem

Finally, I figured out the problem that I had with network connection. The problem was with Realtek (RTL8111/RTL8168) NIC, which somehow detected differently by ubuntu 11.10 and uses r8169 kernel module driver.
To be sure, do check your NIC using:
$ sudo lscpi

You should see something like ...Realtek (RTL8111/RTL8168)...
Next step is to remove the r8169 module using:
$ rmmod r8169

If necessary install build-essential, etc:
$ sudo apt-get install build-essential linux-headers-$(uname -r) linux-source

Then, download the proper driver for that particular NIC from here. The file name should be something like r8168-8.027.00.tar.bz2.
Uncompress the file, and run the shell script file, as root:
# ./autorun.sh

Check the newly compiled driver:

$ sudo lsmod | grep r8168
$ ifconfig -a


Blacklist the r8169 module driver, by editing /etc/modprobe.d/blacklist.conf, add:
#blacklist r8169 driver
blacklist r8169

Reboot your system if necessary.