How to enable Wake On Lan (WOL) in Ubuntu 16.04 LTS?
8 Answers
I've found a better way that worked for me. At least a cleaner way. Apparently Ubuntu changed upstart for systemd, in Ubuntu 15.04, Ubuntu 16.04 and presumably next versions too. I'm new to both systems but this worked for me.
I'm posting this because while googling Ubuntu 16 wol and other similar searches I came across with this post several times. This could help somebody else.
To keep WOL working, I had to re-enable it every time the system booted. To avoid doing this manually I used systemd for this purpose. This is what I did:
First, create the file
/etc/systemd/system/[email protected]
(keep the @ symbol). Put this in it:[Unit] Description=Wake-on-LAN for %i Requires=network.target After=network.target [Service] ExecStart=/sbin/ethtool -s %i wol g Type=oneshot [Install] WantedBy=multi-user.target
Enable this for the interface on boot, run the following command (change eth3 with your interface):
systemctl enable wol@eth3
You should see something like this:
Created symlink from /etc/systemd/system/multi-user.target.wants/[email protected] to /etc/systemd/system/[email protected].
To check if it's enabled, run the following command (change eth3 with your interface) and it should return
enabled
:systemctl is-enabled wol@eth3
To test this, reboot and run (change eth3 with your interface):
ethtool eth3
You should see a line with the following:
Wake-on: g
Sources:
- SystemdForUpstartUsers - Ubuntu Wiki
- Wake-on-LAN - ArchWiki
- systemd - ArchWiki
upstart:
Upstart is an event-based replacement for the /sbin/init daemon which handles starting of tasks and services during boot, stopping them during shutdown and supervising them while the system is running.
- upstart - event-based init daemonsystemd:
systemd is a suite of basic building blocks for a Linux system. It provides a system and service manager that runs as PID 1 and starts the rest of the system. (...)
- systemd
-
-
1There are 2 commands which one might find useful here:
sudo systemctl daemon-reload
andsudo systemctl start [email protected]
. Source: youtu.be/tdzrnGh94n8 Commented Aug 15, 2020 at 17:51
In Ubuntu 16.04 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
Enable Wake on LAN in /etc/network/interfaces
when static network configuration is used.
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.0.10
netmask 255.255.255.0
gateway 192.168.0.1
dns-nameservers 192.168.0.1
up ethtool -s eth0 wol g
Enable wake on lan in BIOS, enter the BIOS setup and look for something called "Wake up on PCI event", "Wake up on LAN" or similar. Change it so that it is enabled. Save your settings and reboot.
https://help.ubuntu.com/community/WakeOnLan
Warning some motherboards / network controllers don't support WOL from the cold boot (S5 state, where the power to the system is physically turned off and back on again). In that case, at least one power cycle (power up, shutdown) has to be performed. To mitigate to the problem, the BIOS can be configured to power up when AC is restored and schedule a shutdown inside Ubuntu afterwards. Refer to the motherboard's manual for further details.
-
-
those two comments about
WOL_DISABLE=N
andNETDOWN=no
should be part of help.ubuntu.com/community/WakeOnLan– AleczCommented Apr 5, 2018 at 1:25 -
Run the following in the terminal:
sudo ethtool -s {your network interface} wol g
sudo ethtool {your network interface}
you should see a g next to wake on lan after writing the second command
-
1Thank you. For 20.04, somehow... this was all I had to do. Network interface can be located via command
ip a
. The second command is to verify the first command, there should be a line that statesWake-on: g
. Commented May 24, 2020 at 17:01
If you use NetworkManager, then you can enable WOL via nmcli
:
nmcli connection show
Remember NAME of the connection of "802-3-ehternet" TYPE for DEVICE of interest. Say its name is "Wired connection 1". Then modify it properly:
nmcli connection modify "Wired connection 1" 802-3-ethernet.wake-on-lan magic
To get its MAC address:
nmcli connection show "Wired connection 1" | grep 802-3-ethernet.mac-address
From now you can turn it off and turn it on from another machine on the same LAN by wakeonlan 1a:2b:3c:4d:5e:6f
command, where 1a:2b:3c:4d:5e:6f
is MAC address of the LAN card from previous step.
-
Does this mean you don't have to install
ethtool
like other answers require? Commented Jun 16, 2020 at 23:56 -
-
Then it may qualify as an answer on this question: askubuntu.com/questions/1251060/… Commented Jun 17, 2020 at 11:06
-
@WinEunuuchs2Unix but one still need to install
wakeonlan
Commented Jun 17, 2020 at 11:35 -
This saves you from having to configure
/etc/network/interfaces
in 16.04 or worse create a script in/etc/network/dispatcher.d/
in 18.04 in order to makeethtool
enable WOL after reboot or resume from suspend when the NIC comes up. Commented Jun 17, 2020 at 12:30
In order for WOL to work, make sure your ethernet interface is properly being shut down by your system when you poweroff.
Try the following:
Create a bash script called wol_poweroff.sh on the /etc/rc6.d/ directory:
sudo nano /etc/rc6.d/wol_poweroff.sh
Put this code in it:
#!/bin/bash ifconfig eth0 down poweroff
Copy it to the /etc/rc0.d directory (so it also works with halt):
sudo cp /etc/rc6.d/wol_poweroff.sh /etc/rc0.d/wol_poweroff.sh
Make them both executable:
sudo chmod 755 /etc/rc6.d/wol_poweroff.sh sudo chmod 755 /etc/rc0.d/wol_poweroff.sh
Now test to see if it works by powering down your machine with sudo shutdown now
or sudo poweroff
and using a WOL tool to send a magic packet to it.
That was the only thing that worked for me. I found those steps at a bug report at launchpad.net.
According to the author, Robbie Williamson, this works because of the following:
To get WOL to work the ethernet interface must be properly brought down as part of the system shutdown. This should be performed as part of run levels rc0 and rc6, noting that Linux typically has 7 different run levels (or operating modes):
rc0.d - System Halted
rc1.d - Single User Mode
rc2.d - Single User Mode with Networking
rc3.d - Multi-User Mode - boot up in text mode
rc4.d - Not yet Defined
rc5.d - Multi-User Mode - boot up in X Windows
rc6.d - Shutdown & Reboot
Source: https://bugs.launchpad.net/ubuntu/+source/ifupdown/+bug/981461
Besides parameters suggested by @nkef you can set the following in /etc/network/interfaces if you use DHCP instead of static IP settings for the LAN adapter (here named eth0):
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
ethernet-wol g
(tested on Ubuntu 16.04 LTS).
This just bit me too under Ubuntu 18.04 (headless / minimal install), unfortunately the answers already listed here although they may seem to work at times are not going to provide a reliable solution as they create race conditions or fight with the likes of systemd, netplan and udev.
I had tried this approach too at first and it seemed to work, I am scheduling a system to boot each evening via WakeOnLan to run backups as the system BIOS does not provide a scheduled AC on option.
It would work for a few days and then refuse to wake, powering it on manually and running ethtool revealed that WoL had been disabled :
Wake-on: d
So I figured something else had to be turning it back off and having had many such issues in the last few years with systemd taking over parts of the system I decided to start here, lo and behold:
WakeOnLan= .. .. Defaults to off.
https://www.freedesktop.org/software/systemd/man/systemd.link.html
Examples online show something along the lines of :
/etc/systemd/network/50-wired.link
[Match]
MACAddress=<MAC ADDRESS>
[Link]
WakeOnLan=magic
How ever this was still not working. Then I came across this :
udevadm test-builtin net_setup_link /etc/systemd/network/50-wired.link
which resulted in :
Load module index
Parsed configuration file /lib/systemd/network/99-default.link
Parsed configuration file /etc/systemd/network/50-wired.link
Parsed configuration file /run/systemd/network/10-netplan-eno1.link
And what do I find in /run/systemd/network/10-netplan-eno1.link ?
[Match]
MACAddress=<MAC ADDRESS>
[Link]
Name=eno1
WakeOnLan=off
Solution Either:
- remove netplan,
- setup networking via a netplan configuration,
- or set the systemd .link file to have a higher priority.
As I already had the systemd .link file I simply renamed it to 00-wired.link, rebooted and now ethtool eno1 reports:
Wake-on: g
Without any extra services solely for the purpose of trying to enable WoL.
You should set ethtool
permanent on ubuntu 16.04, using the terminal:
cat /etc/network/interfaces
Edit the file, and after gateway line add this line:
up ethtool -s eth0 wol g
If yu can't find 'interfaces
' you should download the package from here: rb.gy/imfoq7
When the download completes, you can paste the 'interface' txt to etc/network
.
-
Please do not use url shorteners for web resources, as they may expire at some point and make this answer irrelevant. Use a direct link. Also, if able: when suggesting a packages please use a terminal command example for installation using
apt
ordpkg
, and overall try suggesting official resources and repositories.– PizzaCommented Jan 7, 2021 at 11:17 -