knowledge/technology/internet/Wake on LAN.md

2.2 KiB

obj wiki arch-wiki
concept https://en.wikipedia.org/wiki/Wake-on-LAN https://wiki.archlinux.org/title/Wake-on-LAN

Wake on LAN

Wake-on-LAN (WoL or WOL) is an Ethernet or Token Ring computer networking standard that allows a computer to be turned on or awakened from sleep mode by a network message.

Magic Packet

The magic packet is a frame that is most often sent as a broadcast and that contains anywhere within its payload 6 bytes of all 255 (FF FF FF FF FF FF in hexadecimal), followed by sixteen repetitions of the target computer's 48-bit MAC address, for a total of 102 bytes.

Since the magic packet is only scanned for the string above, and not actually parsed by a full protocol stack, it could be sent as payload of any network- and transport-layer protocol, although it is typically sent with UDP.

Creating & sending magic packet

There exists various software for creating magic packets. This is an example in Python

import socket

def wol(lunaMacAddress: bytes):
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)

    magic = b'\xff' * 6 + lunaMacAddress * 16
    s.sendto(magic, ('<broadcast>', 7))

if __name__ == '__main__':
    # pass to wol the mac address of the Ethernet port of the appliance to wakeup
    wol(b'\x00\x15\xB2\xAA\x5B\x00')

Setup

WOL must first be enabled in the UEFI / BIOS of the computer.

Setup on Linux

To check and enable WOL on Linux the tool ethtool is used.

Check if WoL is enabled:

$ ethtool <interface> | grep Wake-on
Supports Wake-on: pumbag
Wake-on: d

If Supports Wake-on: only shows d WOL is not supported on that interface.

Enable WoL with this command:

ethtool -s <interface> wol g

To enable WOL persistently one can use Systemd:

File: /etc/systemd/system/wol@.service

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

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

[Install]
WantedBy=multi-user.target

Then activate this new service by starting wol@<interface>.service.