SkillPilotAI

Wake-on-LAN: etherwake, wakeonlan

Wake-on-LAN (WoL) switches on a sleeping or powered-off computer by sending it one special 'magic packet' over the LAN. wakeonlan sends it inside UDP, etherwake sends it as a raw Ethernet frame, and the target's NIC and BIOS must be set up to listen for it.

192.1 Why is it used?

  • Power on office or lab PCs remotely for patching, backups or remote desktop without walking to them.
  • Lets machines sleep when idle (saves power) and still be reachable on demand.
  • Linux has both etherwake (RHEL: ether-wake, net-tools) and wakeonlan; macOS has only wakeonlan (brew install wakeonlan).
  • Windows has no built-in sender (third-party tools like WakeMeOnLan), but the target-side setting exists on every OS.

192.2 How it works: the magic packet

  • Payload = 6 bytes of FF (sync stream) + the target MAC repeated 16 times = 102 bytes.
  • It is sent as a broadcast, so the switch floods it on every port of the LAN.
  • The sleeping PC's CPU is off but its NIC runs on standby power and scans every frame for its own MAC x16.
  • When it matches, the NIC signals the motherboard to power on; other PCs ignore the packet.
Magic packet journey on the same LAN
  1. 1.Sender (192.168.1.10) builds 6 x FF + target MAC x 16 (102 bytes)

  2. 2.Sends as broadcast: UDP port 9/7 (wakeonlan) or raw frame 0x0842 (etherwake)

  3. 3.Switch floods the broadcast to every port

  4. 4.Another PC (192.168.1.60) does not see its own MAC and ignores it

  5. 5.Sleeping PC's NIC (standby power) sees its MAC 16 times

  6. 6.NIC sends power-on signal to the motherboard, PC boots

Another subnet: directed broadcast
  1. 1.Target sits in 192.168.20.0/24 behind a router

  2. 2.A 255.255.255.255 broadcast stops at the router

  3. 3.wakeonlan -i 192.168.20.255 sends a directed broadcast

  4. 4.It travels to the router like unicast

  5. 5.Router broadcasts it into 192.168.20.0/24 (only if directed broadcast is allowed)

Most routers block directed broadcast by default; etherwake cannot cross a router at all

192.3 Lab: find the target MAC

  • Isolated Docker bridge: sender 192.168.212.10, target 192.168.212.20 with a made-up MAC.
  • A magic packet needs the MAC, and a sleeping PC does not answer ARP, so note the MAC while it is awake (ip neigh).
Terminal
ping -c 2 192.168.212.20ip neigh show 192.168.212.20wakeonlan -vetherwake -V
Output
$ ip neigh show 192.168.212.20192.168.212.20 dev eth0 lladdr 02:00:00:00:19:2a REACHABLE$ wakeonlan -vwakeonlan version 0.41$ etherwake -Vetherwake.c: v1.09 11/12/2003 Donald Becker, http://www.scyld.com/Specify the Ethernet address as 00:11:22:33:44:55.

192.4 wakeonlan (UDP)

Terminal
wakeonlan -i 192.168.212.255 -p 9 02:00:00:00:19:2atcpdump -i eth0 -n -XX -c 1 'udp port 9 or ether proto 0x0842'
Output
11:57:58.340605 IP 192.168.212.10.38315 > 192.168.212.255.9: UDP, length 102        0x0000:  ffff ffff ffff ba36 0d49 932b 0800 4500  .......6.I.+..E.        0x0010:  0082 5c78 4000 4011 b397 c0a8 d40a c0a8  ..\x@.@.........        0x0020:  d4ff 95ab 0009 006e 2adb ffff ffff ffff  .......n*.......        0x0030:  0200 0000 192a 0200 0000 192a 0200 0000  .....*.....*....        0x0040:  192a 0200 0000 192a 0200 0000 192a 0200  .*.....*.....*..        0x0050:  0000 192a 0200 0000 192a 0200 0000 192a  ...*.....*.....*        0x0060:  0200 0000 192a 0200 0000 192a 0200 0000  .....*.....*....        0x0070:  192a 0200 0000 192a 0200 0000 192a 0200  .*.....*.....*..        0x0080:  0000 192a 0200 0000 192a 0200 0000 192a  ...*.....*.....*
  • -i 192.168.212.255 keeps the packet on the lab bridge instead of the default 255.255.255.255; -p 9 is the discard port.
  • First line: destination MAC ff:ff:ff:ff:ff:ff. The 6 FF bytes start at the end of line 0x0020, then 0200 0000 192a repeats 16 times.
  • UDP length 102 = exactly the magic payload.
Terminal
wakeonlan -i 192.168.212.255 02:00:00:00:19:2a 02:00:00:00:19:2bwakeonlan -f /tmp/lab.wolwakeonlan -i 192.168.212.255 -p 7 02:00:00:00:19:2awakeonlan -i 192.168.212.255 -f /tmp/lab.wol 02:00:00:00:19:2cwakeonlan -n -i 192.168.212.255 02:00:00:00:19:2a
Output
$ wakeonlan -i 192.168.212.255 -f /tmp/lab.wol 02:00:00:00:19:2cSending magic packet to 192.168.212.255:9 with 02:00:00:00:19:2aSending magic packet to 192.168.212.255:9 with 02:00:00:00:19:2bSending magic packet to 192.168.212.255:9 with 02:00:00:00:19:2c(target)11:58:48.928193 IP 192.168.212.10.53308 > 192.168.212.255.9: UDP, length 10211:58:48.928514 IP 192.168.212.10.34759 > 192.168.212.255.9: UDP, length 10211:58:48.928739 IP 192.168.212.10.36566 > 192.168.212.255.9: UDP, length 1023 packets captured$ wakeonlan -n -i 192.168.212.255 02:00:00:00:19:2aUnknown option: nSending magic packet to 192.168.212.255:9 with 02:00:00:00:19:2a
OptionMeaning
MAC / MAC MAC ...wake one MAC, or several in one run (one packet each)
-i 192.168.1.255destination IP (default 255.255.255.255)
-p 9 | 7UDP port (default 9 discard; 7 echo for some firewalls)
-f lab001.wolfile with a MAC (and broadcast IP) per line; extra MACs can follow
-v / -hversion / help
-ndoes not exist in 0.41: prints 'Unknown option: n' and still sends

