How do Wake-On-LAN works
This post provides a deep technical dive into the Wake-on-LAN (WoL) protocol, explaining its underlying packet structure and how it functions at a low level. It meticulously details the components of a 'Magic Packet' and its transmission, complete with a practical Golang implementation for both creating and sending these packets. The clear, code-backed explanation of network fundamentals appeals directly to Hacker News's audience interested in system administration and network programming.
The Lowdown
Wake-on-LAN (WoL) is a network protocol designed to remotely power on computers or servers, useful for tasks like off-hours system maintenance or activating power-hungry machines only when needed. This article breaks down the technical specifics of how WoL operates, focusing on the construction and transmission of the special 'Magic Packet'.
- WoL Fundamentals: WoL functions by having a network interface constantly listen for a specific 'Magic Packet' on the network, even when the computer is powered off (but still receiving standby power). Upon detection, it signals the BIOS to initiate the boot process.
- Magic Packet Structure: A Magic Packet is composed of a 6-byte synchronization stream of
FFs, immediately followed by the target machine's MAC address repeated 16 times. Some implementations also support an optional password field for added security, though this is not universally supported by BIOS versions. - Packet Transmission: The Magic Packet doesn't require a full network stack; it can be sent via any network or transport protocol, with UDP being the most common and easiest method. It is typically sent to a broadcast address (e.g.,
255.255.255.255for IPv4) or a multicast address for IPv6, often on ports 0, 7, or 9. - Limitations: WoL has several constraints. It cannot wake machines across different networks or VLANs, requires prior knowledge of the target's MAC address (not its IP), and only works over wired Ethernet connections, not Wi-Fi. Furthermore, there's no guarantee of packet receipt or a confirmation mechanism, so success isn't always assured.
- Golang Implementation: The article provides a step-by-step guide to implementing a WoL sender in Golang. This includes a
CreateMagicPacketfunction that validates MAC addresses, formats the packet, and aSendMagicPacketfunction that handles IP validation, UDP connection, and packet transmission.
By demystifying the Wake-on-LAN protocol and providing a concrete Golang example, the article offers a comprehensive and actionable understanding of this essential network capability, enabling readers to implement their own remote wake-up solutions.