Wifi disconnects randomly after several hours (18.04)

This is often the result of the power saving feature in Ubuntu. You can disable this for the WiFi device by editing a file and restarting the network manager.

Here's how:

  1. Open Terminal (if it's not already open)

  2. Edit the default-wifi-powersave-on.conf file:

    sudo vi /etc/NetworkManager/conf.d/default-wifi-powersave-on.conf
    

    Note: Feel free to use any text editor of your choice. Be sure to open it with sudo, though.

    You will see the file contents look like this:

    [connection]
    wifi.powersave = 3
    
  3. Replace 3 with 2, then save the file.

    Definition of Values:

    Value What It Means
    0 Use the default value
    1 Do not change existing setting(s)
    2 Disable powersave feature
    3 Enable powersave feature
  4. Restart the network manager:

    sudo service network-manager restart
    

    Alternatively, you could restart the entire system.

This should prevent the device from disconnecting from the network when the system believes it is idle.