Setting Up Wake-on-LAN (WOL) in Linux

Instructions for configuring remote power-on of a computer over the network.
Setting Up WOL
First, you need to check that the Wake on LAN feature is enabled in the BIOS/UEFI.
Next, install ethtool
and check the settings.
sudo apt update && sudo apt install ethtool
sudo ethtool enp8s0 | grep "Wake-on"
If the output shows the value d, it means the mode is disabled. Change the mode to Wake on MagicPacket — g. You can find more about the modes in the documentation.
sudo ethtool --change enp8s0 wol g
The problem with manual changes is that it only works until the system is rebooted. Therefore, you need to add it to the startup using one of the following methods:
Netplan
In your configuration, for example in /etc/netplan/10-init.yaml
, you need to add the wakeonlan
option.
network:
version: 2
ethernets:
enp8s0:
dhcp4: true
wakeonlan: true
Interfaces
In your configuration, for example in /etc/network/interfaces
, you need to add the ethernet-wol
option.
auto enp8s0
iface enp8s0 inet dhcp
ethernet-wol g
NetworkManager
You need to check what your connection is called in the system and change its operation mode.
nmcli con show
sudo nmcli c modify "netplan-enp8s0" 802-3-ethernet.wake-on-lan magic
nmcli c show "netplan-enp8s0" | grep 802-3-eth
Systemd-networkd
Check your interfaces and adjust the necessary one.
networkctl list
sudo networkctl edit enp8s0
And add the option
[Link]
WakeOnLan=magic
Then activate the changes
sudo networkctl reload
sudo networkctl reconfigure
Systemd
If the previous options did not work for some reason, you can do this through systemd.
Create a new service
sudo systemctl edit wol.service --full --force
And add the setting for Wake on MagicPacket.
[Unit]
Description=Enable Wake-on-LAN
After=network-online.target
[Service]
Type=oneshot
ExecStart=/sbin/ethtool --change enp8s0 wol g
[Install]
WantedBy=network-online.target
Reload the modified service configurations and start it.
sudo systemctl daemon-reload
sudo systemctl enable wol.service
sudo systemctl start wol.service
systemctl status wol
Checking Functionality
Put your computer to sleep with sudo systemctl suspend
or turn it off with sudo systemctl poweroff
.
The indicator on the computer’s network card may not light up, depending on the manufacturer,
but it must be lit on the switch (even if it’s yellow), otherwise the magic packets will not reach your network card.
Next, from another computer, send the command to turn it on, specifying the MAC address of the computer to be turned on.
sudo apt update && sudo apt install etherwake
sudo etherwake -i ens3 11:22:33:44:55:66