15

I want to enable wake-on-lan for my network cards, for always. The community guide recommends adding the relevant command to /etc/network/interfaces. In past experiences editing Ubuntu conf files, it's extremely likely that the network interface file is written anew every boot, if not every apt upgrade. What's the best way to ensure that wake-on-lan is enabled every boot?

4 Answers 4

13

A boot script run after the network cards are configured should do the trick. Ubuntu uses upstart. After reading about upstart jobs, ethtool, writing an upstart script, and searching the interwebs for a better solution, I came up with this from jevinskie (you'll want to put this in a file in /etc/init):

start on started network

script
    for interface in $(cut -d: -f1 /proc/net/dev | tail -n +3); do
        logger -t 'wakeonlan init script' enabling wake on lan for $interface
        ethtool -s $interface wol g
    done
end script
  • Starts when the nics are initialised
  • Grabs the nic names from /proc/net/dev
  • Logs actions to syslog
  • Acts on all nics found
  • Requires ethtool, so make sure it's installed first:

    sudo apt-get install ethtool
    

If you want to imbue just one nic with the power of awakening, something like this is more appropriate:

start on started network

script
    interface=eth0
    logger -t 'wakeonlan init script' enabling wake on lan for $interface
    ethtool -s $interface wol g
end script
5
  • 3
    I always thought wake on lan was a BIOS feature.
    – con-f-use
    Jun 9, 2011 at 22:38
  • @con-f-use It requires cooperation between BIOS and NIC. Both must support WOL. Furthermore, at least my nic has a bad habit of disabling wol after boot. The Ubuntu community wiki implies this is the case for many a computer.
    – djeikyb
    Jun 9, 2011 at 23:22
  • @con-f-use This superuser.sx thread on how power and rebooting works is also interesting as it relates to WOL.
    – djeikyb
    Jun 10, 2011 at 5:38
  • Does this need to be changed for systemd? Jan 1, 2016 at 20:56
  • @NathanOsman please add a systemd answer! this solution is still relevant to older but still supported LTS releases
    – djeikyb
    Jan 2, 2016 at 5:35
3

Create new file, let's say wakeonlanconfig, and put below lines to it:

#!/bin/bash
ethtool -s eth0 wol g
exit

Next set the permissions of the file, making it executable:

chmod a+x wakeonlanconfig

And finally make the script run on startup:

update-rc.d -f wakeonlanconfig defaults

For mor details please visit: http://lukasz-lademann.blogspot.com/2013/01/how-set-up-wol-wake-on-lan-on-thin.html

3

For me, using Netplan configurations worked (both for enabling and disabling WOL) since I am using Ubuntu.

Check this similar question about how to enable it. Canonical also provided some nice documentation on how to use Netplan:

Steps I followed

For my specific case, I wanted to disable Wake on Lan, but this boils down to just setting a boolean to true/false.

  1. I created this Netplan config YAML (you need sudo access to create a file in that dir):
# /etc/netplan/02-disable-wol.yaml
network:
  version: 2
  renderer: NetworkManager
  ethernets:
    eth-no-wakeonlan:
      match:
        macaddress: "11:22:33:44:55:66" # The eth interface's MAC address
      wakeonlan: false # To enable, set to true
      dhcp4: false # To enable, set to true
  1. To test this configuration, I ran sudo netplan try, which applies the configurations for some minutes before reverting. NOTE: Apparently, it's a known bug that netplan try fails to revert the configs. This tutorial says that a reboot should be enough (and deleting the yaml file, I assume)

  2. Then, I had to open the Ubuntu Network Settings UI to switch to the newly created ethernet interface netplan-eth-no-wakeonlan.

  3. Done!

On boot, Ubuntu should read all the files in /etc/netplan/*.yaml and apply their configs.

1

In Ubuntu 16.04 additionally set WOL_DISABLE=N in /etc/default/tlp to avoid getting WOL disabled by TLP power management.

http://linrunner.de/en/tlp/docs/tlp-configuration.html

Add NETDOWN=no in /etc/default/halt to prevent powering off the network card during shutdown

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .