How to enable Wake On Lan (WOL) in Ubuntu 16.04
Solution 1:
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 daemon -
systemd:
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
Solution 2:
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.
Solution 3:
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
source
Solution 4:
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.
Solution 5:
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