Wake on Lan with Linux and Windows

Motivation
I have 3 computers. My laptop a Thinkpad X30, another Thinkpad which acts as server and a desktop computer. I have all my main data on my server and use the files on my laptop and desktop by sshfs and NFS.

The only files I don’t store on my server is media files, such as movies and music – these are stored on my desktop. This was the problem – if I was out I couldn’t access my files since my desktop was turned off when I am not home. I need something to turn on my desktop when I wasn’t home.


wol

Wake on Lan
Wake on Lan (WOL) is a technology to turn on a computer by sending it a specific network package. When a WOL-enabled computer is turned off the network port will stay active and listen for a certain packages and in if it receives such a package it will boot the computer.

Two things are needed:

  • Enable WOL on my Desktop.
  • Installing a program to send the magical network package on my server.

BIOS
Somewhere in the BIOS there will hopefully be some setting to enable WOL. I didn’t find it in the BIOS of my ASUS PW5 DH motherboard, but it works fine. A good indicator is to check whether the lights around the network cable is turned on or not on the back of the computer when the computer has been shutdown.

Enabling WOL in Windows
It always takes more screenshots to explain anything in Windows, but there is not really any way around it. In Windows I need to go to the network setting and choose my network adapter. After selecting “configure” as in the screenshot:


wol

I selected the fan called “advanced” where I found to settings I need to turn on:
Wake from shutdown:

wol

Wake up capabilities:

wol

That’s it. :)

Enabling WOL in Linux
To enable WOL from Linux the option has to be set before shutting Linux down. First I see what is supported by network driver:

root@bohr:/home/tjansson# ethtool eth1
Settings for eth1:
        ...
        Supports Wake-on: pg
        Wake-on: d
        ...

So it supports pg which means (from man ethtool):

<code>
p  Wake on phy activity
g  Wake on MagicPacket(tm)

The g option is the interesting part. So I set the option on the my network driver:

root@bohr:~# ethtool -s eth1 wol g

but I don’t want to do this every time I shut down the computer, so I will make a script in /etc/init.d/ named wol.sh containg the lines:

#!/bin/bash
ethtool -s eth1 wol g

and make it executable:

root@bohr:/etc/init.d# chmod +x wol.sh

and finally tell Linux to execute the script on every runlevel, which I quite a overkill, but it doesn’t really mater – it works:

root@bohr:/etc/init.d# update-rc.d -f wol.sh defaults

Now WOL is enabled under Linux as well.

Sending the magical package from Linux
The last thing I need to do is to wake the computer after it has been shut down. I do this from my Linux server on the same local network. The only information needed is the hardware adress of network interface on the desktop machine. I can find this by running ifconfig under Linux or some networkgui on Windows on the desktop machine:

tjansson@bohr:~$ /sbin/ifconfig
...
eth1      Link encap:Ethernet  HWaddr 00:18:F3:CD:78:A0
...

Now I can start the desktop computer by running wakeonlan from my server:

root@nobel:/home/tjansson# wakeonlan 00:18:F3:CD:78:A0
Sending magic packet to 255.255.255.255:9 with 00:18:F3:CD:78:A0

Waking the computer from other OS’s
In the bottom of the wikipediaentry on WOL there is a long list of other programs to send the magical network package but I haven’t tried any of these my self.

This entry was posted in Articles, Computer. Bookmark the permalink.

