The Wake-on-LAN (WoL) feature allows you to remotely wake up a Linux computer by sending a special broadcast Ethernet packet (magic packet) containing the MAC address of the host you want to turn on.
Before enabling WoL on Linux, you need to make sure that your motherboard supports this feature and enable it in the BIOS setting. Restart the host and open the BIOS (UEFI) settings. The name of the WoL option may differ depending on the vendor, motherboard model, and firmware version. This option can be called Wake on PCI/PCI-E
, Power or Resume on PCI/PCI-E
, S5 Wake on LAN
. Find and enable this option. Save the BIOS settings.
The ethtool tool is commonly used to manage Wake On LAN in Linux. Install it:
$ sudo apt install ethtool
List network interfaces:
$ ifconfig
Copy the interface name of your Ethernet LAN adapter and run the command:
$ sudo ethtool enp3s0 | grep "Wake-on"
In this case, WoL is disabled (d).
Enable Wake on LAN for the specific adapter:
$ sudo ethtool --change enp3s0 wol g
The Wake On Lan option should change to g (Wake on MagicPacket).
netlink error: cannot enable unsupported WoL mode (offset 36)
‘ indicates that WoL is not supported by the network adapter or is disabled in the BIOS.You can now remotely wake up your Linux host. However, the network interface’s WoL option will be reset on reboot. There are several ways to automatically enable Wake on LAN for the adapter when the computer boots.
NetworkManager is the default network management tool in many Linux distros including Ubuntu, Rocky, and Debian. In NetworkManager, you can enable WoL for an adapter using the nmcli command:
$ nmcli con show
Copy the name of the Ethernet connection (wired in this example) and enable WoL:
$ sudo nmcli c modify "wired" 802-3-ethernet.wake-on-lan magic
Check that Wake on LAN is enabled on the interface:
$ nmcli c show "wired" | grep 802-3-eth
For other Linux distributions, you can use systemd to enable WakeOnLan on boot. Create a new systemd unit:
$ sudo systemctl edit wol.service --full --force
Add the following configuration:
[Unit] Description=Enable Wake-on-LAN After=network-online.target [Service] Type=oneshot ExecStart=/sbin/ethtool --change enp3s0 wol g [Install] WantedBy=network-online.target
Enable the service:
$ sudo systemctl daemon-reload
$ sudo systemctl enable wol.service
$ sudo systemctl start wol.service
Check that the service is running:
$ systemctl status wol
You can now test how Wake on Lan works on this host. Copy the MAC address of the network adapter on which you have enabled WoL.
Check that sleep mode is enabled on Linux:
$ sudo systemctl status sleep.target suspend.target hibernate.target hybrid-sleep.target
Put your Linux host to sleep:
$ sudo systemctl suspend
To send a magic packet on Linux, you can use wakeonlan or etherwake tool:
$ sudo apt-get install wakeonlan etherwake
To remotely wake a computer, enter its MAC address (WoL packets are not routed, so computers must be on the same LAN segment):
$ wakeonlan <MAC-address>
or:
$ etherwake <MAC-address>
After receiving the magic packet, the computer should wake up. Note that WoL doesn’t require opening the port in the Linux firewall. The WoL UDP broadcast packet is received and processed directly by the network adapter without using the Linux network stack.