BLOG > Raspberry Pi Remote Wake/Sleep-On-LAN Server

A Wake/Sleep-on-LAN Server Powered by a Pi!
A Wake/Sleep-on-LAN Server Powered by a Pi!

Note: This post and the accompanying software packages have been updated several times since this was originally posted. The most up-to-date releases and instructions can always be found in the GitHub Repo. Update notes are appended to the end of this blog post. The V3 Beta release automates most of the setup process, incorporates Dynamic DNS Auto-Updating, and supports signed HTTPS.

I have a very power hungry desktop computer. When I’m travelling with my laptop, I 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 desktop computer. 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 in the instructions). 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…

Once you’re done setting up your Pi-Powered Wake/Sleep on LAN Server, here’s how it will work…

  1. From wherever you are in the world, navigate to your unique, dynamically updating URL (wol.example.com)
  2. You’ll be presented with a screen that looks like the one below (note, you may get a security popup first, if you choose to use a self-signed certificate to enable HTTPS – this is described in the instructions). From this screen, you can select which machine you want to control, and you can view its state (awake or asleep). You can add as many machines that you want to control. Here, you can see that “Phoenix Desktop” is currently awake, and I have the option to put it to sleep:
  3. Next, you’ll enter a passphrase that you’ve pre-chosen. 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 can send a “Wake Up” or “Sleep” command to the remote machine. It will then ping that computer and display the results in real-time, so that you know when the computer has finished booting or when it has finished going to sleep. Here, you can see what that screen looks like when I put “Phoenix Desktop” to sleep remotely:
  4. You’ll receive a confirmation message when the computer has finished waking up or going to sleep. If you just woke it up, you can now perform normal remote access tasks, like SSH, FTP, or Windows Remote Desktop.

Ready to set this up for yourself? Visit the GitHub Project Wiki to follow the detailed installation instructions.

Updates:

  • 7/20/2013: Added the ability to put the computer back to sleep using the mobile webapp. Instructions updated on the Wiki.
  • 12/15/2013: The app now includes a dropdown that allows you to pick a computer. 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).
  • 09/14/2015: The Raspberry Pi WOL software now supports self-signed SSL encryption, meaning you can connect over HTTPS using a self-signed certificate. Additional security measures have also been implemented to reduce the risk of XSS vulnerabilities. Thanks to GitHub user felixrr for the Pull Request! You can still use ordinary HTTP if desired, and updated instructions can be found on the Wiki.
  • 01/24/2015: Software bumped to v2.0. Fixed lots of bugs, and confirmed working latest Raspbian Jessie release, with Apache 2.4.x (which had a bunch of breaking changes).
  • 01/31/2021: An x86 Docker Image is now available for this application (for Desktop, not Raspberry Pi). I have not independently validated its performance, but it pulls directly from my Repo. It’s available on DockerHub here.
  • 02/21/2021: The V3 Beta release automates most of the setup process, incorporates Dynamic DNS Auto-Configuration, and supports signed HTTPS. Follow the V3 Wiki Instructions to install it!

Supporting Documentation and Code

This project is licensed the GNU GPL v3.  Please Attribute and Share-Alike. You can download the source directly from the GitHub Repository linked below.

Get it on GitHub

