Linux: Fixing an unreliable network connection with ASUS P8Z 68-V onboard LAN

Recently I got a new ASUS P8Z 68-V motherboard and CPU, and had been having some strange network issues with it when running Gentoo Linux. The problems included connection failures after random periods of time and generally slow download speeds. The only way to get the connection running again after it failed (which was every few minutes at times) was to run:

ifconfig eth0 down
ifconfig eth0 up

On top of that, running ifconfig (with no args) was reporting 100% RX packets dropped for the interface.

This is the info on the network adapter:

$ lspci
...
07:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express
Gigabit Ethernet controller (rev 06)

At first I suspected there may have been something wrong with my (relatively new) Gentoo setup, so I did some testing running off an Ubuntu 11.10 live CD.  Interestingly this gave the same unreliable behaviour that wasn’t present when running Windows 7.

After further digging it turned out the problem was that the Linux kernel was loading the wrong module for the network adapter. This was confirmed by the presence of “r8169” in the output of lsmod.

The solution was to remove and blacklist the r8169 module and install Realtek’s official r8168 Linux kernel module from their website. On Gentoo I had compiled the kernel with the r8169 module built-in, so this meant first deselecting it and recompiling the kernel. After that, all that was left was to extract Realtek’s driver package and run ./autorun.sh as root.

Solution source: http://askubuntu.com/questions/46942/how-do-i-stop-my-ethernet-network-connection-from-dropping

Update:
In Linux Mint 12, you first need to run sudo apt-get install build-essential linux-headers-3.0.0-12-generic before running autorun.sh.