How to get an Realtek RTL8111/RTL8168 working under Linux
This text does contain Amazon referral links.
So, this article was released in August 2016 on my original blog. Even though the situation with RTL8111/RTL8168 network interfaces under Linux has become more and more stable these days, they still can cause problems like packet loss or an unstable network connection in general.
With this short guide I want to show you how to install the r8168 instead of the r8169 driver. The r8169 driver is default by most Linux distributions these days. The r8168 driver is sometimes more stable but not enabled by default due to license restrictions. This guide describes two ways to install the r8168 driver.
Requirements
This guide assumes that you have a working network connection. If you already have a Wi-Fi / ethernet adapter / dongle you can simply use this one or you can buy yourself an USB ethernet adapter or Wi-Fi dongle which is fully supported by the Linux kernel. An additional network adapter is only required if you can’t download the packages with your actual RTL8111/RTL8168 and the r8169 driver (for e.g. because you’re already experiencing a massive packet loss / connection interruptions). An alternative would be to download each package individually (the r8168 driver AND dependencies) from another computer and transfer it with an USB stick. But using an USB ethernet adapter is definitly the way more convenient way here.
The automatic way (only for Debian and Ubuntu)
Debian added the r8168 driver a few years ago to their non-free repository. With that being said, if you haven’t enabled the non-free repository in your Debian installation yet, you have to do this now. If you’re using the latest Debian release (as of writing this article the latest one being bookworm), you have to adjust your /etc/apt/sources.list file like this:
deb http://deb.debian.org/debian/ bookworm main contrib non-free
For Ubuntu their non-free repository is called universe. With Ubuntu 22.04 it is most likely already enabled. You can check your /etc/apt/sources.list and if the universe repository is missing adjust the file so that it contains something like this:
deb http://archive.ubuntu.com/ubuntu/ jammy main restricted universe
After you enabled the non-free / universe repository you can refresh the packages list and install the r8168 driver like this:
user@ubuntu:~$ sudo apt update && sudo apt install r8168-dkms
The driver is compiled for your running Linux kernel. The packages utilizes DKMS to do this. DKMS ensures that the driver is always rebuild when there is a Linux kernel update installed. Depending on your CPU, the compilation could take a few minutes. After the compilation / installation is finished, reboot your machine. You should be able to use your network interface now as expected without any network issues or package loss. You can also check which driver is being used on the command line:
user@ubuntu:~$ lspci -v | grep -A8 Ethernet | grep -A8 Realtek
[...]
Kernel driver in use: r8168
The manual way (for all distribution, not recommended)
The manual way is a little bit more complicated and I definitely don’t recommend this anymore. However, if your Linux distribution doesn’t ship the r8168 driver on one way or another, you may be forced to go this route. A huge disadvantage with going this way is, that you have to recompile the driver on your own everytime you update your kernel. So keep that in mind. Otherwise your network card will most likely not work after a kernel update and reboot of your system.
In order to compile the r8168 driver on your own, you have to install the kernel headers and compilation utilities like gcc, make and configure. For Debian and Ubuntu systems you can install all the dependencies like this:
user@ubuntu:~$ sudo apt update && sudo apt install build-essentials linux-headers-$(uname -r)
Next step is to download the driver. The official homepage from Realtek seems to not provide the driver anymore. Because of this we have to use a mirror on GitHub, provided by mtorromeo. You can use wget to download the driver directly like this (always check for the latest version on GitHub first):
user@linux:~$ wget https://github.com/mtorromeo/r8168/archive/refs/tags/8.052.01.tar.gz
We have to ensure that the r8169 driver isn’t loaded when booting the machine in the future. The following command ensures this:
user@linux:~$ sudo sh -c 'echo blacklist r8169 >> /etc/modprobe.d/blockr8169.conf'
As next we can extract the previously downloaded driver archive:
user@linux:~$ tar xfvz r8168-8.052.01.tar.gz
With extracting the driver archive, there is a new folder with the same name scheme which we can change into:
user@linux:~$ cd r8168-8.052.01
NOTICE: The number can change, depending on the version of the driver in the future. So don’t forget to change the version number if needed.
Now that we are in the correct directory, we can finally start compiling the driver. To do so, simply enter the following command:
user@linux:~/r8168-8.052.01$ sudo ./autorun.sh
You should then see an output like this one:
Check old driver and unload it.
rmmod r8168
Build the module and install
At main.c:222:
- SSL error:02001002:system library:fopen:No such file or directory: bss_file.c:175
- SSL error:2006D080:BIO routines:BIO_new_file:no such file: bss_file.c:178
sign-file: certs/signing_key.pem: No such file or directory
Backup r8169.ko
rename r8169.ko to r8169.bak
DEPMOD 4.4.0-31-generic
load module r8168
Updating initramfs. Please wait.
update-initramfs: Generating /boot/initrd.img-4.4.0-31-generic
Completed.
You can ignore the SSL error for now. The driver should be successfully compiled and installed into your system. The driver is already loaded and should work.
To ensure that the driver is really used and loaded, you can use the same command as mentioned above:
user@ubuntu:~$ lspci -v | grep -A8 Ethernet | grep -A8 Realtek
[...]
Kernel driver in use: r8168
Also a user called Tim on my old blog mentioned ethtool which does the same and helps you to check if the correct driver is in use:
user@linux:~$ sudo ethtool -i enp1s0
driver: r8168
version: 8.042.00-NAPI
firmware-version:
expansion-rom-version:
bus-info: 0000:07:00.0
supports-statistics: yes
supports-test: no
supports-eeprom-access: yes
supports-register-dump: yes
supports-priv-flags: no
NOTE: You have to change enp1s0 to the device name of your network card. This can be eth0, eth1, enp2s0, and so on.
If r8168 is mentioned, the driver was installed correctly and you should be able use your network card now without any package loss or interruptions.
If you liked this article, please consider supporting me by either subscribring or using one of my referral links listed here.