DEV Community

vast cow
vast cow

Posted on • Edited on

Installing Realtek r8168 as a DKMS Module on RHEL-Compatible Distributions

If you run a RHEL-compatible distribution and your onboard Realtek NIC behaves poorly with the in-kernel r8169 driver (link drops, odd throughput, unstable autoneg, etc.), switching to Realtek’s out-of-tree r8168 driver can be a pragmatic fix.

This post walks through a clean, repeatable approach: install r8168 via DKMS so it automatically rebuilds whenever your kernel updates.

Source assumption: you download the r8168 Linux driver tarball from Realtek’s official download page:
https://www.realtek.com/Download/List?cate_id=584

Why DKMS

On RHEL-compatible distributions, kernel updates are normal and frequent operational events. If you install an out-of-tree driver without DKMS, you often need to manually rebuild/reinstall it after each kernel update.

DKMS solves that by rebuilding the driver module locally for whatever kernel you boot, keeping the module aligned with kernel lifecycle changes.

Before you start (important operational note)

Switching NIC drivers can temporarily drop networking.

If you are working over SSH on a remote server, you should have out-of-band console access (IPMI/iDRAC/iLO/KVM) or at least a fallback path. Plan a maintenance window.

Step 0: Identify the NIC and current driver

First, confirm the NIC and whether r8169 is currently in use:

uname -r
lspci -nnk | grep -A3 -i ethernet
Enter fullscreen mode Exit fullscreen mode

If you see Kernel driver in use: r8169, you are a good candidate for this change.

Step 1: Enable EPEL (for DKMS) and ensure kernel build repos are available

You typically need:

  • EPEL (for dkms)
  • Access to packages that provide the matching kernel headers/devel for your running kernel

Enable EPEL and required base repositories:

sudo dnf install -y dnf-plugins-core

# EPEL prerequisites differ slightly between RHEL major versions
RHEL_MAJOR="$(rpm -E %rhel)"
if [ "$RHEL_MAJOR" -eq 9 ]; then
  sudo dnf config-manager --set-enabled crb
elif [ "$RHEL_MAJOR" -eq 8 ]; then
  sudo dnf config-manager --set-enabled powertools
fi

# EPEL
sudo dnf install -y epel-release
Enter fullscreen mode Exit fullscreen mode

Note: How you obtain kernel headers/devel depends on which kernel stream you run (vendor kernel, alternative kernel repos, etc.). The key requirement is: headers/devel must match the kernel you boot.

Step 2: Install build tools, DKMS, and matching kernel headers/devel

DKMS needs a working toolchain and the kernel build environment corresponding to your running kernel.

sudo dnf install -y gcc make elfutils-libelf-devel tar bzip2
sudo dnf install -y dkms
Enter fullscreen mode Exit fullscreen mode

Now install the kernel headers/devel that match your running kernel:

sudo dnf install -y "kernel-devel-$(uname -r)" "kernel-headers-$(uname -r)" || \
sudo dnf install -y kernel-devel kernel-headers
Enter fullscreen mode Exit fullscreen mode

A quick sanity check

If you recently installed a new kernel but haven’t rebooted, uname -r may still show the older kernel. In that case:

  • reboot into the intended kernel
  • then re-run uname -r
  • ensure kernel-devel matches that version

This prevents the common DKMS error: “kernel headers not found”.

Step 3: Download r8168 from Realtek and extract it

From Realtek’s page, download the r8168 Linux driver tarball. The filename is typically like:

  • r8168-8.xx.xx.tar.bz2 (version varies)

From your download directory:

ls -1 r8168-*.tar.bz2
tar -xvf r8168-*.tar.bz2
ls -1 | grep -E '^r8168-[0-9]+\.[0-9]+\.[0-9]+$'
Enter fullscreen mode Exit fullscreen mode

Capture the extracted directory name and version:

R8168_DIR="$(ls -d r8168-* | head -n 1)"
R8168_VER="${R8168_DIR#r8168-}"
echo "Using version: ${R8168_VER}"
Enter fullscreen mode Exit fullscreen mode

Step 4: Put the source into /usr/src (DKMS-friendly layout)

DKMS expects module sources under /usr/src/<name>-<version>.

