▤ Homelab

Wake-on-LAN and scheduled power-on for home servers

How to power homelab servers on only when needed: Wake-on-LAN, the magic packet, BIOS and Linux setup, rtcwake and automatic shutdown when the job is done.

Not all of a homelab needs to stay on day and night. A backup server that works for an hour a night, a workstation used for weekend experiments, a second NAS receiving data replication: keeping them on all the time means paying for energy for idle machines. The solution is to switch them on only when needed, with Wake-on-LAN or with scheduled power-on from the motherboard clock.

How Wake-on-LAN works

When a computer is off but plugged in, the network card can stay powered in a low-power mode, listening for a specific signal: the magic packet. This packet contains six bytes of value FF followed by the card's MAC address repeated sixteen times. When the card recognises it, it asks the motherboard to power the system on.

The packet is usually sent as a broadcast on the local network, often as a UDP datagram on port 9 or 7. Being a broadcast, it does not normally cross routers: the sender must be on the same network or VLAN as the machine to wake, or you need a device that forwards it.

Setting up the machine to wake

In the BIOS or UEFI

The option has different names depending on the manufacturer: «Wake on LAN», «Power on by PCI-E», «Resume by LAN». Enable it, and often disable deep power-saving modes, such as certain eco power-off states, which also cut power to the network card.

In the operating system

On Linux, the ethtool tool shows and sets the card's behaviour:

ethtool enp3s0 | grep Wake-on
ethtool -s enp3s0 wol g

The letter g means waking via magic packet. On many distributions the setting is lost on reboot, so make it permanent through the network configuration, for example with the dedicated option in systemd-networkd or NetworkManager, or with a small systemd unit.

On Windows the option is in the network card's advanced properties, under power management.

Sending the packet

There are plenty of tools:

  • from Linux, commands such as wakeonlan or etherwake followed by the MAC address;
  • from a router with advanced firmware, which often includes a Wake-on-LAN page;
  • from an always-on homelab service, such as a small single-board computer, which can wake other machines on request or at set times;
  • from a phone, with dedicated apps, when on the home network or connected through a VPN.

To power on a server from outside the home you do not need to expose anything to the Internet: just join the home network over VPN and send the packet from there.

Scheduled power-on with the clock

Many motherboards can power themselves on at a set time using the system clock (RTC). You can set it in the BIOS, at a fixed time, or from Linux with rtcwake, which schedules the wake-up and powers off or suspends the machine:

rtcwake -m off -t $(date -d "tomorrow 02:00" +%s)

The command shuts the system down and schedules power-on at 2 a.m. the next day. Not every motherboard supports waking from a full power-off; some only work from suspend. Test it to be sure.

A complete cycle: the nightly backup server

A concrete example I use in my work:

  1. at 2 a.m. a scheduled task on an always-on machine sends the magic packet to the backup server;
  2. the server boots; a systemd unit waits until the backup disk is mounted;
  3. the backup or sync jobs start, or the main server starts them in turn;
  4. when they finish, a script checks there are no active transfers and shuts the machine down;
  5. an alert reports if the server did not power on or did not complete its work by a certain time.

The saving is real: a machine on for two hours a day instead of twenty-four uses about a twelfth of the energy.

Limits and common problems

Problem Likely cause
The machine does not power on option disabled in the BIOS, or network card unpowered when off
Works after shutdown, not after a power cut many cards lose the setting when power is lost
Works only from some devices the sender is on another network or VLAN
Powers on by itself wake set for any traffic, not just the magic packet
Does not work over Wi-Fi many wireless cards do not support waking from off

For the power cut case, also set the BIOS behaviour when power returns, and decide deliberately whether the machine should come back on or stay off.

When it is not worth it

Frequent power cycling has a cost: boot times, spinning disks starting up again, services that have to reconnect. For machines needed several times a day, or that must respond within seconds, staying on with good idle power saving is often preferable.

In short

  • The magic packet wakes a powered-off machine if the BIOS and network card allow it.
  • On Linux it is enabled with ethtool ... wol g and must be made permanent in the network configuration.
  • The packet stays on the local network: from outside the home, go through the VPN.
  • rtcwake and the BIOS allow fixed-time power-on with no other devices.
  • It is ideal for backup and replication servers, less so for services in constant use.
MM
Marco Marzaduri

Marco Marzaduri works in cybersecurity, digital forensics and web development. A computer science graduate, he combines rigorous technical analysis with attention to the people who use technology.

Read also