Ubuntu – How to enable Wake On Lan (WOL) in Ubuntu 16.04
16.04wakeonlan
How to enable Wake On Lan (WOL) in Ubuntu 16.04 LTS?
Best Answer
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 googlingUbuntu 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/wol@.service (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/wol@eth3.service to /etc/systemd/system/wol@.service.
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):
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
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
Best Answer
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/wol@.service
(keep the @ symbol). Put this in it:Enable this for the interface on boot, run the following command (change eth3 with your interface):
You should see something like this:
To check if it's enabled, run the following command (change eth3 with your interface) and it should return
enabled
:To test this, reboot and run (change eth3 with your interface):
You should see a line with the following:
Sources:
upstart:
systemd: