This post shows the steps required to set up Wake-on-LAN (WOL) on a 15-year-old computer running CentOS 7. I can imagine that different hardware configurations might need less or different steps.

Check WOL capabilities

First of all, make sure that your network interface card supports WOL. In the following, I will assume that the NIC is called enp1s4. Run

$ sudo ethtool enp1s4 | grep Wake
  Supports Wake-on: pumbg
  Wake-on: d

If the output contains the g option, your card supports waking up on the MagicPacket.

Enable WOL

You can manually enable WOL by running sudo ethtool -s enp1s4 wol g. However, with my setup, the option was reset every time I rebooted. From what I read online, it was possible to append a line with ETHTOOL_OPTS to /etc/sysconfig/network-scripts/ifcfg-enp1s4 to make the option persistent. Unfortunately, nowadays, it seems like this method does not work anymore.

The only method I found that worked on my computer is the one from Zivo NiX BLog. The idea is to create a service which enables WOL and configure the service to be executed once the NIC is ready.

Here are the steps.

Create the file /etc/udev/rules.d/99-wakeonlan and add the following line.

KERNEL="enp1s4", ACTION=="online", PROGRAM="/bin/systemctl start wakeonlan.service"

This adds a udev rule for the network interface card. When the card becomes online, a new service called wakeonlan is executed.

Then, create the file /usr/lib/systemd/systemd-wakeonlan, add

#!/bin/sh

# only usable for root
[ $EUID = 0 ] || exit 4

start() {
  ethtool -s enp1s4 wol g
}

stop() {
  sleep 0
}

case "$1" in
  start|stop) "$1" ;;
esac

and make the file executable.

$ chmod +x /usr/lib/systemd/systemd-wakeonlan

Finally, we need to create the service /usr/lib/systemd/system/wakeonlan.service with the following content.

[Unit]
Description=Configure Wake-up on LAN

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/lib/systemd/systemd-wakeonlan start
ExecStop=/usr/lib/systemd/systemd-wakeonlan stop

[Install]
WantedBy=basic.target

and enable it.

$ systemctl enable wakeonlan.service

These steps deviate from the ones in the linked document. The source disabled WOL again when the service is stopped. With my setup, service was stopped every time I shut down the computer, which defied the propose of WOL. The service described above does nothing when the service is stopped.

Enable signals in BIOS

With my old mainboard, I had to enable the Resume On PME# option. The naming of the option depends on the mainboard manufacturer.

Test

Shutdown the computer and log in at another computer in the same link-local network. On Ubuntu, you can send the magic packet using the wakeonlan tool

$ wakeonlan 00:16:3e:12:34:56

On another CentOS 7 machine, you can use ether-wake from the net-tools package.

$ sudo ether-wake 00:16:3e:12:34:56