Wake on LAN

Introduction
Wake on LAN (WOL, sometimes WoL) is an Ethernet computer networking standard that allows a computer to be turned on or woken up remotely by a network message. This is a brief guide to enable WOL under Gentoo Linux.

Requirements
Starting with PCI version 2.2, there’s been a new development in the PCI standard in the form of PME (Power Management Events). What this means is that PCI cards can send and receive PME via the PCI socket directly, without the need for a WOL cable.  Before continuing, be sure to enable "Power On on PCI Devices" or similar in the Bios setup of the computer you want to wake up with WOL packet.

Wake-up frame
A Wake-up frame is a special data packet containing the Ethernet address of the remote network card. Somewhere in this frame should exist a byte stream (magic sequence) composed by, at the least, 16 times the repetition of the Ethernet address and preceded by a synchronization stream of 6 bytes of FFh.

Magic sequence
If the Ethernet address of a target computer is 01:02:03:04:05:06 (6 bytes), then the LAN controller of that machine should be looking for the following sequence

FFFFFFFFFFFF010203040506010203040506010203040506010203040506 010203040506010203040506010203040506010203040506010203040506   010203040506010203040506010203040506010203040506010203040506    010203040506010203040506

inside the frame. Note that this is an ethernet layer frame; IP is not necessary for WOL to work. We use it here because it's ubiquitous, but as long as the frame contains the magic sequence, the magic happens.

WOL on Gentoo Linux
We assume to have two Gentoo boxes, the first will act as client and send the WOL packet, while the second will be the computer we want to wake up with WOL packet. Remember to enable Power On PCI device (or similar) in your BIOS setup, otherwise WOL packet will not work.

ethtool utility
is a simple and yet powerful utility for examining and tuning ethernet-based network interfaces. You have to install this tool on the computer you want to wake up, since you have to enable WOL on your ethernet driver:

You may see if your ethernet interface (in this example ) is WOL capable:

You will have a report similar to this:

Settings for eth1: Supported ports: [ MII ] Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full Supports auto-negotiation: Yes Advertised link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full Advertised auto-negotiation: Yes Speed: 100Mb/s Duplex: Full Port: MII PHYAD: 1 Transceiver: external Auto-negotiation: on	Supports Wake-on: g	Wake-on: d	Link detected: yes

In this case, the ethernet interface is WOL capable ("Supports Wake-on: g"), but this feature is disable ("Wake-on: d"); you may enable WOL with the following command:

and then verify the new settings:

Now, you will have a report similar to this:

Settings for eth1: Supported ports: [ MII ] Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full Supports auto-negotiation: Yes Advertised link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full Advertised auto-negotiation: Yes Speed: 100Mb/s Duplex: Full Port: MII PHYAD: 1 Transceiver: external Auto-negotiation: on	Supports Wake-on: g	Wake-on: g	Link detected: yes

Don't switch off the PC, you may need some more information before (see the following instruction).

wakeonlan client
On the computer you will use to send the WOL packet, you need to have a client to generate this kind of data. You may use Perl script as client, which is in Portage tree:

Prepare and wake up your PC
You need to know the MAC address of the PC you want to wake up; you may get this information from the client PC using ping towards the PC you want to wake up (in this example 192.168.20.52) and then you can see the arp table:

You will have an output similar to this, from which you'll get the MAC address:

Address                HWtype  HWaddress           Flags Mask            Iface jupiter.home.net        ether   00:0C:6E:96:58:DE   C                     eth0

Now, you may switch off the computer on which you want to try WOL. From the client PC, you have to send the WOL packet:

In this example, we send the WOL packet in broadcast to the subnet 192.168.20.x, using the MAC address we got before. Now, if everything is ok, you see your computer wake up magically!

WOL always enabled on shutdown
You may experience that, on next reboot of system, your PC won't wake up, even if you send WOL packet correctly from another box; this is due to the fact that the ethernet driver will lose it's previous configuration during boot.

A quick and clean way to get rid of this, and let the wake on LAN be enabled on every shut-down, is to add this line to

/etc/conf.d/local.stop

