I have a very power hungry desktop computer
for HTPC and a server for large file storage. When I’m travelling with my laptop, I obviously can’t carry all my files and data with me, so I occasionally use “remote desktop
” to access my desktop from the road. I also use a Plex Media Server
to stream content from my server. However, the computer has to be on for me to be able to do this. This means I need to leave the computer on all the time, just in case I need to access it. This wastes power, costs me money, and harms the environment. My Raspberry Pi
, on the other hand, consumes a minuscule amount of power, and is always on anyways, serving other purposes.
In this tutorial, I’ll show you how to run a simple mobile-friendly website from your Raspberry Pi that will allow you to remotely wake up your power-hungry computer, so you can remotely access it. When you’re done, just put it back to sleep from within the remote desktop service (or use the mobile app plus a small background server running on your desktop to put it back to sleep – this is described below). The app pings the computer from the Raspberry Pi to inform you of when the computer has woken up and established network connectivity. Follow along after the break…
When you’re done, here’s how this will work:
- From wherever you are in the world, navigate to your unique, dynamically updating URL (example.dyndns.org:5000)
- You’ll be presented with a screen that looks like this:
- Next, you’ll enter a passphrase that you’ve pre-allowed. If the wrong phrase is entered, a “denial” note will pop up, and you’ll be able to try again. If you enter the right phrase, the Raspberry Pi will send a Wake Up command to the network interface of the computer that you want to wake up. It will then ping that computer and display the results in real-time, so that you know when the computer has finished booting and is accessible. That screen looks like this:
- Once you’ve received confirmation that the computer is alive, you can access it as you normally would, depending on what you’re doing (via SSH, FTP, or Windows Remote Desktop, for example).
For the purposes of the following explanation and tutorial, I’ll define a few terms:
- Remote Computer: This is the “power-hungry” computer located on the same network as your Raspberry Pi. I’m assuming you are using a hardwired Ethernet connection, since Wake-On-LAN (WOL) does not work over Wi-Fi.
- WOL Sever (Raspberry Pi): This is the low-power, always-on, micro server that will be running on the same network as the remote computer. You don’t have to use a Raspberry Pi; any low-power platform capable of serving up web pages, running PHP, and sending Wake-On-LAN magic packets will work fine.
- Client: This is the computer, phone, or other web-connected device that will view the WOL control webpage.
- Router: I assume you are using a home router with a fairly standard feature set, and that you have administrative access to it. It should support DHCP address reservations, NAT port forwarding, and ideally support for a dynamic DNS updating service (like DynDNS or NoIP).
- Dynamic DNS Service: This is a service that handles redirecting a URL to your home’s dynamic IP address. Since most ISPs assign dynamic WAN IP addresses, you need to use a service like this to ensure you can maintain access to your home network, even when the externally-facing IP address changes.
Here’s what you need to do to get this working:
- Ensure that the remote computer supports Wake-On-Lan (WOL) functionality. You may need to boot into the BIOS and permit the computer to be woken up via the network interface. This will look different on nearly every BIOS. LifeHacker has a good tutorial showing how to enable WOL functionality. For a shortened version specifically for this tutorial go here.
- Setup your Raspberry Pi with a linux distribution if you haven’t already, and get it connected to your network. Adafruit has a great set of tutorials that can help you do the initial setup for your Raspberry Pi. I made a condensed version on one webpage here. (Note: some instructions are for older version but I was able to find my way through everything ).
- Log into your Router’s administration panel (in most scenarios you can do this by visiting your Gateway IP from your browser). Find the status page and locate the listing of attached clients. Identify your Raspberry Pi and your computer by their hostnames, and copy down their MAC addresses, and IP addresses. In the screenshot below, the hostname of the computer I want to control is “PHOENIX” and the Pi’s hostname is, appropriately, “raspberrypi.” This will vary by router, but the listing will look something like this (Note: I blurred out some of my personal info):
- Now, find the “DHCP Reservation” or “Static Leases” list in your router’s administration panel. You’ll configure your router to always assign your remote computer and the raspberry pi the same IP address every time they connect to the network. This ensures that you’ll be able to reliably forward data to them through the router. It will look something like this:
- Next, find the port forwarding configuration screen in your router’s administration panel. You’ll want to route HTTP data to the raspberry pi, and any remote service ports that you want to access to the remote computer. Importantly, many ISPs will block incoming traffic on port 80, the default HTTP port, to prevent customers from hosting websites from their residences. But, you’re smarter than they are! Simply route an arbitrary external port, to the internal port 80 on your Raspberry Pi. In the screenshot below, you can see that I am routing external port 5000 to internal port 80. This means that when you eventually access the WOL server, you’ll need to specify the port, like this: . Route the appropriate port for whatever services you want to access on the remote computer. In the screenshot below, I’ve routed port 3389, which is what Window’s uses for Remote Desktop. If you wanted to access an SSH server or SFTP server running on the remote computer, you could additionally route port 22. You can find a listing of ports used by various services on wikipedia.
- Next, you’ll want to sign up for a dynamic DNS updating service that your router supports. Different routers support different services and most likely will require DDWRT installed to configure. If you have an Apple Airport Extreme or Time Capsule then this is not an option. That is why I chose to create this tutorial since I got rid of my router with DDWRT.
- Follow my guide here if you want to also use your raspberry pi to configure and autoupdate your DynDNS.
- Sign up for a free account, and get a URL that looks something like this: yoursite.no-ip.org. NoIP even supports port 80 redirects, so you can configure your account to not require appending the non-standard port number to the end as described in the last step. Once you’ve got your dynamic DNS account, find the Dynamic DNS (DDNS) updating screen in your router’s administration panel, and enter your account info. Now, you’ll always be able to access your home network, without knowing the IP addresses, and the router will handle automatically updating where the URL directs when your dynamic IP changes!
- Now that your router is all set to handle everything, it’s time to get the Raspberry Pi setup. Access your Raspberry Pi over SSH and log in with the username (pi) and the password that you configured when you followed the setup tutorial linked from step 2 (ssh email@example.com). You’ll need to install WOL software and a webserver. Enter this command at the terminal to do so:
pi@raspberrypi ~ $ sudo apt-get install wakeonlan apache2 php5
pi@raspberrypi ~ $ sudo apt-get install git
pi@raspberrypi ~ $ git clone https://github.com/sciguy14/Remote-Wake-On-LAN-Server.git
pi@raspberrypi ~ $ sudo chown pi /var/www
pi@raspberrypi ~ $ sudo chgrp pi /var/www
pi@raspberrypi ~ $ mv Remote-Wake-On-LAN-Server/* /var/www
pi@raspberrypi ~ $ rm -rf Remote-Wake-On-LAN-Server/
pi@raspberrypi ~ $ rm -f /var/www/index.html
- Now, you’ll need to adjust the configuration settings so that they work with your particular network setup. Rename config_sample.php
to config.php. Then, open it for editing with a terminal editor such as nano or vim:
pi@raspberrypi ~ $ mv /var/www/config_sample.php /var/www/config.php
pi@raspberrypi ~ $ nano /var/www/config.php
Follow the instructions in the file to set your passphrase hash, the local IP/MAC for the computer to wake up, and the ping retry value. When you’re done, save and close the file.
Notes for the config.php file. You can add as many computers to the list that you want. For some reason to work with mine I had to included a space after mac address and ip address for it to work.
eg. “BC:5F:3T:33:44:6F ” and “192.168.1.132 ” notice a single space after mac/ip and before quotation
If the remote computer is Windows 8, you will need to change some settings to make it reply to ping requests (or else you won’t know when it has woken up). By default, Window 8 does not reply to pings. Follow these instructions
to make it reply.
I’ve added the ability to put the computer back to sleep using the mobile webapp. The new version of the code can still be found on GitHub. Follow the same instructions from above to copy it into /var/www on your Pi. For it to work, you’ll need to ensure that Curl is enabled for your PHP installation, and that your computer is running the Sleep-on-LAN application server:
- Install Curl on your Raspberry Pi for PHP
pi@raspberrypi ~ $ sudo apt-get install php5-curl
If it doesn’t work, you might need to update your repositories first:
pi@raspberrypi ~ $ sudo apt-get update
- Download the Sleep on LAN software and run it on your windows computer. Set it to launch at boot so that it will always be ready to go.
Note, with this updated version of the webapp, it will now ping the computer to check if it’s awake or not to decide if it should present you with a “Wake Up” or “Put to Sleep” button on the interface.
The app now includes a dropdown that allows you to pick a computer. The config file has been updated to include lists for computer names, IP addresses, and MAC addresses. You can now Wake/Sleep as many computers as you want! Thanks to GitHub user ahodgey for submitting a Pull Request
with most of this functionality (I made some updates to his pull request, and merged it into the master repository branch).
You’re done! Put the computer to sleep, visit the dynamic URL that you chose, and you should be presented with the screen that was shown earlier in the tutorial. When you input your passphrase, it will be compared with the hash by the PHP script. If it is approved, the Raspberry Pi will send a command to the remote machine to wake it up. The display will update in real time to show you when the machine has woken up and successfully joined the network. You can then access it using any program whose ports you’ve forwarded. Enjoy!