192.5 etherwake (raw Ethernet frame)

  • Uses a raw socket, so it needs root / CAP_NET_RAW (only the sender container got NET_RAW).
  • Builds a frame with EtherType 0x0842 and no IP or UDP header: 14-byte Ethernet header + 102-byte payload = 116 bytes.
  • -b sends to the broadcast MAC, which helps with switches that drop unknown unicast.
Terminal
etherwake -i eth0 02:00:00:00:19:2aetherwake -b -i eth0 02:00:00:00:19:2aetherwake -D -i eth0 02:00:00:00:19:2aetherwake -i eth0 -p 00:22:44:66:88:aa 02:00:00:00:19:2aetherwake -i eth0 -p 192.168.212.1 02:00:00:00:19:2aecho '02:00:00:00:19:2a target' >> /etc/ethersetherwake -i eth0 target
Output
$ etherwake -b -i eth0 02:00:00:00:19:2a(target) $ tcpdump -i eth0 -n -XX -c 1 'ether proto 0x0842'11:59:25.574202 ba:36:0d:49:93:2b > ff:ff:ff:ff:ff:ff, ethertype Unknown (0x0842), length 116:        0x0000:  ffff ffff ffff ba36 0d49 932b 0842 ffff  .......6.I.+.B..        0x0010:  ffff ffff 0200 0000 192a 0200 0000 192a  .........*.....*
  • -D shows debug info (sendto sent 116 bytes). A 6-byte SecureOn password makes the frame 122 bytes; a 4-byte dotted password is appended as its 4 bytes.
  • A name in /etc/ethers (02:00:00:00:19:2a target) lets you run etherwake -i eth0 target.
Option / exitMeaning
Host-IDMAC or a name from /etc/ethers (default interface eth0)
-bsend to broadcast MAC
-Ddebug (repeat for more)
-i eth1another interface
-p 00:22:44:66:88:aa / -p 192.168.1.16-byte / 4-byte SecureOn password
-Vversion (without a MAC also exits 3)
exit codes0 ok, 1 send/interface (eth9: No such device), 2 permission, 3 params (unknown name)

192.6 Comparison: wakeonlan vs etherwake

Pointwakeonlanetherwake
TransportUDP port 9 (or 7) inside IPRaw Ethernet frame, EtherType 0x0842
Frame sizeUDP length 102116 bytes (14 header + 102)
Crosses a router?Yes, with -i directed broadcast (router must allow)No, no IP header: same LAN only
PrivilegesNormal userroot / CAP_NET_RAW
PlatformsLinux, macOSLinux
Extras-f file, several MACs, -p port-b broadcast, SecureOn -p, /etc/ethers names

192.7 Enabling WoL on the target

Output
# Linuxethtool eth0 | grep -i wake          # Wake-on: g (magic) / d (disabled)ethtool -s eth0 wol g                # magic packet onethtool -s eth0 wol d                # WoL offnmcli ... wake-on-lan magic          # persistent across reboot# Windowspowercfg /devicequery wake_armedSet-NetAdapterPowerManagement -Name ... -WakeOnMagicPacket Enabled# macOSsudo pmset -a womp 1# BIOS/UEFI: Power On By LAN, Wake on PCI-E
Output
$ ethtool -h 2>&1 | grep -A1 -E '\[ wol '                [ wol %d[/%d] | p|u|m|b|a|g|s|f|d... ]                [ sopass %x:%x:%x:%x:%x:%x ]
  • In 'wol' letters, g = magic packet, d = disabled. The lab NIC is a veth, so ethtool -s eth0 wol g gives 'Operation not supported'; without NET_ADMIN it gives 'Operation not permitted'.
  • ethtool settings can reset after reboot; nmcli wake-on-lan magic makes it persistent.
  • Windows: Device Manager > adapter > Wake on Magic Packet, or Set-NetAdapterPowerManagement; powercfg /devicequery wake_armed lists wake-capable devices.
  • macOS: pmset -a womp 1 (same as 'Wake for network access'). First of all, Power On By LAN must be on in BIOS/UEFI.

192.8 Common mistakes

  • Thinking the IP is enough: a sleeping PC does not answer ARP, so a normal IP packet never leaves the sender. The MAC inside a broadcast is the trick.
  • Using etherwake for another subnet: a raw frame has no IP header, so the router cannot forward it.
  • Enabling WoL only in the OS and not in the BIOS (or vice versa).
  • Forgetting the router blocks directed broadcast by default.
  • Not verifying: run tcpdump -XX on the target (or a mirror port) to see the 6 x FF + MAC x 16 pattern.

192.9 Interview tips

  • Magic packet = 6 x FF + target MAC x 16 = 102 bytes, sent as broadcast.
  • Transport: raw frame 0x0842 (etherwake) or UDP 9/7 (wakeonlan).
  • Target NIC listens on standby power; WoL must be on in BIOS and OS.
  • Another subnet: wakeonlan -i <directed broadcast> and allow it on the router.
  • Verify with tcpdump -XX on the target.