Wake-on-LAN (WoL) on Linux: Don’t Let Turning On Your Server Become a Nightmare

Network tutorial - IT technology blog
Network tutorial - IT technology blog

A 2 AM “Nightmare” Scenario

Imagine you’re sleeping soundly in the middle of the night after a long day at work, when suddenly your phone buzzes with a message: The server is down. You jump up, open your laptop to SSH in, but realize the machine at the office is completely off. Maybe someone accidentally shut it down, or a power flicker caused the “auto-power-on after power loss” feature to fail.

In my five years of managing infrastructure for a 50-person office, I’ve wasted countless hours just driving to the site to press that damn power button. This is a massive waste of time, especially when the server is located dozens of kilometers away. That’s why I always set up Wake-on-LAN (WoL) from the moment I unbox a machine.

How It Works: The Magic of the Magic Packet

The secret lies in the Magic Packet. When a computer is off but still plugged in, the network interface card (NIC) still consumes about 0.5W to 1W of power. This small amount of electricity allows it to remain in a “hibernation” state while listening for signals from the local network.

The NIC waits for a specific Ethernet frame. It contains 6 bytes of 0xFF, followed by 16 repetitions of that machine’s MAC address. When it detects the correct identifier, the NIC immediately triggers the motherboard’s power supply. Remember: This mechanism operates at Layer 2 (Data Link). At this stage, the machine doesn’t have an IP address, so don’t try to use Ping—it will definitely fail.

4 Steps to Properly Implement WoL on Linux

I’ve tested this process on hundreds of Ubuntu, Debian, and CentOS nodes. This is the fastest and most stable way to do it.

Step 1: Unlock in BIOS/UEFI

If the BIOS is locked down, all software is useless. Start your machine and press F2 or Del to enter setup. Look for sections related to Power Management. Enable options like “Wake up on LAN” or “Resume by PCI-E”. For the “ErP Ready” setting, you need to Disable it to ensure the NIC always has power when the machine is off.

Step 2: Configure the Network Card with ethtool

Next is the operating system’s job. The Swiss Army knife here is ethtool. Installing it takes only a few seconds:

sudo apt update && sudo apt install ethtool -y  # Ubuntu/Debian
sudo yum install ethtool -y                    # RHEL/CentOS

Type ip link to find the interface name (e.g., enp3s0). Then, check if the card supports WoL:

sudo ethtool enp3s0

Pay attention to the Supports Wake-on line. If you see the letter g (short for Magic Packet), congratulations—you’re halfway there. If the Wake-on line shows d (disabled), activate it with this command:

sudo ethtool -s enp3s0 wol g

Step 3: Prevent Configuration Loss After Reboot

A common issue is that ethtool resets after every reboot. To fix this, create a systemd service. This is much more professional than adding commands to your .bashrc file.

sudo nano /etc/systemd/system/wol.service

Copy the code below (replace enp3s0 with your network card name):

[Unit]
Description=Enable Wake-on-LAN
After=network.target

[Service]
Type=oneshot
ExecStart=/usr/sbin/ethtool -s enp3s0 wol g

[Install]
WantedBy=multi-user.target

Enable the service so it runs automatically every time the system boots:

sudo systemctl enable wol.service && sudo systemctl start wol.service

Step 4: Wake the Server Remotely

Finally, from another machine on the same network, use the wakeonlan tool to send the command. The syntax is extremely simple:

# Install on the control machine
sudo apt install wakeonlan -y
# Wake the machine with the corresponding MAC address
wakeonlan 00:11:22:33:44:55

The Tough Question: How to Turn on a Machine via the Internet?

Many people wonder how to send a Magic Packet from home to the office. Since this is a Layer 2 packet, it cannot hop across routers on its own. You have two options:

  1. Port Forwarding UDP 9: This is quite common but poses security risks, and many routers block incoming broadcast packets from the outside.
  2. Using a VPN (Recommended): I always keep a Raspberry Pi or a MikroTik router running 24/7. When needed, I VPN into the local network via WireGuard and then issue the wakeonlan command from that Pi. This method is perfectly secure.

Real-world Experience to Avoid Common Pitfalls

Don’t forget to check the quality of your network cables. Old Cat5 cables or those with internal damage to pins 4 and 5 might prevent the NIC from receiving enough power in standby mode. Additionally, prioritize using a static IP for your server. Although WoL uses the MAC address, a static IP allows you to check the machine’s status via Ping as soon as it finishes booting.

Configuring WoL only takes 10 minutes but can save you in emergency situations. Have you successfully set it up, or are you stuck at the BIOS step? Leave a comment and I’ll help you out!

Share: