---
title: Set up Wake-on-LAN with systemd
url: https://photostructure.com/coding/wake-on-lan/
date: 2023-03-04
keywords: Linux, performance
---


PhotoStructure is (mostly) developed on an [AMD Ryzen 9
5950X](https://www.amd.com/en/processors/ryzen-for-creators) workstation.

It's nice and speedy, but consumes **500+ watts** when busy, and **200 watts**
at idle!

I can't do much about power consumption while I'm using it, but that idle
consumption certainly could be reduced.

## ⚡ Suspend-to-RAM when idle

The latest version of Ubuntu (and my current motherboard) support "[suspend to
RAM](https://help.ubuntu.com/community/SuspendHowto)" (much like a laptop).
Configuration can be done via the built-in Settings app, which is simple and
works. If you need more customization,
[Circadian](https://github.com/mrmekon/circadian) is an excellent alternative.

Power drops to 2 watts (!!) when suspended to RAM.

## ⌨️ Local wakeups

I come back to my workstation after my morning coffee, and it springs back to life when I hit a key on my USB keyboard. The system wakes up and is available in a couple seconds, and most things are right where I left them (except for Firefox, which regularly crashes, but all my prior tabs restore automatically when I re-launch it).

## 🌐 Remote wakeups: how to enable Wake-on-LAN

The issue is if I'm remote, and I need access to my workstation.

Is it possible to _remotely_ resume power on my workstation?

The answer is yes: [Wake-on-LAN](https://en.wikipedia.org/wiki/Wake-on-LAN) is a thing. Unfortunately, it typically requires a bit of tweaking.

Following the steps on the Ubuntu wiki, <https://help.ubuntu.com/community/WakeOnLan>:

1. Install `ethtool` (via `sudo apt install ethtool`)

2. Run `ip link` to get the name of your network device. Ignore `lo` (that's the [localhost LOopback device](https://en.wikipedia.org/wiki/Localhost#Loopback)) and any named `docker*` or `br*` devices (those are for docker and bridge networking). Mine happens to be called `enp5s0`.

3. Run `sudo ethtool $devicename | grep Wake` (replace `$devicename` with the name of your device). You'll see something like this:

   ```
     Supports Wake-on: pumbg
     Wake-on: d
   ```

   The `d` means `Wake-on` is disabled. Read the `ethtool man` page for details.

4. If `Supports Wake-on:` includes `g`, we're in business: we just need to set `Wake-on: g` _after every powercycle_. That's done by running `sudo ethtool -s $devicename wol g`.

   If you _don't_ see it, don't panic: it may just be disabled in your BIOS. Reboot and hit f2/del/f12 to enter BIOS configuration, and poke around--mine was enabled via a Power submenu.

## 🔧 How to enable Wake-on-LAN on reboot

If you've read to here, you've enabled Wake-on-LAN on your hardware... but might have caught the bit about needing to run `ethtool -s $devicename wol g` after every reboot.

Simple, add it to `/etc/rc.local`, right?

**NOPE**. That file's been gone for over a decade on many Linux distributions. Good idea, though, ~~old man~~ wise neckbeard.

Ah, just follow the `/etc/network/interfaces` instructions on the Ubuntu wiki?

**NOPE**, that file doesn't reliably exist since NetworkManager times.

_SO... It's gotta be something involving `systemd`, right?_

**CORRECT**. Run `sudo systemctl edit wol.service --full --force` and paste this into the editor. Replace `$deviceName` with the name of your device.

```ini
[Unit]
Description=Enable Wake-on-LAN
Documentation=https://help.ubuntu.com/community/WakeOnLan
After=network-online.target

[Service]
Type=oneshot
ExecStart=/sbin/ethtool -s $deviceName wol g

[Install]
WantedBy=network-online.target
```

Check that there were no errors with `sudo systemctl status wol`.

If you need to tweak anything, you can re-enable the service with `sudo systemctl enable --now wol`.

## ✅ Trust but verify

Verify this all worked by shutting down your computer, turning off the power supply for 10 seconds, then restarting (to make sure the physical network device isn't retaining prior settings).

After rebooting, `sudo ethtool $devicename | grep Wake` should show

```
  Supports Wake-on: pumbg
  Wake-on: g
```

## 🔐 Get your MAC address

The [MAC address](https://en.wikipedia.org/wiki/MAC_address) is a unique identifier that is used by Wake-on-LAN client applications to send the "magic packet" that will wake up your workstation.

If you're in Gnome, open the `Settings` app, select the `Network` tab, and click the gear by your wired network device.

Otherwise, run the `ip link` command, and look for the MAC address right after the "link/ether" line following your network device (remember to ignore the docker and bridge devices!)

## ✨ Finally, send the magic packet

Suspend your workstation, either via the command-line with `sudo systemctl suspend`, or via the menu bar > `Power off/log out` > `Suspend`.

You should be able to wake your sleeping workstation via another computer on your LAN by using either the `etherwake` or `wakeonlan` commands (both can be installed via `sudo apt install`).

Alternatively, some routers have "network tools" that support sending Wake-on-LAN magic packets.

## 📖 Read more

- https://help.ubuntu.com/community/SuspendHowto
- https://wiki.ubuntu.com/DebuggingKernelSuspend
- https://github.com/mrmekon/circadian
- https://help.ubuntu.com/community/WakeOnLan
- https://systemd.io/NETWORK_ONLINE/
- https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_basic_system_settings/assembly_working-with-systemd-unit-files_configuring-basic-system-settings

