Ubuntu 18.04 - Ethernet disconnected after suspend

The main Ubuntu bug tracking this issue, at least for network kernel module r8169, seems to be:

https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1752772

I'd encourage everyone that is affected by this issue to go there and mark that it affects you, so that the maintainers have a better sense of how serious it is.

I'm running a fresh install of Xubuntu 18.04, and my Ethernet interface uses kernel module r8169, which I discovered running:

sudo lshw -C network

There'll be 2 groups of info, one starting with description: Ethernet interface, and another with description: Wireless interface. Under description: Ethernet interface, look for a line starting with configuration:, like this:

configuration: autonegotiation=on broadcast=yes driver=r8169 driverversion=2.3LK-NAPI duplex=full firmware=rtl_nic/rtl8105e-1.fw ip=192.168.100.6 latency=0 link=yes multicast=yes port=MII speed=100Mbit/s

The driver will be here: driver=.

Systemd runs all executable scripts under /lib/systemd/system-sleep before and after suspend, passing 2 parameters, $1 is the state (pre, before suspend, or post, after suspend), and $2 is the action (suspend, hibernate, hybrid-state, or suspend-then-hibernate). This is documented in the man page for systemd-suspend.service.

We need to reload the module for the Ethernet interface when resuming from suspend, after suspend. So I created script /lib/systemd/system-sleep/r8169-refresh:

#!/bin/bash

PROGNAME=$(basename "$0")
state=$1
action=$2

function log {
    logger -i -t "$PROGNAME" "$*"
}

log "Running $action $state"

if [[ $state == post ]]; then
    modprobe -r r8169 \
    && log "Removed r8169" \
    && modprobe -i r8169 \
    && log "Inserted r8169"
fi

and made it executable:

chmod +x /lib/systemd/system-sleep/r8169-refresh

The messages logged from the script will go to /var/log/syslog tagged with the name of the script and its PID. This way you can check whether the script reloaded the kernel module:

grep r8169-refresh /var/log/syslog

Here's another simple(r?) solution: create a systemd service whose only task is to unload/reload the module after a suspend cycle (I named it /etc/systemd/system/fix-r8169.service):

[Unit]
Description=Fix RTL-8169 Driver on resume from suspend
After=suspend.target

[Service]
User=root
Type=oneshot
ExecStartPre=/sbin/modprobe -r r8169
ExecStart=/sbin/modprobe r8169
TimeoutSec=0
StandardOutput=syslog

[Install]
WantedBy=suspend.target

Then just execute systemctl enable fix-r8169.service, and you should be set!! Systemd will now automagically unload-and-reload your module upon wake from suspend.

Cheers!


It happened to me too.

Unload/reload network kernel modules/drivers works.

Mine is r8169, so (as root): (I typed by hand, so there was a delay)

sudo modprobe -r r8169
sudo modprobe -i r8169

I also removed mii during my first try. Not necessary though.