Search:  
Gentoo Wiki

Wakeonlan

Merge-arrows.gifIt has been suggested that this article be Merged into one article with Wake on LAN.    (Discuss)

Contents

Introduction

For years I've been seeing that the ethernet cards I buy say that they support "Wake on LAN". I can guess from the name what it does. But it sounds like the complicatedness of it will out-weigh the neatness of it. Recently I buckled down and figured it out and it is not hard at all but ranks incredibly high on the neat scale. The next logical step was to finally contribute something to the wiki of which I've taken so much.

What is it (I'm still confused)

Wake on LAN is a feature of certain (quite a lot, actually) ethernet adapters that allow it to "Wake Up" the computer from a completely halted state by receiving the "Magic Packet". Much documentation I found on it claims that your computer must be in the ACPI/APM "sleep" state for WOL to work. However, I have completely halted my PC (shutdown -h now) and pulled the plug and this still works. I have not gone so far as to remove the CMOS battery but if you reset your BIOS the WOL default is almost always to be disabled.

Who wants this

This is most useful those of us in Administrationesque positions, but still pretty darn cool for anyone. In short, You do.

How to do it

Your motherboard will need to support "Wake on LAN". If it does not then just stop now and go cry somewhere. Or you can go on and see what your missing. "But how do I know if my BIOS supports it?" Read on.

BIOS Settings

In your BIOS look under the "Power Management" (or similar) section. There will usually be a sub-section called, you guessed it, "Wake On LAN". If you don't see it right away then keep poking around. Most all computer over the last few years support it. WOL will be disabled by default for obvious security reasons. Just select "Enable" and then "Save and Exit".

Ethernet Settings

If you have an Onboard Ethernet adapter then you are all set. If you have an ethernet adapeter in a PCI slot then its a bit more complicated. The card must be able to support WOL. This will definitely be listed with the card specifications on the box or (if you have long since thrown out the box) on the manufacturer's website. If it does support WOL then you are not quite out of the woods yet. Some mobo/card combinations will require a special 3-pin cable to connect from the motherboard to the ethernet card. My ethernet is onboard so I have not had to play with this. But apparently if the PCI bus is of the 2.2 standard and the card is also compliant with this, then no connection cable is required.

User-Space Programs

To do this you will need "ethtool" and "wakeonlan":

emerge ethtool    # on the local (to be woken) machine
emerge wakeonlan  # on the remote (to do the waking) machine

There are alternatives to wakeonlan such as wol and etherwake but wakeonlan is pretty simple and it can be used by non-root users (lusers).

However, Java enthusiasts should check out net-misc/java-wakeonlan. It comes with a nice gui, is platform independent and provides a library which can be used in custom projects.

Actually Doing It

Setting up the Sleeping Machine

(Install ethtool as per above) You will need to be root to run ethtool

ethtool eth0

will produce output similar to this:

Settings for eth0:
       Supported ports: [ MII ]
       Supported link modes:   10baseT/Half 10baseT/Full 
                               100baseT/Half 100baseT/Full 
                               1000baseT/Half 1000baseT/Full 
       Supports auto-negotiation: Yes
       Advertised link modes:  10baseT/Half 10baseT/Full 
                               100baseT/Half 100baseT/Full 
                               1000baseT/Half 1000baseT/Full 
       Advertised auto-negotiation: Yes
       Speed: 100Mb/s
       Duplex: Full
       Port: Twisted Pair
       PHYAD: 1
       Transceiver: internal
       Auto-negotiation: on
       Supports Wake-on: g
       Wake-on: d
       Current message level: 0x000000ff (255)
       Link detected: yes

We are really only interested in "Supports Wake-on", "Wake-on" and "Link detected". As long as yours read "g", "d" and "yes", respectively, then we're good. If the first is anything besides "g" then you are out of luck, maybe. I haven't had any luck with non-g values. But that doesn't necessarily mean that it can't be done. I'm pretty sure non-g means that your motherboard/ethernet-card does not support WOL in some way.

Now, we need that "d" to be a "g" too:

ethtool -s eth0 wol g

"ethtool eth0" should now look like this:

Settings for eth0:
       Supported ports: [ MII ]
       Supported link modes:   10baseT/Half 10baseT/Full 
                               100baseT/Half 100baseT/Full 
                               1000baseT/Half 1000baseT/Full 
       Supports auto-negotiation: Yes
       Advertised link modes:  10baseT/Half 10baseT/Full 
                               100baseT/Half 100baseT/Full 
                               1000baseT/Half 1000baseT/Full 
       Advertised auto-negotiation: Yes
       Speed: 100Mb/s
       Duplex: Full
       Port: Twisted Pair
       PHYAD: 1
       Transceiver: internal
       Auto-negotiation: on
       Supports Wake-on: g
       Wake-on: g
       Current message level: 0x000000ff (255)
       Link detected: yes

El Sweeto.

Note: you will notice that everytime you reboot your computer this value will be reset. But that doesn't seem to matter, so the previous step might not even be required, however, in some setups it may. Add the command for setting the value to /etc/init.d/bootmisc .

Now, you need your MAC address which can be found one-of-two ways. From your local machine:

root@jupiter:~$ ifconfig eth0 |grep HWaddr
eth0      Link encap:Ethernet  HWaddr 00:14:22:5D:14:0E

(It is your HWaddr. In my case its 00:14:22:5D:14:0E) or from a remote machine (root required):

ping -c 1 192.168.100.218
arp 192.168.100.218

(You have to ping first. Just try and arp before [exception: if you ssh'd into the remote machine and then arped back to your local machine]) You should see something like this:

[root@edelweiss ~]# arp 192.168.100.218
Address                  HWtype  HWaddress           Flags Mask            Iface
192.168.100.218          ether   00:14:22:5D:14:0E   C                     eth0

Under "HWaddress" is what you want.

Write your MAC addy down somewhere. You cannot call a sleeping computer by its IP address.

Waking it up

Now shutdown your computer and move to your other Gentoo box (I know you've got one). Install wakeonlan on this machine as per the "User-Space Programs" section above. Now just

[josh@frontenac ~]$ wakeonlan 00:14:22:5D:14:0E
Sending magic packet to 255.255.255.255:9 with 00:14:22:5D:14:0E

Depending on your network topography you may want to give a broadcast:

[josh@frontenac ~]$ wakeonlan -i 192.168.100.255 00:14:22:5D:14:0E
Sending magic packet to 192.168.100.255:9 with 00:14:22:5D:14:0E

And that's it! If everything worked then your sleeping computer in the next room is in for a rude awakening!

Conclusion

Story Time

But what purpose could this possibly serve? I have two instances in which I use this where it is quite handy.

I'd like my computer to be ready for me in the morning with the weather or the news. Or I'd like it to start playing an mp3 or ogg to wake me up. But I don't want my computer on all night because it is kind of noisy. No problem! I setup my router/ftp/file-sharing box in the other room to wake up my computer at a certain time and I have my computer setup to play that file when it boots!

It is not uncommon that I get a call from work saying that there is a problem with the application/db server. So I tunnel into my computer at work, fire up a desktop, and now I've got all my tools right handy. But what if the power went out at some point? That happens here somewhat frequently, especially in the summer. This could definitely cause problems somewhere along the line. The servers will be ok, they are on batter backup. But my workstation could be off! Granted; I could log into the server and fix just about anything, but it sure is nice having all of my desktop tools. No problem! I log into the server, wake up my desktop, and go on my merry way!

Security Issues

At first I thought this seemed like a real security problem. But you must be on the LAN to do it (hence the L in WOL). Even then you probably don't want just anyone on your network to be able to turn on your computer. Well, most of the time they can walk into the next room and hit the On button anyway. But if your computer is behind a locked door and this is a serious concern for you, then check out "man ethtool" and look at "sopass". You can set a password in 6 byte MAC address hex format and then somehow pass that along with the wakeup call. I'm not that paranoid so I haven't tried it yet. But if I do or if anyone has then append it to this page.

Retrieved from "http://www.gentoo-wiki.info/Wakeonlan"

Last modified: Sat, 11 Oct 2008 05:33:00 +0000 Hits: 1,756