20 lines
3.2 KiB
Gemtext
20 lines
3.2 KiB
Gemtext
> DATE: Thu 19 Dec 2024 18:35 By: konsthol@pm.me
|
|
|
|
# The magic of Wake-On-LAN
|
|
|
|
Years ago, some good friends of mine gifted me for my birthday, a Raspberry Pi 4 with 2GB of ram. It was and still is the most thoughful gift anyone has ever gotten for me. It aligns perfectly with my hobbies and I used it for a long time as a VPN server using WireGuard and I also played around with Pi-hole for a while as a network-wide ad blocker.
|
|
|
|
Eventually I became more interested in cloud computing and started self hosting many services on a VPS that I rent through MVPS. It has 4GB of ram and has currently many of the services I use in a day-to-day basis like my Gitea server, Searx, NTFY and many others. While it was definetely doable for the Raspberry Pi to host these, the 2GB of ram would not allow for every service to be run at the same time. You see, my friends were lucky to even find one because it was in the middle of the chip shortage problems.
|
|
|
|
One day as I was thinking about what kind of projects could I utilize a single Raspberry Pi for, it hit me. A simple Wake-On-LAN server. It requires almost no resources as it just needs to stay on and send out wol packages when I need it to. The Raspberry Pi is connected using Wi-Fi to the same network as my laptop. Usually if I wanted to wake my laptop up using Wake-On-LAN I would need to have it plugged with an ethernet cable with the router. However, the Raspberry Pi has an ethernet port and a cable has two ends. Which lead me to try to connect one end to the Pi and another one to the laptop. At first I begun with a simple shell script that used etherwake. A simple command-line tool that sends Wake-On-LAN Magic Packets. It worked like a charm. I had enabled Wake-On-LAN in my laptop's BIOS, it was enabled on the operating system, which I checked using ethtool and it was super easy to remotely wake my laptop up using a Termux shortcut on my phone which used ssh to connect to the Raspberry Pi and from there execute the etherwake command.
|
|
|
|
That setup was wonderful but I wanted to make it even better. It wasn't actually a Wake-On-LAN server at this point. The only service that was running on the Pi was SSH and I just used a command to wake just my laptop up. So after some research I came across Flask. With Flask I managed to make an actual server that used routes, authentication, logging rate limits and everything needed to make it robust, secure and functional. The main reason I currently prefer my project over etherwake, even though etherwake is still a great tool that follows the Unix philosophy "Do one thing and do it well", is because of it's dynamic nature. I can configure a .env file with many device's MAC addresses and have as many possible routes as the number of the devices. So for a laptop and a desktop I have LAPTOP_MAC="itsmac" and DESKTOP_MAC="itsmac" and can wake them up using http requests in the route /wol/laptop and /wol/desktop respectively.
|
|
|
|
=> /images/pic-selected-19-12-24_19-10-42.png Mascot
|
|
|
|
I would suggest anyone to take a look at my project's repo and if they find that it fits their needs, use the setupSingleBinary.sh script to grab the latest executable. The repo is over at
|
|
|
|
=> https://git.konsthol.eu/konsthol/WOL-Ly WOL-Ly
|
|
|
|
=> ..
|