32 Responses to Wake on Lan with Linux and Windows

  1. Pingback: Sunglasses For Your Dog and Stuff » Blog Archive » Configuring Wake-On-LAN (WoL) in Debian

  2. Luca says:

    Thanks!
    ethtool -s eth1 wol g
    That is what i was missing!

  3. Kerry Wong says:

    Thanks so much. It worked great on my machine with Asus P5E motherboard.

  4. Pingback: Kerry D. Wong » Blog Archive » A Fun Week

  5. Bruce C. Jones says:

    Great information:

    I have some additional info for the Linux system. If you create the /etc/ethers file with each line in the format of Mac and host name (ie: 00:18:F3:CD:78:A0 DeskTop), you should be able to type the name when using wol. This only works if the hostname on each line in /etc/ethers is resolvable to an ip address (perhapse found in /etc/hosts). Now if the files are working and using the wol-07.1 for Linux, I can type

    $ wol DeskTop
    Waking up DeskTop…
    $

    Using the etc/ethers file allows the use of names rather than the mac address for the wol command.

  6. I’m looking for what you might call wake on wan. How would you do that in a similar setup but with a wireless connection?

  7. Hmm – It all depends on whether or not your hardware supports WOL. I haven’t heard about it my self before, but apparently netgear makes some adapters which supports WOL. Sorry – but I can’t provied much more help than that.

  8. Lindylex says:

    Britney Spears, if you have the time change the firmware of you your router to DD-WRT or OpenWRT then create VPN. Log into the VPN and then you can run that command.

    You might even be able to log into the router threw ssh and run that command with the VPN setup. I would try this first.

  9. Chevinge says:

    Why not run wol.sh at startup, only needs to be run once…

  10. Noobie says:

    I have a problem with the

    root@bohr:/etc/init.d# chmod +x wol.sh

    part

    When i type in that command, i get “No ushc file or directory… Im totally new to linux and only type what im told, so if that “ect” stands for something that i have to put in myself, then please help me to find out what i should put it.

    Also i wrote the “#!/bin/bash” command… Im not sure if i should do that either. If anyone would help it would be great :)

  11. Noobie: /etc is a folder on the filesystem that traditionally contains all configuration files for the programs installed. If you are in doubt about other folders try googling “Linux Filesystem Hierarchy” which should give plenty reading on the subject. The following seems as a decent introduction:
    http://www.tuxradar.com/content/take-linux-filesystem-tour

    So now that /etc is established, /etc/init.d/ contain all the control scripts for most of the daemons you on the machine. Putting wol.sh here seems reasonable. The comand “chmod” changes permissions for files and folders. “chmod +x” adds executable permissions to the argument and in my case I used this to make the script wol.sh executable.

    Are you sure you shell said “ushc”? I think you might have made a type in the filename or on the command you wrote in console?

    I am sorry but I don’t have the time to teach how to move around int the shell but luckily there is plenty of good documentation:
    https://help.ubuntu.com/
    Try especially the following document called “Using the Command Line” which will certainly get you started.
    https://help.ubuntu.com/10.04/basic-commands/C/
    Happy reading and welcome to the world Linux – you will not regret it.

  12. Noobie says:

    Sorry that i didnt spell correctly.

    It said “No such file or directory found” (such became usch)

    I think i know what the problem is. You wrote that you “make a script in /etc/init.d/ called wol.sh.

    I don’t know how to make that script… im not sitting with a GUI linux, like ubuntu. Im sitting with a OS called OpenFiler, and it ONLY has a commando prompt, or terminal.

    Is there anyway to make that script, then add the lines of the script, from the terminal?

  13. Noobie says:

    Update to my privious post.

    I have now managed to craete a script file, also to write in it, save it, give it permission, so completely forget about my privious post, and read this post instead :).

    but when i write “update-rc.d -f wol.sh defaults”

    It says “-bash: update-rc.d: command not found”

    I’m not certain, but I think it might be because I use OpenFiler. Anyone who could give any help on other “start on start-up” commands?

  14. This is because was written to fit debian based Linux. I think that openfiler is Redhat based, so in this case you should use:

    /sbin/chkconfig wol.sh on

    The difference is the programs “update-rc.d” and “chkconfig” used to set which programs should be run at startup.

  15. Noobie says:

    Thx for your help, but my problems doesnt seem to end here…

    I manged to find out, that i had to use the chkconfig

    When i type in chkconfig i get a list of usage

    list, add, del, override, level.

    But when i try to type what u suggested: “/sbin/chkconfig wol.sh on” it gave the following respond :(

    “service wol.sh does not support chkconfig”

    Now I’m seriously down in the mud… I can’t seem to find any solution to this

  16. This is not your fault – I need to rewrite the script to make it compatible with chkconfig. I can’t do this at the moment as I have to test it on a redhat based machine, but if you would like to experiment yourself take a look at a pages as:
    http://www.instiki.org/show/RedhatInitScript

    There is however a quick hack. Instead of using wol.sh just add the following line to the file /etc/rc.d/rc.local – now the line will be done on every restart:

    ethtool -s eth1 wol g

    This is very appropriate in our case since we don’t need a fullblown script but just on command that needs to be run at each restart. The same can by the way be done on Debian based system in the file
    /etc/rc.local

  17. Noobie says:

    Thanks a lot. I haven’t had a chance myself to test this, but I’m going to for sure! :)

    I want to thank you for all your help, and I will be coming back if this doesn’t work either, but for now Thank You Thomas Jansson :D

  18. besho says:

    Great, thanks so much, but I don’t realize that this is for waking up from shut down, look at this site :

    http://onlineforall.info/2010/08/how-to-wake-your-pc-on-lan/

    I thought it’s only form standby !!!

  19. Besho – I don’t really understand what you are writing. But Wake On Lan is a method to wake make a computer boot that is completely shutoff beside that the network card – which listens for a magic packet (WOL).

  20. besho says:

    But I’ve followed all steps ( on your site and on different sites), but it only wakes my PC if it was on standby, If I shut it down, then the magic packet doesn’t switch it on !!!

  21. Brian Nixon says:

    I got Mandriva 2007 to enable WoL by adding

    ETHTOOL_OPTS='wol g'

    to /etc/sysconfig/network-scripts/ifcfg-eth1.

  22. Pingback: Wake up your PC from WD MyBook WE at Peter's Blog

  23. Pingback: acpid, Is it possible to use ethernet to wakeup from hibernation[Fedora11]

  24. DaftDuck says:

    Worked a treat on my Linux box, now I don’t have to go downstairs to turn it on!

  25. Thanks says:

    Hello,
    Thanks, this worked great on my ubuntu and LMDE boxes. The tip about adding the ethers file helped as well.

    Thanks!

  26. TotallyConfused says:

    OK, I have this working and can wake up my DIY Ubuntu Server from any PC on the LAN by sending the magic packet. That part’s the great. It’s nice to impress friends with “You watching? I’m gonna start that PC over there from here”.

    However, in this “it’s good to be green age”, the idea is if no one is accessing the server it should suspend itself after a reasonable time. Just like my QNAP NAS does.

    My server runs headless. If I set the suspend time to say 30minutes, the server suspends itself, blissfully disconnecting any user on LAN. The user then has to wakeonlan blah blah…

    It seems all rather self defeating, unless there is a work around.?

  27. I don’t think there is a work around to what you are describing. If it suspends you will need to wake it up. On my own server, see Building a powerful, cheap and silent Linux NAS and HTPC server I have it running all the time, but the raided disks spin down after 30 minutes of no activity.

  28. Pingback: HowTo: HomeServer « Wi King

  29. Pingback: BT Günlü?ü - A? üzerinden bilgisayar açma

  30. urland says:

    from this page: http://wiki.debian.org/WakeOnLan

    you can (on Debian since squeeze) add a line to your /etc/network/interfaces:

    iface eth0 inet dhcp
    ethernet-wol g

  31. Luke says:

    I made something a little bit different – wake up my server with ubuntu system by any of my PC with windows. When i stop working my server automatically shuts down. if you like such idea pls visit: http://lukasz-lademann.blogspot.fr/2013/01/how-set-up-wol-wake-on-lan-on-thin.html

Leave a Reply