1. Introduction

In Linux, Realtek Ethernet controllers, such as the RTL8111/8168/8411 models, frequently report connection problems. Typically, the Ethernet works briefly before the connection drops, even though the network icon might still indicate an active connection. This can be incredibly frustrating, especially if we rely on a stable network for work or personal use.

In this tutorial, we’ll tackle the persistent Realtek Ethernet connection issues often encountered on Linux systems. Let’s get started!

2. Understanding the Potential Causes of the Issue

To effectively troubleshoot and resolve this issue, first, we need to understand the potential causes.

Several factors can contribute to this persistent connection issue:

  • Driver problems: The Realtek driver might not be fully compatible with our kernel version, leading to instability
  • Network Manager misconfiguration: Incorrect settings in Network Manager or /etc/network/interfaces can cause disconnections
  • IPv6 interference: Sometimes, IPv6 settings can interfere with IPv4 connections
  • Incorrect MTU settings: Incorrect MTU (Maximum Transmission Unit) settings can lead to packet loss and disconnections
  • Kernel incompatibility: Certain kernel versions may not work well with specific Realtek drivers

Understanding these potential causes is our first step toward resolving the issue.

3. Running Initial Diagnostics

Before troubleshooting, let’s gather some information about our network configuration and Realtek Ethernet controller. This can help us in our journey to identify the root cause of the issue.

3.1. Checking Ethernet Controller and Driver Information

First, we should check which Realtek Ethernet controller we’re using and the driver currently loaded with the lspci command:

$ lspci | grep -i realtek
04:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8168/8111/8411 PCI Express Gigabit Ethernet Controller (rev 15)

This command lists the PCI devices and filters with grep for Realtek controllers.

In this example, our output shows that we have a Realtek RTL8168/8111/8411 Ethernet controller.

Next, let’s see if the correct Realtek driver is loaded with lsmod and grep:

$ lsmod | grep r816
r8169                  90112  0
libphy                 61440  2 r8169,mdio_devres

This command lists all loaded modules and filters for the Realtek driver (usually r8168 or r8169). Here, the r8169 driver is currently loaded.

3.2. Inspecting Kernel Messages

After confirming the current driver, we can check kernel messages with dmesg for clues about any basic driver issues:

$ dmesg | grep r816
[    1.234567] r8169 0000:04:00.0 eth0: RTL8168h/8111h, 00:e0:4c:68:00:01, XID 541, IRQ 27
[    1.234568] r8169 0000:04:00.0 eth0: jumbo features [frames: 9200 bytes, tx checksumming: ko]

We should look for any warnings or errors related to the Realtek driver.

In this example, our output shows the initialization of the r8169 driver for the Realtek Ethernet controller and mentions features such as jumbo frames.

3.3. Inspecting Network Configuration

Now, let’s check the current network interface configuration with ifconfig to ensure everything is set up correctly:

$ ifconfig
enp4s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.100  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::e0:4cff:fe68:1/64  scope link
        ether 00:e0:4c:68:00:01  txqueuelen 1000  (Ethernet)
...

We should look for the ethernet interface (e.g., enp4s0) and note its status. Our output here shows the status of the enp4s0 Ethernet interface, including its IP address, MAC address, and packet statistics.

Lastly, let’s use the ethtool command to see detailed information about the Ethernet interface:

$ sudo ethtool enp4s0
Settings for enp4s0:
    Supported ports: [ TP MII ]
    Supported link modes:   10baseT/Half 10baseT/Full
                            100baseT/Half 100baseT/Full
                            1000baseT/Full
...
    Speed: 1000Mb/s
    Duplex: Full
    Supports Wake-on: pumbg
    Wake-on: g
    Current message level: 0x00000033 (51)
                           drv probe ifdown ifup
    Link detected: yes

Our output confirms that the interface is up and running at full duplex with support of up to 1000Mb/s. It further shows supported link modes, speed, duplex settings, auto-negotiation status, and wake-on settings.

Notably, if we encounter an error in any of these diagnostic processes, the information can help during troubleshooting.

4. Basic Troubleshooting Steps

With initial diagnostics in hand, we can now proceed with basic troubleshooting steps to address common issues.

4.1. Restarting the Network Interface

Sometimes, simply restarting the network interface can temporarily resolve the persistent connection issues.

To do this, we can bring the interface down and up with ifdown and ifup commands:

$ sudo ifdown enp4s0
$ sudo ifup enp4s0

This will turn off and then re-enable the Ethernet interface.

After restarting the interface, we should check if the connection is stable and ensure the Ethernet interface shows UP and RUNNING:

$ ifconfig
enp4s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
...

Our output indicates that the enp4s0 interface is now active and running.

4.2. Verifying Network Manager Settings

Network Manager settings can sometimes cause connectivity issues. Let’s check its configurations and adjust them if necessary.

