DEV Community

vast cow
vast cow

Posted on

Installing Realtek r8168 as a DKMS Module on Rocky Linux (ELRepo `kernel-lt`)

If you run Rocky Linux with ELRepo’s long-term kernel (kernel-lt) 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 kernel-lt 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 (and why it matters with kernel-lt)

ELRepo’s kernel-lt is not Rocky’s stock kernel stream. That’s often exactly why you want it—but it also means “prebuilt kmod” packages may not match your running kernel. DKMS solves that problem by rebuilding the driver module locally for whatever kernel you boot.

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 ELRepo and EPEL

You typically need:

  • ELRepo (for kernel-lt packages and matching headers/devel)
  • EPEL (for dkms)

Install repository packages and enable what you need:

sudo dnf install -y dnf-plugins-core

# ELRepo
sudo dnf install -y elrepo-release
sudo dnf config-manager --set-enabled elrepo-kernel

# EPEL prerequisites differ slightly between Rocky 8 and 9
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

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-lt headers/devel:

sudo dnf --enablerepo=elrepo-kernel install -y kernel-lt-devel kernel-lt-headers
Enter fullscreen mode Exit fullscreen mode

A quick sanity check

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

  • reboot into the intended kernel-lt
  • then re-run uname -r
  • ensure kernel-lt-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-lt-devel
  • kernel-lt-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-lt-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-lt-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 ELRepo kernel-lt: it keeps the driver aligned with kernel updates without requiring you to manually rebuild every time.

Top comments (0)