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
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
-
3
-
@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.– djeikybJun 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.– djeikybJun 10, 2011 at 5:38
-
-
@NathanOsman please add a systemd answer! this solution is still relevant to older but still supported LTS releases– djeikybJan 2, 2016 at 5:35
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
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
.
- 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
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 thatnetplan try
fails to revert the configs. This tutorial says that a reboot should be enough (and deleting the yaml file, I assume)Then, I had to open the Ubuntu Network Settings UI to switch to the newly created ethernet interface
netplan-eth-no-wakeonlan
.Done!
On boot, Ubuntu should read all the files in /etc/netplan/*.yaml
and apply their configs.
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