How can I enable wake-on-lan permanently?

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

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


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