383 comments

  1. Great guide thanks and almost working here – I can used this from my LAN perfectly but using my Dyndns address it does not work. Port forwarding on my Netgear DGND3700 works fine usually but in this case it will not forward the request to the Pi, and I cannot work out why this is.

    1. Just worked it out I had to change the Apache listening port and all good now. Thanks for a very useful app for the Pi.

  2. Hi Jeremy,

    I’m a total greenhorn when it comes to wep apps. I installed an apache server (xampp distribution), got your WOL control app running on it and of course edited the config file. No matter what i do though, the ping always sais that the client pc is still asleep. Tried it with numerous clients (windows 7), even disabled the firewall, but still no ping. I can, of course, ping them manually. The wake up itself won’t work as well. Manually, with a conventional WOL command line tool it works (meaning the PCs are capable of WOL). I suspect there is something, that won’t allow me execute PINGs and WOL packet sending. Is there such as restricted user rights on apache server?

    Thank you and kind regards
    Chris

  3. I have got this working with one computer which has two network ports and a second that has one – although it does not accurately state the wake or sleep state in all cases it wakes them up fine. I followed the steps above to the letter – is the Apache server you use the same one as the above guide installs?

    1. I installed it on my win 7 computer, not on a raspberry. Sorry for the confusion. It’s the xampp Distribution from apachefriends.org.

  4. Works perfekt! The only thing is, that the favicon or what ever dont really looks great on my iPhone 5 with iOS7. I only have a black square. Can u update this or can you say me how i can fix this? I allready searched arround but i can’t fixed it.

  5. I’ve got a strange one – I’m trying to set this up to power on my Desktop via my Pi in the following scenario:
    – Pi connected to wifi
    – Desktop connected to wifi
    – Pi connected to Desktop via Ethernet for purpose of WoL (using a DHCP-free IP range of 169.254.x.x)

    The Pi can remote-shutdown the Desktop as they’re sharing the wifi, however with your scripts I can’t find a way to get the Pi to send the magic packet through the ethernet instead of the wifi (as obviously WoL doesn’t work over most wifi, and it seems the Pi is defaulting to it’s main connection).

    Any ideas?
    acra

    1. You may be able to get that to work by specifying the IP address broadcast range of the target machine in the wakeonlan exec call instead of using the default broadcast mode. So, you would change this:
      exec (‘wakeonlan ‘ . $COMPUTER_MAC[$selectedComputer]);

      to this:
      exec (‘wakeonlan -i 168.254.1.255’ . $COMPUTER_MAC[$selectedComputer]);

      I haven’t tested this.

      1. I have this exact same set up and I would love to get Wake-On-LAN working, but I am not sure how to find or edit the wakeonlan exec call. Could you elaborate on that?

          1. Thanks for the reply! I gave this a shot but still was unable to get it to work.

            Here are the steps I have taken:
            1) Got the website running and can connect to it and sleep the computer when using wifi only.
            2) Set up the pi and home computer with static ips over the direct ethernet connection (can SSH over this connection, so I know it works)
            3) Changed the ip and MAC address in the config.php file to match the wired NIC on my home computer
            4) Edited the line you mentioned in the index.php file to point to the ethernet ip
            5) Followed some instructions here: http://www.raspberrypi.org/forums/viewtopic.php?f=36&t=3837

            None of this has quite worked yet and the current status is:
            1) The pi can properly detect the state of the computer
            2) Neither the sleep or wake commands work from the pi
            3) The sleep command gives me an error: ‘Command Failed: connect() timed out!’
            4) The wake command just continuously pings the computer

            Any other thoughts or suggestions would be greatly appreciated!

          2. Seems like the pi can’t see your computer on the specified IP. If you are SSH’d into your Pi, are you able to ping your computer with the IP you’re using the script? If the connect() is timing out, then it must not be able to ping it on that IP.

          3. So I was finally able to get it working. I’m not sure what I did to get the sleep command to work, but it eventually worked with the new ip. But for some reason the wake command still wouldn’t. So I went back and had another look at the index.php file and found my mistake: I forgot a space after the ip address and before the closing quotation mark. I was so mad that such a simple thing caused so much trouble but I added a space and everything worked beautifully. Thanks for the great tutorial and the helpful replies!

  6. You’re my hero, that’s exactly the thing i was looking for! (also a plex user)
    Borrowed a Raspberry Pi, due to my limited linux experience it was quitea bummer, but it works now :D

    I could “maybe” work on an Android App in Summer, when i have more time.

    many thanks!!!
    Andi

  7. Great utility for pi thanks.
    Question though as I am pretty ignorant about the pi.
    Is it possible to run this alongside homegenie on the pi or could it be incorporated into homegenie ?

  8. Hey, thanks for the great work, got it up and running in no time! Just a note I had the same problem as @Humschi above, seems iPhones do not like favicons with transparent backgrounds which it turns to black! I quickly modified the png images in bootstrap/ico to have a coloured background and now get a nice image on my home screen.

  9. Thank you for this tutorial.

    I adapted this for Xbian and everything seems to be working fine, except that I can’t assign port 80 in the router for the Pi because it’s used by another device in my house and assigned through UPnP. Is there a way to change for the Pi port 80 in something else, like 3123?

    Thank you in advance!

    1. Yes, you can adjust the port number in the apache configuration file. You could also direct a different external port to an internal port 80.

  10. Great tutorial,
    I was wondering if it was possible to disable the pass phrase. I only use from within my network.

    Thanks
    Abdel

  11. Hi Jeremy, great job. This was almost what I were looking for…and it works.

    However my main intention was to have this function for my NAS to wake up other Systems but since I have a RasPi running anyway, I can use it as well. (Maybe it’ll work on my NAS as well since it’s a Linux based system. But I’m not very familiar with Linux and want to be on the safe side – So I do not do any code changes on my NAS system)

    There’s one thing which does not really work, it’s the ping..it remains all time red although the NAS started very well – But I can live with that.
    As I said unfortunately I’m not very familiar with Linux and programming – In that case I would help myself and pimp your software for my needs…….well so I have to ask you gently if you could add a function whereI the WOL could run automatic by a timing setup. i.e. run every week on Monday and so on. This would be really great if the efford is not too much and you can work on this.

    Best regards, Dirk

    1. The ping is probably failing because your NAS is configured to ignore pings. You’ll need to change that if you want the ping function to work.

      As for the timed functionality, you can do that using a cronjob. Edit your cronjobs with crontab -e, and trigger the script from there.

  12. Does this work with Macs if they have “wake for network access” checked in the system preferences?
    Thanks in advance
    And also thanks for this wonderful idea. You now gave my Pi a purpose! :)

  13. I’m a bit confused on part 5 of your tutorial discussing port forwarding since the port forwarding page on my netgear router has a external start port, external end port, internal start port, and internal end port text box rather than just an internal and external port and I’m unsure what to enter into the extra text boxes.

  14. Hey Jeremy, thanks for the tutorial. I installed it and it works like charm!

    However, I run Linux at my home Desktop, which makes the Sleep function unusable with the software you linked. I did a simple Google search, but coundln’t find any suitable alternative for it. Do you know of any?

    Have you thought about strengthing and streching the password hash with salt and a couple thousand iterations? And maybe block the WoL from working after the 3rd or 4th wrong password attempt? Maybe it’s redudant, was just an idea. I messed a bit with the code to try to implement that, but my PHP skills remain at “Being able to reasonably understand VERY simple PHP code” :-)

    Awesome work you did here, I’m using the WoL script on a daily basis now!

  15. Here is to change the color of wake/sleep text

    {
    $asleep = true;
    echo “” . $COMPUTER_NAME[$selectedComputer] . ” is presently asleep.”;
    }
    else
    {
    $asleep = false;
    echo “” . $COMPUTER_NAME[$selectedComputer] . ” is presently awake.”;
    }

    Here is how to remove (uncomment) the password field:

    <?php
    //print_r($_POST); //Useful for POST Debugging
    $approved_wake = false;
    $approved_sleep = false;
    if ( isset($_POST['submitbutton']) ) {
    //$hash = hash("sha256", $_POST['password']);
    //if ($hash == $APPROVED_HASH)
    //{
    if ($_POST['submitbutton'] == "Wake Up!")
    {
    $approved_wake = true;
    }
    elseif ($_POST['submitbutton'] == "Sleep!")
    {
    $approved_sleep = true;
    }
    //}
    }

  16. Here is to change the color of the sleep wake text:

    {
    $asleep = true;
    echo “” . $COMPUTER_NAME[$selectedComputer] . ” is presently asleep.”;
    }
    else
    {
    $asleep = false;
    echo “” . $COMPUTER_NAME[$selectedComputer] . ” is presently awake.”;
    }

  17. First, thank you for the kind tutorial.
    However, I spent hours but I can’t get it work.
    The browser is displayed fine, but when I send wake up command it says “It’s Alive!” but my macbook actually does not wake up… Is it because my macbook runs OS X Mavericks?(10.9) Has anybody tried this tutorial on mavericks with success??

    Or maybe I did something wrong since I don’t know anything about linux or php thing.. I didn’t know where I should declare I will use 3389 port, (I opened it in my router setting, but I don’t understand where I should declare that I will use it to wake my computer) so in my config.php, I did “$COMPUTER_SLEEP_CMD_PORT = 3389;” Is this the right place?? If I did something wrong, I guess this is the part.

    please help me if you have any idea. thanks in advance

  18. Thanks so much for sharing this. Being quite new to Linux I struggled to get this to work as none of my computers would wake up using your server but they did without a hitch when using the integrated WOL function in an old DD-WRT router I have. I finally realized that I needed to install wakeonlan on my RaspberryPi. As soon as I did that it worked! Sharing to spare other newbies like me the grief.

    sudo apt-get install wakeonlan

    1. EDIT: I am quite sure I executed:

      sudo apt-get install wakeonlan apache2 php5

      as you had instructed but for some reason it apparently failed to install wakeonlan until I tried to install it again on its own.

  19. Installed and can see the website externally. it pings correctly to tell me computer is awake but then I get

    Going to Sleep!
    Approved. Sending Sleep Command…
    Command Failed: couldn’t connect to host

  20. This is an excellent guide. Thanks a lot.
    It was my first attempt with a Raspberry pi and Linux ever and it took me a very long evening to get up running. Probably because I am a beginner. The wake is working fine (which is the most important for me), the sleep not yet working (connect() time out).
    Previously I used Wake on Ring because WOL via internet could not be trusted. Now I can stop my telephone land line subscription which I really do not use except to wake up my PC. Saving $25/mth. The Raspberry pi has soon saved me its cost.
    Thanks again!

  21. Thanks for doing this. Successfully ditched ddwrt netgear router for new Time Capsule.

    Any chance you could turn this into an ios/android app? Right now I saved bookmark, but having the app could save password and make it easier from iphone.

    Also for people who dont have ddwrt and want dyndns to automatically update (Apple Time Capsule/Extreme) go here and follow these instructions. Works perfect for me now.
    http://www.techjawab.com/2013/06/setup-dynamic-dns-dyndns-for-free-on.html

  22. Great Tutorial! But i couldn’t get the SHA-256 password to work! I generate the code and paste it in the script but when i type it on the web interface, I get the error message: “Invalid Passphrase. Request Denied”.

    Is there anybody else experience this issue?

    Thanks in advance

  23. I cant seem to get the website to work or start on the pi (does it start on its own?) ive got a virgin media super hub 2ac (notorious for not portforwarding) ive managed to get it to portforward a minecraft server but port checkers say that port 80 is blocked as you would expect but so is port 500 so I don’t know what next!

    1. tell a lie it works but the password thing wont work can I restart the webserver or do changes take effect immediately when I change the config file

  24. Hey, Jeremy,

    first off, THANKS for this!

    Secondly, I’d like to get some support from you regarding ping. Firewall on my remote win 8.1 pc is set up (incoming and even outgoing rules allowing private and public network pinging are active).

    The website used to display messages after each ping until the computer responded UNTIL I decided to change the config file to ping every 20 seconds, and not every 5. After that, the website freezes on “Ping 1…”. I don’t even know if the raspberry server sends more than this one ping.

    I got back to the config file, changed the ping interval to 5 seconds but this did not help. I copied and renamed the original one (by you) from the git repository and set up everything without touching the ping interval but the website still freezes on the first ping.

    This really isn’t a big issue, since the server successfully wakes my computer but I thought you might be able to help.

    Regards,

    Rado

  25. This is great – now I dont have to use ssh.
    My raspberry pi is also used in the same way to wake up the plex and file server.
    Thanks for your time to do this.

  26. Hi,

    Thanks for the tutorial, managed to get the web app to turn on my pc however the sleep on lan utility is not working correctly. the commands work over the local network however the webapp always shows the pc is asleep regardless of if it is or not. i have the correct port for the utility in the config file on the pi.

    Thanks for any help you can provide..

    Regards,
    Bilal

    PS Did i mention the pi wol server is super awesome

    1. So i managed to solve it… for some reason i had multiple firewalls on my computer they where interfering…

      so i have set this up on my dads computer aswell..

      again thanks a lot for the work you did here Jeremey gonna spread the word.

  27. Thanks so much, Jeremy, for your guide and files. This is EXACTLY what i was looking for. Following the steps, I managed to set it up in just 30 mins. Very useful and clever. Thanks again.

    Sergio

  28. During pass phrase login include a max number of attempts or pause function to limit the number of pass phrase attempts per second. Include ip address in log file and blacklist rogue attempts in ‘ufw’.

  29. Hey Jeremy,

    Thans so much for this very usefull tool and excellent guide. Much appreciated!

    Some feedback, on my win 8.1 pro HTPC/NAS I did not have to set up pings to get it to work. With the 5 second intervall the 4th ping is succesfull (booting from an ssd)

    All the best and happy hollidays,

    Kevin

  30. Hey, not sure if you’ll get this but I’ve been trying to get this to work all day. I’m in someone of a predicament and don’t really know how to solve it as I know little about networking. My current setup is I have to routers. One acting as a repeater of the other. My main router is one provided by cox which is a belkin n150 i believe. The second one,which is the repeater, is a linksys wrt-54g with ddwrt firmware. The computer that I am trying to wake is connected to my main router and the raspberry pi is connected to my repeater. Both devices are connected through ethernet. I can connect to the web server through the local ip of my raspberry pi but not through the dynamic url (dynamic url shows up as webpage is unavailable). The status report of my computer is incorrect. Whether it is on or off the site always says off. When I send the magic packet through the site it won’t turn on. Any help would be greatly appreciated. I apology for the amount of writing but I was just trying to be as detailed as possible. If you need anymore info please ask.

  31. You probably have NAT turned on for both routers. Only the main router that is connected directly to the internet should have NAT turned on. The second router should be in bridge mode. The setting location varies from router model to router model.

    1. I actually ended up getting it to work by doing a fresh install of raspbian, and then changing the IP of the raspberry. The only problem is this only lasted for on go. I turned my computer on and then off and after that the dynamic address would give me the page not reachable(connection refused).

      1. Does your raspberry pi have a static local IP address and is your main router set to forward requests to the web page? I’ve worked it out so I can access my Raspberry Pi’s through a VPN connection, but then you need to forward port(s) for the VPN.

        1. My raspberry pi does have a static local IP. I’m not sure how to set my main router to forward the request to the page since my main router only supports dyndns and I’m using noip since its free. I was trying to get it to work by running noip duc off of the pi an it works for a short period.

          1. Setting up noip and dyndns just gets the request as far as your wan IP. Once it hits the router, you need to have port forwarding have the request go to the raspberry pi. Your port forwarding should be something like wan port 80 lan port 80 and the LAN IP address of your raspberry pi. It will not work at all unless you have this set. Not sure why it would work for a short period of time. Are you sure you didn’t type the LAN IP instead? You could also change the WAN port to something else like 8082 to hide the page a bit, but then you need to type the address like http://www.myhomeip.net:8082.

            Check your routers port forwarding settings. Neither dyndns or noip handle this part. One thing additional about the noip duc. I run it on Ubuntu. When I set up up initially it started up OK, but did not stay running after a reboot. I had to change a setting somewhere so it would launch on boot. Make sure it’s still running using Top from the terminal. IP numbers shouldn’t change all that frequently. Mine decided to change for the first time the one time I took a trip to the opposite end of the country.

          2. I have it set up so the external port is 5000 is fowarded to internal port is 80 for the ip adress of my raspberry pi. I got rid of the port fowards i had on my second router and that fixed part of the problem. I can access the page through the custom address from noip and shut my pc down and then the server starts to slow down when i shutdown my main pc. Then when i turn my main pc back on using the custom address the server is no longer accessible unless i go to my routers page and click apply settings on the port foward page. I don’t actually change anything it just refreshes or something and then the page is accesible again.

          3. The second router should not have port forwarding options and you shouldn’t use them if they are there for some reason. I think you need to make sure that you are not doing network address translation on the second router. The main router should be the DHCP server for the whole network. I have a second wireless router as well that is connected through a wired connection so I can get good signal throughout the house. The second router is in what is called bridge mode. All my addresses are 10.0.0.x and either handed out by the DHCP server or manually assigned outside the range that my DHCP server assigns (above 200).

          4. Yeah my second router is also in bridge mode but it is connected to my main router over the wireless. It did have a port foward option but I got rid of the ones that were setup. I have dchp disable on the second one and I don’t believe there is any Network Address Translation going on from the second router. All my local ips designated by dhcp and are all 192.168.1.x. In regards to noip I have it set up so it runs on the startup.

          5. Not sure why it’s not working for you. All I can suggest is that you troubleshoot something like this:
            1. Try noip address.
            2. Try LAN IP address if noip address not working.
            3. If LAN IP does work, try your wan IP address as found from http://wanip.info
            4. Compare results from the address you obtained from wanip.info to what noip indicates your IP is.

            Some routers will not remember that a computer is there if it has gone to sleep for too long. I know that my Mac has a setting to wake periodically to make sure that router knows it’s still there. You might check of that setting. It would certainly explain why WOL would work sometimes but not always.

  32. Are you sure the computer you are trying to wake up is capable of being woken up this way? Not all are.

  33. Excellent work.

    I have your Remote WOL Server on my Amahi (Fedora 19 based) server. I can wake computers in the network but cannot get the Remote WOL Server to work outside the network. I cannot even access the main page from outside the network and can see it through my VPN but cannot wake any computer. I think the VPN’s issue is something with the reverse proxy settings. What would suggest an .htaccess should look like to redirect to the outside port 1234? How about a conf.d file for Apache?

    1. Sorry, I mean to say that I cannot access the main page directly but I can access the main page through a replacement proxy web forward in my VPN. In the VPN Remote WOL Server can detect if client computers are awake or asleep, but cannot cause sleeping computers to wake.

  34. Hello, your utility works amazing, how would it be possible to add a timed wake and sleep on the pi to auto wake the pc at 9:00am then sleep at 9:30pm?

  35. This tool is great, works like a charm as intructed and im gona use this a lot!! Lots and lots of thanks!!!!

Leave a Reply to Mathias Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Advertisement