.. title: Wake-on-lan
.. slug: wake-on-lan
.. date: 2017-04-28 22:24:18 UTC+02:00
.. updated: 2025-02-23 09:53:41 UTC+01:00
.. tags: linux, network-manager, systemd, wol
.. category: 
.. link: 
.. description: 
.. type: text

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.

.. image:: /images/wol.png
   :width: 200
   :alt: Wake-On-Lan
   :align: center

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

.. code-block:: ini

  [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:

.. code-block:: console

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

.. TEASER_END

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``:

.. code-block:: console

  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:

.. code-block:: console

  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
<https://developer.gnome.org/NetworkManager/unstable/settings-802-3-ethernet.html>`_
enabling it for the current configuration is easy enough:

.. code-block:: console
  
  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:

.. code-block:: console

  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:~$ 
  
Update 2020-04-11
-----------------

Corrected systemd instructions - thanks to "NoNeedForNameCalling"

Update 2025-02-23
-----------------

With a new main-board I discovered that a few years later, there's now
a nice GUI to enable wake-on-lan in `nm-connection-editor`:

.. image:: /images/nm-connection-editor-wol.png
   :width: 740
   :alt: nm-connection-editor
   :align: center
