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.

  • Share/Bookmark
Related articles

9 Responses to “Wake on Lan with Linux and Windows”

  1. Luca says:

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

  2. Kerry Wong says:

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

  3. [...] finally got WOL (wake on LAN) to work on my P5E quad-core PC, thanks to this post here! As it turned out, I had to set the WOL capability every single time after reboot (that’s why [...]

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

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

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

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

  8. Chevinge says:

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

Leave a Reply