2

Ubuntu's networking stack is constantly evolving and most previous information on enabling Wake-on-LAN for an interface is outdated (like the Ubuntu wiki).

Now that Ubuntu uses Netplan instead of /etc/network/interfaces, how do I enable Wake-on-LAN automatically whenever a particular interface comes up?

rgov
  • 449

4 Answers4

4

I fixed it by adding a file to /etc/netplan, named /etc/netplan/50-wol.yaml

the contents of the file are: (fill in your own mac-address).

network:
  version: 2
  renderer: NetworkManager
  ethernets:
    enp2s0:
      match:
        macaddress: XX:XX:XX:XX:XX:XX 
      wakeonlan: true
      dhcp4: yes
0

The wiki tells us we need to run ethtool -s <interface> wol g when the interface comes up.

Although Ubuntu 20.04 has ifupdown scripts under /etc/network/if-up.d, Netplan provides different guidance on how to run post-up hook scripts that suggests using networkd-dispatcher.

The manual page for networkd-dispatcher does not explain how to detect which interface is going down but the source code shows several environment variables that get set including IFACE.

So we can create /etc/networkd-dispatcher/routable.d/50-wake-on-lan (and chmod +x it) with a script like this:

#!/bin/sh -eu

case "$IFACE" in enp60s0) ethtool -s <interface> wol g ;; esac

rgov
  • 449
0

For me really helped this post: https://forum.manjaro.org/t/troubles-with-setting-up-wol/24815/3

TLDR: execute sudo systemctl disable tlp

TLP is for power management on laptops etc. It is unlikely that you will need TLP on a system that you want to be able to remotely start a machine.

After execution of the command above WoL became persistent and you don't need to apply netplan after every reboot.

0

As far as I understand netplan merges all configuration files.

So for those of you who pass by here looking for a general solution I have to offer this based on the current 24.04 LTS Desktop:

#!/bin/bash

Get the names of all interfaces.

Filter interfaces with grep which you don't need.

Could also be done with jq if one wants to spend more time on it.

mapfile -t interfaces < <( ip -json -pretty link show
| jq -r ".[].ifname"
| grep -vE "(bond|lo|tailscale)" )

[[ -z "${interfaces[*]}" ]] && { echo "Error: No interfaces selected." exit 1 }

Create upper part of the temporary service unit.

tmp_file_netplan="$(mktemp)" tee "${tmp_file_netplan}" > "/dev/null" << EOF network: version: 2 renderer: NetworkManager ethernets: EOF

for interface in "${interfaces[@]}"; do

tee -a "${tmp_file_netplan}" > "/dev/null" << EOF ${interface}: wakeonlan: true EOF

done

Install the file and apply the new configuration

sudo mv -v "${tmp_file_netplan}" "/etc/netplan/02-wol.yaml" sudo netplan apply

I had an invocation of gum to interactively select interfaces (gum choose --no-limit). But lets stick to a solution here that works out of the box for every one.

If you are using the Server variant or a different version you have to check the other configuration files if something else than renderer: NetworkManager is used and decide what's best.

LiveWireBT
  • 29,597