Get Rewarded! We will reward you with up to €50 credit on your account for every tutorial that you write and we publish!

Installing the r8168 driver

profile picture
Author
Hetzner Online
Published
2019-03-08
Time to read
4 minutes reading time

Introduction

The Linux r8169 driver for the Realtek network chips does not always work correctly up to kernel version 4.16. There can be timeouts and/or frequent link up/link down state changes, bandwidth problems and even system crashes may occur.

One solution is to use the official Realtek r8168 driver (instead of r8169). It can be installed from external repositories or compiled by yourself. As an alternative, you can upgrade the kernel to version 4.17+.

This article describes how to setup the network driver.

Option A - Installing kmod-r8168 from elrepo.org

ELRepo is an RPM repository for Enterprise Linux packages. ELRepo supports Red Hat Enterprise Linux and its derivatives (CentOS, Scientific Linux and others). It is the easiest way to get the r8168 driver for the standard upstream kernels.

NOTE: If you are using a special kernel like Virtuozzo, OpenVZ or something similar you MUST compile the module yourself!

Import the public key:

rpm --import http://elrepo.org/RPM-GPG-KEY-elrepo.org

Install ELRepo for RHEL 6, CentOS 6 or SL 6:

rpm -Uhv http://www.elrepo.org/elrepo-release-6-6.el6.elrepo.noarch.rpm

For RHEL 7, CentOS 7 or SL 7:

rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm

Install the kmod-r8168 Realtek r8168 driver:

yum --enablerepo=elrepo install kmod-r8168

After a reboot of the server the new driver will be used. It stays active even after kernel upgrades.

Option B - Installation from source

Step 1 - Prerequisites

Please make sure you are running the latest kernel available by running yum or apt-get and then rebooting.

CentOS

On CentOS the header packages of the kernel, kernel-devel and kernel-headers, as well as the compiler, will need to be installed to replace the driver:

yum install gcc gcc-c++ kernel-devel kernel-headers

Debian/Ubuntu

In Debian/Ubuntu the name of the header package depends on the selected kernel. It can be for example linux-headers-generic or linux-headers-server. All the other required packages will be installed via build-essentials:

aptitude install build-essential linux-headers-`uname -r`

Proxmox

In Proxmox the headers can be found in the pve-headers package

aptitude install pve-headers-`uname -r`

Step 2 - Getting the sources

cd /tmp
wget http://mirror.hetzner.de/tools/Realtek/drivers/r8168-8.046.00.tar.bz2
tar xf r8168-8.046.00.tar.bz2

Step 3 - Compiling the driver

The package contains an autorun.sh script that automatically compiles the drivers and replaces the present r8169 driver. Doing so means the network connection is lost. You should therefore start this script in a screen session and only use it if you are absolutely sure that the kernel module can be compiled without errors. You can check this beforehand through make modules.

cd r8168-8.046.00
make modules

or

make all

If there are no errors with make modules, you can replace the driver in the current system. In this case the network connection is interrupted and the r8169 driver permanently disabled!

screen
cd r8168-8.046.00
./autorun.sh

If you do not want an interruption of the system or you want to only temporarily disable the r8169 driver, you can instead compile the driver as shown below.

Step 4 - Activating the new driver

CentOS

In the file /etc/modprobe.conf the appropriate driver for eth0 needs to be edited. To do this the line

alias eth0 r8169

must be changed to

alias eth0 r8168

The new driver must now be activated. To do this a simple shell script can be created that does the necessary steps.

echo "rmmod r8169" > /tmp/r8168
echo "depmod -a" >> /tmp/r8168
echo "modprobe r8168" >> /tmp/r8168
echo "service network restart" >> /tmp/r8168
echo "service ipaliases restart" >> /tmp/r8168

Execute that script:

sh /tmp/r8168

After several seconds the server should be back online using the new network driver. The working directory can now be removed:

rm -rf /root/r8168

Debian/Ubuntu

After installing the driver, update the module dependencies.

depmod -a

First the r8169 network driver needs to be blocked, so as to prevent the kernel from loading it. Note: If additional NICs are installed in the server, the driver must not be blocked.

Ubuntu/Debian 6.0 (Squeeze):

echo "blacklist r8169" >> /etc/modprobe.d/blacklist.conf

Next, the kernel must be forced to include the driver in the initrd. This also ensures that if additional NICs have been installed the new r8168 module is loaded before the r8169 module.

echo "r8168" >> /etc/initramfs-tools/modules

Afterwards the initrd will be rebuilt.

update-initramfs -v -t -u

Now you can reboot the server.

After a kernel update the driver might need to be recompiled.

Conclusion

Either of the two ways shown here should eliminate the problems with the Realtek network chip.

Want to contribute?

Get Rewarded: Get up to €50 in credit! Be a part of the community and contribute. Do it for the money. Do it for the bragging rights. And do it to teach others!

Report Issue

Discover our

Dedicated Servers

Configure your dream server. Top performance with an excellent connection at an unbeatable price!

Want to contribute?

Get Rewarded: Get up to €50 credit on your account for every tutorial you write and we publish!

Find out more