💻
🔧
🐧
Beginner
Bash
June 7, 2026

Wake-on-LAN Automation with Raspberry Pi Guide

Description

This guide covers Wake-on-LAN automation using a Raspberry Pi to wake up a PC on the local network via magic packets, and shows how to automate the process with a monitoring script that sends a magic packet whenever the PC is found to be offline.

Raspberry Pi 4 sending a Wake-on-LAN magic packet over a local network

Table of Contents

  1. Prerequisites on the Target PC
  2. Part 1 — Sending Magic Packets from the Raspberry Pi
  3. Part 2 — Automatic Monitoring with WoL
  4. Final Notes



Prerequisites on the Target PC

The PC you want to wake up must have WoL enabled at both the OS and BIOS/UEFI level.

On Linux

Check WoL support:

bash

sudo ethtool eth0 | grep Wake

ethtool man page.

If it shows Wake-on: d, enable it:

bash

sudo ethtool -s eth0 wol g

To make the setting persistent across reboots, create a systemd service:

bash

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

ini

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

[Service]
Type=oneshot
ExecStart=/sbin/ethtool -s eth0 wol g
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

bash

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

On Windows

Device Manager → Network Adapter → Properties → Power Management tab → check Allow this device to wake the computer.

Also enable WoL in the BIOS/UEFI (usually found under Power Management).


Part 1 — Sending Magic Packets from the Raspberry Pi

Installation

bash

sudo apt update && sudo apt install wakeonlan -y

Find the MAC Address of the Target PC

From the target PC (while it is on):

bash

# Linux
ip link show | grep ether

# Windows
ipconfig /all | findstr "Physical"

Send the Magic Packet

bash

wakeonlan AA:BB:CC:DD:EE:FF

If it does not work, specify the network broadcast address explicitly:

bash

wakeonlan -i 192.168.1.255 AA:BB:CC:DD:EE:FF

Replace 192.168.1.255 with the correct broadcast for your subnet (e.g. 192.168.0.255 if your network is 192.168.0.x).

Quick Script for Frequent Use

bash

nano ~/wakepc.sh

#!/bin/bash
wakeonlan -i 192.168.1.255 AA:BB:CC:DD:EE:FF
echo "Magic packet sent!"

chmod +x ~/wakepc.sh
./wakepc.sh

Part 2 — Automatic Monitoring with WoL

The core of this Wake-on-LAN automation setup is a bash script running on the Raspberry Pi that periodically checks via ping whether the PC is online. If it is found to be offline, a magic packet is sent automatically.

Monitoring Script

bash

nano ~/wake_pc.sh

#!/bin/bash

# === CONFIGURATION ===
PC_IP="192.168.1.100"           # IP address of the target PC
PC_MAC="AA:BB:CC:DD:EE:FF"      # MAC address of the target PC
BROADCAST="192.168.1.255"       # Network broadcast address
INTERVAL=60                     # Seconds between each check
PING_ATTEMPTS=3                 # Number of pings to verify status
LOG="/var/log/wake_pc.log"      # Log file path

# === FUNCTIONS ===
log() {
    echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG"
}

pc_online() {
    ping -c "$PING_ATTEMPTS" -W 1 "$PC_IP" &>/dev/null
}

# === MAIN LOOP ===
log "Starting PC monitoring ($PC_IP)"

while true; do
    if pc_online; then
        log "PC online — no action needed"
    else
        log "PC offline — sending magic packet to $PC_MAC"
        wakeonlan -i "$BROADCAST" "$PC_MAC"
    fi
    sleep "$INTERVAL"
done

chmod +x ~/wake_pc.sh

Edit the variables at the top of the script with your actual network values.

Read: Linux Bash Scripting Automation

Systemd Service for Automatic Startup

bash

sudo nano /etc/systemd/system/wake-pc.service

ini

[Unit]
Description=Monitor PC and send WoL if offline
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
ExecStart=/home/pi/wake_pc.sh
Restart=on-failure
RestartSec=10
StandardOutput=journal
StandardError=journal
User=pi

[Install]
WantedBy=multi-user.target

bash

sudo systemctl daemon-reload
sudo systemctl enable wake-pc.service
sudo systemctl start wake-pc.service

Master Linux systemd: Services and Daemon Management Guide

Management Commands

bash

# Check service status
sudo systemctl status wake-pc.service

# Follow the log in real time
tail -f /var/log/wake_pc.log

# Or via journalctl
sudo journalctl -u wake-pc.service -f

# Stop the service
sudo systemctl stop wake-pc.service

Sample Log Output

[2025-03-10 08:00:01] Starting PC monitoring (192.168.1.100)
[2025-03-10 08:00:01] PC offline — sending magic packet to AA:BB:CC:DD:EE:FF
[2025-03-10 08:01:01] PC offline — sending magic packet to AA:BB:CC:DD:EE:FF
[2025-03-10 08:02:01] PC online — no action needed
[2025-03-10 08:03:01] PC online — no action needed

Log Rotation (Optional)

To prevent the log file from growing indefinitely:

bash

sudo nano /etc/logrotate.d/wake-pc
/var/log/wake_pc.log {
    weekly
    rotate 4
    compress
    missingok
    notifempty
}

Linux Log Rotation: Complete Management Guide


Final Notes

AspectDetail
ConnectionThe target PC must be connected via Ethernet cable (Wi-Fi does not support WoL)
Static IPRecommended: assign a fixed IP to the PC via DHCP reservation on the router
Different subnetIf Pi and PC are on different subnets, a WoL relay may be required
Power supplyThe PC must remain plugged in to the mains even when switched off

Related Commands