sudo rm -rf "/usr/src/r8168-${R8168_VER}"
sudo cp -a "${R8168_DIR}" "/usr/src/r8168-${R8168_VER}"
Enter fullscreen mode Exit fullscreen mode

Step 5: Create a dkms.conf

Create the DKMS configuration file at:

/usr/src/r8168-<version>/dkms.conf

This example assumes the Realtek tarball builds the module from the src/ directory:

sudo tee "/usr/src/r8168-${R8168_VER}/dkms.conf" >/dev/null <<EOF
PACKAGE_NAME="r8168"
PACKAGE_VERSION="${R8168_VER}"

BUILT_MODULE_NAME[0]="r8168"
BUILT_MODULE_LOCATION[0]="src/"
DEST_MODULE_LOCATION[0]="/kernel/drivers/net/ethernet/realtek"

AUTOINSTALL="yes"
MAKE[0]="make -C src KERNELDIR=/lib/modules/\${kernelver}/build modules"
EOF
Enter fullscreen mode Exit fullscreen mode

If your Realtek package uses a different Makefile interface, adjust MAKE[0]. The clue is in the Makefile itself:

sed -n '1,120p' "/usr/src/r8168-${R8168_VER}/src/Makefile"
Enter fullscreen mode Exit fullscreen mode

Step 6: Register, build, and install the DKMS module

Now add the module to DKMS, build it for your current kernel, and install it:

KVER="$(uname -r)"

sudo dkms add -m r8168 -v "${R8168_VER}"
sudo dkms build -m r8168 -v "${R8168_VER}" -k "${KVER}"
sudo dkms install -m r8168 -v "${R8168_VER}" -k "${KVER}"

dkms status
Enter fullscreen mode Exit fullscreen mode

If the build fails

DKMS logs are usually very direct. Check make.log:

sudo find "/var/lib/dkms/r8168/${R8168_VER}" -name make.log -print -exec tail -n 120 {} \;
Enter fullscreen mode Exit fullscreen mode

Most failures come down to:

  • missing kernel-devel / kernel-headers
  • kernel-devel not matching uname -r
  • a Makefile mismatch with your dkms.conf

Step 7: Blacklist r8169 to avoid conflicts

r8168 and r8169 can contend for the same hardware. The standard approach is to blacklist r8169.

echo 'blacklist r8169' | sudo tee /etc/modprobe.d/blacklist-r8169.conf
Enter fullscreen mode Exit fullscreen mode

Rebuild initramfs (recommended so the blacklist is respected early in boot):

sudo dracut -f "/boot/initramfs-$(uname -r).img" "$(uname -r)"
Enter fullscreen mode Exit fullscreen mode

Reboot:

sudo reboot
Enter fullscreen mode Exit fullscreen mode

Step 8: Validate after reboot

After the system comes back:

lsmod | egrep 'r8168|r8169'
lspci -nnk | grep -A3 -i ethernet
ethtool -i <YOUR_INTERFACE_NAME>
Enter fullscreen mode Exit fullscreen mode

You want to see:

  • r8168 loaded
  • r8169 not loaded
  • ethtool -i reports driver: r8168

Step 9: Staying healthy through kernel updates

Because you set AUTOINSTALL="yes", DKMS is intended to rebuild the module automatically when you install a new kernel—provided the matching kernel-devel is present.

If you ever need to force it manually for a specific kernel version:

sudo dkms autoinstall -k <new-kernel-version>
Enter fullscreen mode Exit fullscreen mode

Common pitfalls and troubleshooting notes

Headers/devel mismatch

If you see errors like “kernel headers not found” or missing build/ directories, ensure:

  • uname -r matches the installed kernel-devel package version

Secure Boot

If Secure Boot is enabled, unsigned third-party modules may fail to load. The usual remedies are:

  • disable Secure Boot, or
  • sign the module and enroll a key (MOK)

Wrong driver package

Realtek provides several similar drivers (r8125, r8126, etc.). Make sure you downloaded the r8168 driver from the correct category page.

Closing thoughts

DKMS is the cleanest way to run Realtek’s r8168 driver on RHEL-compatible distributions: it keeps the driver aligned with kernel updates without requiring you to manually rebuild every time.

Top comments (0)