Fixing Realtek ethernet driver on Linux

When my 3 year old son pressed the sleep button on my keyboard, we discovered that it actually sends my Archlinux desktop to sleep. Who would have thunk it? What was more annoying is that when the machine woke up, the network connection did not come back.

Poking around in the log files, I saw lines like the following lines which lead me to believe it was a NetworkManager problem.

Oct 26 09:12:30 grouch NetworkManager[14296]: <info> (eth0): carrier now OFF (device state 70, deferring action for 4 seconds)
Oct 26 09:12:31 grouch NetworkManager[14296]: <info> (eth0): carrier now ON (device state 70)
Oct 26 09:12:32 grouch NetworkManager[14296]: <info> (eth0): carrier now OFF (device state 70, deferring action for 4 seconds)
Oct 26 09:12:34 grouch NetworkManager[14296]: <info> (eth0): carrier now ON (device state 70)
Oct 26 09:12:50 grouch NetworkManager[14296]: <warn> (eth0): DHCPv4 request timed out.
Oct 26 09:12:50 grouch NetworkManager[14296]: <info> (eth0): canceled DHCP transaction, DHCP client pid 15506
Oct 26 09:12:50 grouch NetworkManager[14296]: <info> Activation (eth0) Stage 4 of 5 (IP4 Configure Timeout) scheduled...
Oct 26 09:12:50 grouch NetworkManager[14296]: <info> Activation (eth0) Stage 4 of 5 (IP4 Configure Timeout) started...
Oct 26 09:12:50 grouch NetworkManager[14296]: <info> Activation (eth0) Stage 5 of 5 (IP Configure Commit) scheduled...
Oct 26 09:12:50 grouch NetworkManager[14296]: <info> Activation (eth0) Stage 4 of 5 (IP4 Configure Timeout) complete.
Oct 26 09:12:50 grouch NetworkManager[14296]: <info> Activation (eth0) Stage 5 of 5 (IP Configure Commit) started...
Oct 26 09:12:50 grouch NetworkManager[14296]: <info> Activation (eth0) Stage 5 of 5 (IP Configure Commit) failed (no IP configuration found)
Oct 26 09:12:50 grouch NetworkManager[14296]: <info> (eth0): device state change: ip-config -&gt; failed (reason 'ip-config-unavailable') [70 120 5]
Oct 26 09:12:50 grouch NetworkManager[14296]: <warn> Activation (eth0) failed.
Oct 26 09:12:50 grouch NetworkManager[14296]: <info> Activation (eth0) Stage 5 of 5 (IP Configure Commit) complete.
Oct 26 09:12:50 grouch NetworkManager[14296]: <info> (eth0): device state change: failed -&gt; disconnected (reason 'none') [120 30 0]
Oct 26 09:12:50 grouch NetworkManager[14296]: <info> (eth0): deactivating device (reason 'none') [0]
</info></info></info></warn></info></info></info></info></info></info></info></info></warn></info></info></info></info>

After a lot of googling, it turns out that the problem was the kernel was using the wrong driver for the network card. First to find out which type of Realtek card you have use the following command:

lspci | grep Real

If you see the following, you need to update the driver loaded by the kernel to one provided by Realtek.

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

If you are using Archiinux, its as simple as installing the AUR package for the r8168 module. Using the package, the module downloaded and compiled fine for me, with the latest 3.0 Linux kernel.

yaourt -S r8168

Finally, reboot and you should still have a working network with the added bonus that it will automatically reconnect when resuming.