First, let’s open the NetworkManager configuration file (/etc/NetworkManager/NetworkManager.conf) with a preferred text editor like nano or vi:

$ sudo vi /etc/NetworkManager/NetworkManager.conf

In the file, we need to confirm it includes the following:

[main]
plugins=ifupdown,keyfile,ofono
dns=dnsmasq

[ifupdown]
managed=true

Let’s better understand these configurations:

  • ifupdown – enables NetworkManager to handle network interfaces present in /etc/network/interfaces, ensuring compatibility with traditional network configuration methods
  • keyfile – manages connections stored in keyfile format (the default format NetworkManager stores network configurations)
  • ofono – allows NetworkManager to manage mobile broadband connections using oFono
  • dns=dnsmasq – configures NetworkManager to use dnsmasq as a local DNS resolver
  • managed=true tells NetworkManager to control the network interfaces in /etc/network/interfaces (if this is set to false, NetworkManager will ignore these interfaces, which can lead to connectivity issues if another tool or service does not manage them properly)

After saving our changes (if any), we should restart NetworkManager for the changes to take effect:

$ sudo systemctl restart NetworkManager
Job for NetworkManager.service restarted successfully.

This output indicates that the NetworkManager service has been successfully restarted.

4.3. Configuring Network Interfaces

As part of our basic troubleshooting process, we need to ensure the proper configuration of our network interface in the /etc/network/interfaces file.

To do this, we should open the /etc/network/interfaces file with any text editor and confirm it includes the correct settings for our Ethernet interface:

$ sudo vi /etc/network/interfaces
...
auto lo
iface lo inet loopback

auto enp4s0
allow-hotplug enp4s0
iface enp4s0 inet dhcp

Let’s better understand these important configurations:

  • auto lo – indicates that the specified interface (lo in this case) should be automatically brought up when the system boots
  • iface lo inet loopback – configures the loopback interface for IPv4 (for IPv6, we would use inet6) using the loopback method
  • auto enp4s0 – indicates that the specified interface (enp4s0 in this case) should be automatically brought up when the system boots
  • allow-hotplug enp4s0 – specifies that the interface should be brought up automatically when it’s detected (plugged in), useful for interfaces that might not be connected at boot time but may be plugged in later
  • iface enp4s0 inet dhcp – configures the Ethernet interface to use DHCP

Notably, DHCP simplifies network management, as the DHCP server automatically assigns and manages IP addresses and other settings. This is especially useful in environments where network configurations frequently change or if we manage them centrally.

4.4. Restarting the Networking Service

If we make any edits from our previous interaction, either by changing our Ethernet interface (enp4s0, for our example) or by changing init for IPv4 to inet6 for IPv6 or any other preferred changes, we should save our changes and exit the editor.

Then, we should apply the changes by restarting the networking service:

$ sudo systemctl restart networking
Job for networking.service restarted successfully.

Our output indicates that the networking service has been successfully restarted.

4.5. Checking System Logs

System logs can also provide valuable information and insights into any underlying issues with the Realtek Ethernet controller.

We can use journalctl to view an extended log of messages related to the Realtek driver:

$ sudo journalctl -xe | grep r816
Jun 02 10:45:21 hostname kernel: r8169 0000:04:00.0 eth0: link up
Jun 02 10:45:22 hostname kernel: r8169 0000:04:00.0 eth0: Link is Up - 1Gbps/Full - flow control rx/tx
Jun 02 11:15:45 hostname kernel: r8169 0000:04:00.0 eth0: link down
Jun 02 11:16:01 hostname kernel: r8169 0000:04:00.0 eth0: link up
...

From our sample output, we can see that the Ethernet interface experienced intermittent link drops and reconnections. This pattern could indicate an issue with the cable, network port, or driver. Reviewing these logs can help pinpoint the timing and frequency of the issue, which is critical for diagnosing and fixing the problem.

5. Advanced Troubleshooting Steps

If basic troubleshooting doesn’t resolve the issue, we have to explore advanced troubleshooting.

Specifically, we need to focus on updating or reinstalling drivers, blacklisting conflicting drivers, disabling IPv6, and adjusting MTU Settings.

5.1. Installing the Realtek Driver via DKMS

We should confirm we have the correct and latest drivers for our Realtek Ethernet controller.

To install or reinstall the Realtek driver, first, we should remove any existing installations:

# Remove existing r8168-dkms package, including the driver and DKMS configuration
$ sudo apt purge r8168-dkms

# Remove r8168 driver module from the kernel, ensuring it's fully unloaded
$ sudo /sbin/modprobe -r r8168

Afterward, we can now install the driver using Dynamic Kernel Module Support (DKMS), which helps manage driver modules:

$ sudo apt install r8168-dkms

Here, we install the r8168-dkms package, which automatically builds and installs the Realtek driver for the currently running kernel using DKMS.

