Ubuntu 18.04 - Ethernet disconnected after suspend

49,508

Solution 1

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

Solution 2

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!

Solution 3

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.

Solution 4

I had the same problem and i found this solution.

  1. run: sudo lshw -C network
    to find your network card kernel module

    In *-network, description: Ethernet interface, in configuration field found
    driver=sky2 for me. sky2 is a ethernet network kernel module for my laptop.

  2. I create a file sky2.sh into: /lib/systemd/system-sleep/ folder with

    #!/bin/bash 
    modprobe -r sky2 # unload sky2 kernel module 
    modprobe -i sky2 # reload sky2 kernel module 
    

    and change the permissions with:

    sudo chmod a+x sky2.sh
    

After that the problem solved.

Solution 5

It detects the Ethernet Connection?

then

open NetworkManager.conf

sudo nano /etc/NetworkManager/NetworkManager.conf

Comment (Add #) the dns=dnsmasq

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

[ifupdown]
managed=true

Restart the Network manager

sudo service network-manager restart
Share:
49,508

Related videos on Youtube

aaaa
Author by

aaaa

Updated on September 18, 2022

Comments

  • aaaa
    aaaa over 1 year

    Ethernet does not resume after suspend.

    sudo service network-manager restart
    

    does not work. Only restart solves problem.

    • HEKTO
      HEKTO almost 5 years
      This problem is back for me in Xubuntu 18.04.2, kernel 4.15.0-54
  • aaaa
    aaaa about 6 years
    [main] plugins=ifupdown,keyfile [ifupdown] managed=true [device] wifi.scan-rand-mac-address=no
  • aaaa
    aaaa about 6 years
    this is what I have in the file....
  • Santhosh Veer
    Santhosh Veer about 6 years
    did you update the conf file Previously? if yes reboot & check
  • aaaa
    aaaa about 6 years
    I tried your fix Santhosh Veer. Still greyed out. Ethernet.
  • Santhosh Veer
    Santhosh Veer about 6 years
    run this command systemctl status NetworkManager.service to check the error
  • aaaa
    aaaa about 6 years
    sudo modprobe -i r8169
  • aaaa
    aaaa about 6 years
    worked! do I have to do this manually now all the time i resume?
  • Paulo Marcel Coelho Aragão
    Paulo Marcel Coelho Aragão almost 6 years
    madzohan, I feel it might be redundant to add your edit, since I mentioned twice in the answer that the script has to be executable: "systemd runs all executable scripts under /lib/systemd/system-sleep", and also "I created and made executable script /lib/systemd/system-sleep/r8169-refresh"
  • Fabby
    Fabby almost 6 years
    Welcome to Ask Ubuntu! ;-) Could you please review my edits and also review the editing help to improve the readability of your answers in the future... ;-)
  • Paulo Marcel Coelho Aragão
    Paulo Marcel Coelho Aragão almost 6 years
    This was fixed in kernel 4.15.0-24.26, released on 07/01/2018, so the workaround is not needed anymore.
  • Danfro
    Danfro almost 6 years
    I have this problem on my laptop since installing some updates a few days ago. The solution given above does still solve the issue. Thanks a lot!
  • Paulo Marcel Coelho Aragão
    Paulo Marcel Coelho Aragão almost 6 years
    @Daniel, could you post the output of: apt policy linux-image-generic ? This issue should have been solved since 07/01/2018, this workaround shouldn't be needed anymore.
  • WinEunuuchs2Unix
    WinEunuuchs2Unix over 5 years
    It's not just 18.04. In 16.04 the rtl8169 kernel driver had to be unloaded and loaded after suspend too: askubuntu.com/questions/950871/…
  • Gemechu Fanta Garuma
    Gemechu Fanta Garuma over 5 years
    I was looking around in the internet for this answer. Thanks, it really solves the problem.
  • Dominic108
    Dominic108 over 5 years
    They say that it is not needed anymore, but I had the same problem and tried this solution and it worked. In my case, the driver was sky2, so I had to edit the script.
  • Dominic108
    Dominic108 over 5 years
    This is the same as the accepted solution, without the logging function.
  • Dominic108
    Dominic108 over 5 years
    This the same as the accepted solution, but without putting it in a script that will be executed at resume and without the logging function.
  • wjandrea
    wjandrea over 5 years
    This is not really an answer, unless you're suggesting to use kernel 4.13.
  • Michael
    Michael over 5 years
    I have this problem too, but my Ethernet driver is "e1000e". I'm running the 4.15.0.43.45 kernel. This answer does appear to fix the issue.
  • Michael
    Michael over 5 years
    There appears to be a race condition (?) between reinserting the module and networking getting reconfigured, as about 10% of the time even with this method I still keep getting the "network is disconnected" notification every so often and never get connected.
  • kxr
    kxr about 5 years
    Problem still here after standby (with sky2 driver) - and fixed by those modprobe's on a laptop. Linux HPC 4.15.0-47-generic #50-Ubuntu SMP Wed Mar 13 10:44:52 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
  • alper
    alper over 4 years
    After making those changes I have suspended manually systemctl suspend and still having the same error. @Paulo Marcel Coelho Aragão
  • jc00ke
    jc00ke almost 4 years
    Just tested this on Ubuntu 20.04 (Regolith 1.4) on a Dell XPS 13 connected to a Thunderbolt dock and it worked flawlessly. :chef: :kiss: Thanks @diego-rivera!
  • Thomas Ferris Nicolaisen
    Thomas Ferris Nicolaisen almost 4 years
    Exactly the same here. Only replace the module with r8152 for the Dell XPS 13 9360. Thanks!
  • Ruth
    Ruth over 3 years
    This worked perfectly on my 20.04 desktop, with a wifi card using the ath9k drivers. Thank you!
  • Lizardx
    Lizardx over 3 years
    this should be the accepted answer.
  • Rodrigo Soares
    Rodrigo Soares almost 3 years
    Including grep to find the driver will be easier: sudo lshw -C network | grep driver=
  • Admin
    Admin almost 2 years
    Try the steps manually first - on my system the rmmod failed because of dependencies... had to stop network-manager service, then remove and later insert some more modules in specific order and start network-manager again...