Wake-on-lan

  |   Source

After upgrading my main desktop machine from Debian Jessie to Stretch, I wondered if my current solution to enable wake-on-lan on that machine could be replaced with something prepared in one of the upstream packages.

Wake-On-Lan

The old (but in my opinion still very elegant) solution consisted of a systemd template contained in /etc/systemd/system/wol@.service:

[Unit]
Description=Wake-on-LAN for %i
Requires=network.target
After=network.target

[Service]
ExecStart=/sbin/ethtool -s %i wol g
Type=oneshot

[Install]
WantedBy=multi-user.target

With this in place, all that is needed to enable wake-on-lan for eth0 is a simple:

root@deepthought:~# systemd enable wol@eth0.service

Thinking about it some more, it may be better to attach this functionality to the one service that knows about network connections, i.e. network-manager and surely that's what I now use, but lets look at the individual steps.

To find out if your interface supports and enables wake-on-lan, check with ethtool:

dzu@deepthought:~$ sudo ethtool enp2s0
Settings for enp2s0:
      Supported ports: [ TP ]
      Supported link modes:   10baseT/Half 10baseT/Full
                              100baseT/Half 100baseT/Full
                              1000baseT/Full
      Supported pause frame use: No
      Supports auto-negotiation: Yes
      Advertised link modes:  Not reported
      Advertised pause frame use: No
      Advertised auto-negotiation: Yes
      Speed: 1000Mb/s
      Duplex: Full
      Port: Twisted Pair
      PHYAD: 0
      Transceiver: internal
      Auto-negotiation: on
      MDI-X: Unknown
      Supports Wake-on: pg
      Wake-on: d
      Current message level: 0x0000003f (63)
                             drv probe link timer ifdown ifup
      Link detected: yes
dzu@deepthought:~$

The line "Supports Wake-on: pg" tells us that the adapter can wake on phy activity (p) or on a magic packet (g). "Wake-on: d" however tells us that the functionality is currently disabled (d).

Now let's see if there is a suitable network manager property for this functionality:

dzu@deepthought:~$ nmcli con show "Wired connection 1" | grep wake
802-3-ethernet.wake-on-lan:             1 (default)
802-3-ethernet.wake-on-lan-password:    --
dzu@deepthought:~$

Indeed that looks promising and after checking the documentation enabling it for the current configuration is easy enough:

dzu@deepthought:~$ nmcli con modify "Wired connection 1" 802-3-ethernet.wake-on-lan magic
dzu@deepthought:~$ nmcli con show "Wired connection 1" | grep wake
802-3-ethernet.wake-on-lan:             64 (magic)
802-3-ethernet.wake-on-lan-password:    --
dzu@deepthought:~$

All that is left to do is to check that wake-on-lan is indeed enabled on the adapter after re-activating the connection:

dzu@deepthought:~$ sudo nmcli con up id "Wired connection 1"
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/20)
dzu@deepthought:~$ sudo ethtool enp2s0
Settings for enp2s0:
      Supported ports: [ TP ]
      Supported link modes:   10baseT/Half 10baseT/Full
                              100baseT/Half 100baseT/Full
                              1000baseT/Full
      Supported pause frame use: No
      Supports auto-negotiation: Yes
      Advertised link modes:  Not reported
      Advertised pause frame use: No
      Advertised auto-negotiation: Yes
      Speed: 1000Mb/s
      Duplex: Full
      Port: Twisted Pair
      PHYAD: 0
      Transceiver: internal
      Auto-negotiation: on
      MDI-X: Unknown
      Supports Wake-on: pg
      Wake-on: g
      Current message level: 0x0000003f (63)
                             drv probe link timer ifdown ifup
      Link detected: yes
dzu@deepthought:~$
Comments powered by Disqus