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.

Only registered users can comment.

  1. 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.

  2. 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.

  3. 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.

  4. 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 🙂

  5. 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.

  6. 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?

  7. 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?

  8. 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.

  9. 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

  10. 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

  11. 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 😀

  12. 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).

  13. 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 !!!

  14. I got Mandriva 2007 to enable WoL by adding

    ETHTOOL_OPTS='wol g'

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

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

    Thanks!

  16. 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.?

  17. la direccion mac xx: xx:… esta mala (con espacios),
    debe ser
    xx:xx….. (sin escios anda bien)

Leave a Reply