5.2. Building and Installing Specific Driver Versions

Sometimes, specific driver versions work better with certain kernels. Therefore, we can decide to build and install a specific driver version.

To do this, first, we have to build the specific driver version with DKMS:

$ sudo dkms build r8168/8.043.02 -k "$(uname -r)/$(uname -p)"

Here, this command tells DKMS to build the r8168 driver version 8.043.02. uname -r returns the current kernel version, and uname -p returns the processor architecture to initiate the build process.

After completing the build process, we can now install the driver:

$ sudo dkms install r8168/8.043.02 -k "$(uname -r)/$(uname -p)"
...
DKMS: install completed.

Similar to the build process, we install the built r8168 driver version 8.043.02 into the kernel.

After installation, we can verify the driver installation with modinfo:

$ modinfo r8168 | grep -i version
version:        8.043.02-NAPI
srcversion:     1A2B3C4D5E6F7890

As we can see, this line shows the version of the installed driver. It should match the version we intended to install (8.043.02 in this case).

5.3. Blacklisting Conflicting Drivers

Sometimes, the r8169 driver can conflict with the r8168 driver, leading to persistent connection issues. However, blacklisting the conflicting driver can help ensure the system loads only the correct driver.

To do this, we’ll edit the blacklist configuration file (/etc/modprobe.d/blacklist.conf) with our preferred text editor:

$ sudo vi /etc/modprobe.d/blacklist.conf

Inside the blacklist configuration file, we’ll add the blacklist driver (in this case, the r8169):

blacklist r8169

After blacklisting and saving the file, we need to update the initial RAM filesystem (initramfs) to apply the changes:

$ sudo update-initramfs -u

Notably, the -u option updates the existing initramfs images for all installed kernels. With this, we ensure that the changes to the blacklist configuration are included in the boot process.

Finally, we should reboot our system to apply changes.

5.4. Disabling IPv6 With sysctl Configuration

IPv6 can sometimes cause connectivity issues.

However, turning it off by modifying the etc/sysctl.conf file might stabilize our connection and fix our issue:

# Disable IPv6 on all network interfaces
$ sudo sh -c "echo 'net.ipv6.conf.all.disable_ipv6 = 1' >> /etc/sysctl.conf"

# Disable IPv6 on the default network interface
$ sudo sh -c "echo 'net.ipv6.conf.default.disable_ipv6 = 1' >> /etc/sysctl.conf"

# Disable IPv6 on the loopback interface
$ sudo sh -c "echo 'net.ipv6.conf.lo.disable_ipv6 = 1' >> /etc/sysctl.conf"

Notably, sudo sh -c runs our commands with superuser privileges.

Afterward, we should apply our changes with sysctl and restart the network service:

$ sudo sysctl -p
$ sudo systemctl restart networking

sudo sysctl -p reloads the sysctl settings from the /etc/sysctl.conf file, applying the new configuration immediately.

5.5. Adjusting MTU Settings

If the problem persists, adjusting MTU might help. Incorrect MTU settings can lead to packet loss and disconnections, as the MTU defines the largest packet size the system can transmit over the network without fragmentation.

To do this, we open the network interfaces file (/etc/network/interfaces) and add or modify the MTU setting for our interface:

auto enp4s0
iface enp4s0 inet dhcp
mtu 1500

Here, the MTU for the enp4s0 interface is 1500 bytes.

However, if the MTU is set too high, packets may need to be fragmented, which can cause network inefficiency and packet loss. On the other hand, if set too low, it can reduce throughput by increasing the number of packets that need to be sent.

Notably, here are some common MTU values:

  • 1500 bytes: the default MTU size for Ethernet networks and is usually optimal for most standard networks
  • 1492 bytes: commonly used for Point-to-Point Protocol over Ethernet (PPPoE) connections
  • 576 bytes: sometimes used for dial-up connections or highly fragmented networks

If we change our MTU value, we should restart networking to apply the changes and see if that works.

6. Using Different Kernel Versions

If the persistent connection issue remains unresolved, as a last resort, we can consider using a different kernel version. Different kernel versions may have varying levels of compatibility with hardware drivers, including the Realtek Ethernet driver.

To do this, first, let’s identify our current kernel version:

$ uname -r
5.4.0-54-generic

Now, we can proceed to install an alternative kernel with apt:

$ sudo apt install linux-image-5.8.0-53-generic

After installation, we should reboot our system.

As a last resort, this should resolve the issue if other approaches fail.

7. Conclusion

In this article, we explored various methods for troubleshooting and resolving persistent connection issues with Realtek Ethernet controllers on Linux systems. We discussed basic and advanced troubleshooting steps, including restarting network interfaces, updating drivers, adjusting network settings, disabling IPv6, adjusting MTU settings, and using a different kernel version as a last resort.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments