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,941
- 32,005
5 Answers
(NB this answer is for my original question, which was for ubuntu 11.04… your mileage may vary, especially as the years turn to decades)
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
- 32,005
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 tryfails 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.
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
- 4,176
- 31
The answers here are either outdated or missing important information. On modern versions of ubuntu netplan is the way to go, but in order to set particular features you need to passthrough to network manager. Here is what worked for me:
network:
version: 2
ethernets:
NM-3bc8f989-e4ad-359e-89d6-8e66e83d93ef:
renderer: NetworkManager
wakeonlan: true
networkmanager:
uuid: "3bc8f989-e4ad-359e-89d6-8e66e83d93ef"
name: "Wired connection 1"
passthrough:
802-3-ethernet.wake-on-lan: "magic,unicast"
Documentation for passthrough settings can be found here: https://www.networkmanager.dev/docs/api/latest/nm-settings-nmcli.html
And you can test the outcome using the network manager cli, for instance:
sudo nmcli connection modify "Wired connection 1" 802-3-ethernet.wake-on-lan magic
- 111
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
- 1,151
- 1
- 10
- 15