Wake On Lan with a Raspberry Pi

Magic packet

The magic packet is a frame that is most often sent as a broadcast and that contains anywhere within its payload 6 bytes of all 255 (FF FF FF FF FF FF in hexadecimal), followed by sixteen repetitions of the target computer’s 48-bit MAC address, for a total of 102 bytes.

  • Requires destination computer MAC address
  • Does not provide a delivery confirmation
  • May not work outside of the local network
  • Requires hardware support of Wake-on-LAN on destination computer
  • Most 802.11 wireless interfaces do not maintain a link in low power states and cannot receive a magic packet

TLDR: A magic packet is a string of numbers and letters in a pattern that computers recognize to mean “wake up.”

I went through several tutorials online and the writeup awfully assumed you were an experienced network professional! So I’m writing this to hopefully fill in the gaps I needed to get the job done the easy way. And the raspberry pi is $200 right now 👀 — the supply chain is bonkers.

The network map we are going to achieve

Set up Raspberry Pi

Let’s begin by setting up the raspberry pi. Why are we using a pi? The raspberry pi will be like a computer that we can ssh into from anywhere. The pi will have a library downloaded called Etherwake that can send magic packets.

Flash the Raspberry Pi

The raspberry pi runs off a microSD card with the operating system on it. We will download the operating system image and then use a software to flash the image onto the card.

  1. The image I used is called Raspbian Jessie lite. Click to download the zip. When it has downloaded, unzip the file. It should be several gigabytes large.
  2. The software I used to flash is called Balena Etcher. Click the link to download. (I’m using Balena over the official Raspberry Pi Imager because it corrupted my SD card and I ended up using Balena anyway to re-flash. Maybe it’ll work for you! 🤷‍♀)
Balena Etcher screenshot
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=US
network={
ssid="your wifi name here"
psk="your passwork here"
key_mgmt=WPA-PSK
}
#!/bin/bash# Replace "AA:BB:CC:DD:EE:FF" with the MAC address

echo "Going to wake up your PC..... <3"
sudo etherwake -i wlan0 AA:BB:CC:DD:EE:FF
-rwxr-xr-x 1 pi pi 364 May 15 02:36 wol.sh

Network Setup

Great! The pi is all set up. The next step is to do a couple simple things in your home network. You’ll need admin access to the router. To get to the admin panel, it’s usually something like ‘http://192.168.1.1/’ You can google the router brand to find the right URL.

Put the raspberry pi on a static ip

Every time a new device joins your wifi, your router has to be the DHCP which is like an “address-giver” The DHCP gives your device a temporary address. That is your device’s IP and is effectively a pointer. What we have to do is make sure that the pointer doesn’t change for the raspberry pi. We must make the IP static, the router should recognize the device and always assign it the same IP.

Port Forwarding

Now that your pi is on a static IP, we need to set your pi up for port forwarding. What that means is that we are going to be able to log into the raspberry pi from anywhere in the world — like going to a website.

Get a Domain to your network address

What does that mean? We’re going to get you a website URL that will point to your home wifi. Yes, that’s right. Sign up for noip. It’s a domain name service similar to buying your own website address — except it points to your wifi’s network IP. Your network IP is your address in the world wide web of the internet — it is external facing. To find your external facing IP, go to google and type in “What is my IP.” Your router will change it every two weeks. Your router will sent a message to your ISP (i.e Google fiber or spectrum) and your ISP will send back a new IP for you.

Set Computer to Allow Wake on Lan

Back at your chunky desktop, there’s a setting you’ll have to flip on. It’s called Wake on Lan. Both Apple and Windows machines usually have this feature. It’s the ability for a special packet to trigger the computer to wake up from sleep mode. The packet is called the Magic Packet.

Pull the Trigger, Dora.

Finally, we’re at the final stage.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Juliana Mei

Juliana Mei

Software Engineer — Blockchain, Cybersecurity, and Commercial Space