This is the same command used to enable WOL previously used from shell; when your Gentoo box turns off, the commands presents in this configuration file are executed, so you'll have WOL enabled at every shut-down.

N.B.: You may want to put this in instead to make sure it's activated even if your computer shuts down ungracefully.

N.B.: If you are using OpenRC you should create instead. Make sure this file is executable.

Other tools
There are other tools besides, this is a short list:


 * ether-wake
 * Net::Wake
 * WOL in Java
 * AMD - Magic Packet Download (Windows)
 * AMD - Magic Packet Download (Windows)

Hardware
The WOL on Gentoo is known to work with the following hardware:


 * 3Com 3C920B-EMB Controller [Tornado] - 3c59x driver
 * Broadcom Corporation BCM4401 100Base-T (integrated on Dell Inspiron laptops)
 * SiS900 PCI Fast Ethernet (integrated on Intel® Desktop Board D201GLY2) - sis900 driver


 * Foxconn G31MXP-K, Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller (rev 03)

Power management FAQ
That is: is it better to shut the system down or leave it running? This is a good question.

"It's best to leave it running. When it starts up, everything heats up and expands, and when it shuts down, everything cools down and contracts. Repeat twice a day and you can see how it could shorten the lifespan. Bit like a lightbulb; a lightbulb left on all the time will last a lot longer than a lightbulb that's always being turned on and off."

Source: [http://ask.metafilter.com/5700/Do-You-Keep-Your-Computer-Running-All-the-Time-or-Turn-It-Off Do You Keep Your Computer Running All the Time or Turn It Off? | Ask Metafilter]

"When do lightbulbs burn out -- while they're lit, or when you turn them on? Exactly. Same thing with computer monitors: the only time I've had them fail is during power-on. I've normally left them on 24/7 for years at a time; they've only ever burned out (with flames, once!) when I was foolish enough to power-cycle them. Losing one monitor is more environment-harming than leaving it on for years at a time. Hard drives are particularly susceptible to the hot/cold expansion cycle. Back in the old days of bulky drives with servo stepper motors, I had one that I had to mechanically assist when it was powered-on. Once it was up and running, it could be left indefinately. It ultimately failed during, you guessed it, a power-on cycle. I recommend setting your BIOS or OS to use power-saving features, and not powering-down your computer. In standby mode your system will use far, far less energy than that required to manufacture a replacement."

Source: [http://ask.metafilter.com/5700/Do-You-Keep-Your-Computer-Running-All-the-Time-or-Turn-It-Off Do You Keep Your Computer Running All the Time or Turn It Off? | Ask Metafilter]

"It's best to leave it running. When it starts up, everything heats up and expands, and when it shuts down, everything cools down and contracts. Repeat twice a day and you can see how it could shorten the lifespan. You are considering the right information, but you are drawing the wrong conclusion. The main enemies for all computers are heat, static, dust, and moisture. Turning the comptuer off reduces the risk from all of these to almost zero. Energy issues aside, the best reason to shut off your computer (or to put it to sleep) is because leaving the computer on exposes the computer to constant heat. Continuous heat stresses the computer far more than shutting down and restarting. The expanding and contracting is microscopically minor and happens over a period of hours. It is to be ignored, unless you are out-of-doors. For typical PC, in a typical environment, this point is inarguable: shut the computer off or put it to sleep, no matter what."

Source: [http://ask.metafilter.com/5700/Do-You-Keep-Your-Computer-Running-All-the-Time-or-Turn-It-Off Do You Keep Your Computer Running All the Time or Turn It Off? | Ask Metafilter]

Hibernation and Power States
If you find that WOL works after shutting down normally, but not when hibernating (or suspending to disk) this is because WOL only works from certain power states, depending on the BIOS and other factors.

For Suspend2, or Tuxonice, edit /etc/hibernate/suspend2.conf and change the PowerdownMethod: PowerdownMethod 4
 * 1) Powerdown method - 3 for suspend-to-RAM, 4 for ACPI S4 sleep, 5 for poweroff

You can also experiment with the BIOS allowing hardware to wake the device in certain states.