Saturday, 27 May 2006

How to get Wake-on-LAN (WOL) to work in Fedora Core

(Update 3.ix.2011: This content is from 2006.  I don't have the
hardware any more so I cannot reproduce what is described here.  I am
keeping this around for posterity in case it might be of use to

Recently I've been wrestling with WOL for one of my linux servers.  I
found a WOL client called `etherwake`, which installs just fine in
OpenDebianSlug using the command `apt-get install etherwake`.

However, I found that I was having problems on the other end.  I
noticed that if I switch off the computer using the front power switch
at the GRUB boot menu, I could wake the machine using etherwake,
whereas if I use `shutdown -h now` from within linux, nothing happens.
The tell-tale sign is that the port light on my 3Com router/switch is
lit in the first instance, and dark in the second.

A bit of googling around suggested that this is a common problem.  The
explanation was something along the lines of "linux shuts down your
network card on OS shutdown".  (For the pedantic, this should be
rephrased as "most linux distributions shutdown the network card on
shutdown").  The Gentoo Wiki's page on WOL suggested [removing the
`-i` option from `halt`][gentoo].

Starting from this, I managed to get my machine to shutdown and be

## Server config

My machine is running Fedora Core 4, though these change would likely
work for other versions of Fedora and Redhat/CentOS.  I changed the
script `/etc/init.d/halt` so that the last few lines were changed from

     HALTARGS="-i -d"
     [ -f /poweroff -o ! -f /halt ] && HALTARGS="$HALTARGS -p"

     exec $command $HALTARGS


    [ -f /poweroff -o ! -f /halt ] && HALTARGS="$HALTARGS -p"

    /usr/sbin/ethtool -s eth0 wol g
    sleep 5 # this pause seems to be important!

    exec $command $HALTARGS

Note the removal of `-i` from `HALTARGS` and the extra `ethtool`
invocation before the last `exec` command.

## Client config

This is the easy part.  I created a file called `/etc/ethers` to map
names to my MAC addresses:

    00:20:ED:5A:00:2B fried
    00:11:09:24:1C:8B white

Now to wake up `fried`, all I need to do is type the following

    sudo etherwake fried

and `fried.rice` wakes up!

[gentoo]: "Gentoo WOL"