Turning on computers remotely

Posted by Steve on Wed 20 Apr 2005 at 08:42

To save power it's often useful to turn systems off, but of course when you do that you cannot use them! This is especially frustrating when you turn off a machine which is physically remote from you, but it doesn't need to be. Many modern PCs have the ability to be remotely "woken up" and turned on.

"WakeOnLan" is the term which is used for remotely powering on machines, as this is done by sending "magic network packets" to switch on machines.

To use wakeonlan you'll need either:

Many modern systems with on-board NICs support wakeonlan, but it must be enabled in the BIOS. (Look for the option in the "power management" section of your BIOS, it might be called "wakeonlan", "netboot", or "wake on ring events").

If you have the requisite hardware support can see if it's enabled by your system by running the ethtool command, this shows whether the wakeonlan option is supported by your card, and whether it is enabled.

If you don't have this installed run:

apt-get install ethtool

Once it's installed run it with the name of your network interface:

root@lappy:~# ethtool eth0
Settings for eth0:
       Supports Wake-on: g
       Wake-on: d
       Link detected: yes

Here we can see that wakeonlan support is available because of the g, but it's disabled. (This is explained in the manpage which you can read with "man ethtool"). To enable the magic packet support run:

root@lappy:~# ethtool -s eth0 wol g

Now you should be able to see that it's turned on:

root@lappy:~# ethtool eth0
Settings for eth0:
       Supports Wake-on: g
       Wake-on: g
       Link detected: yes

Now that you know it's turned on you need to do one more thing. Wakeonlan software requires that you know the MAC address of the machine you wish to switch on, rather than the IP address.

To determine the MAC address you can either:

To determine the MAC address via ifconfig just run it:

skx@mystery:~$ /sbin/ifconfig 
eth0      Link encap:Ethernet  HWaddr 00:0A:E6:F6:A3:F4  
          inet addr:192.168.1.80  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::20a:e6ff:fef6:a3f4/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2218390 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3098440 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1624008578 (1.5 GiB)  TX bytes:1368310661 (1.2 GiB)
          Interrupt:10 Base address:0xd400 

Here the MAC address is 00:0A:E6:F6:A3:F4, it's on the first line and is described as the "HWaddr" or "hardware address".

If you're looking for the MAC address of another machine upon your LAN you can ping the machine, then look at the arp cache.

For example if I wished to determine the MAC address of the machine sun.my.flat from my current host I'd run the following two commands:

kx@mystery:~$ ping -c 1 sun
PING sun.my.flat (192.168.1.1) 56(84) bytes of data.
64 bytes from sun (192.168.1.1): icmp_seq=1 ttl=64 time=0.202 ms

--- sun.my.flat ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.202/0.202/0.202/0.000 ms
skx@mystery:~$ /usr/sbin/arp sun
Address                  HWtype  HWaddress           Flags Mask            Iface
sun                      ether   08:00:20:C2:1E:F6   C                     eth0

The arp command shows the machine's MAC address, the ping being required first to make sure that my current machine knew the MAC address in the first place.

Once you have the MAC address you can shutdown the system you wish to test, and then attempt to restart it remotely.

There are several pieces of software for sending the wakeonlan packets inside the Debian archive:

I'm going to use wakeonlan, since it's already installed and can be used by non-root users:

skx@mystery:~$ wakeonlan  08:00:20:C2:1E:F6 
Sending magic packet to 255.255.255.255:9 with 08:00:20:C2:1E:F6

This sends the magic wake on lan packet to the machine on the LAN with the hardware address "08:00:20:C2:1E:F6" which we previously determined belonged to the machine sun.

If all goes well the machine will begin to boot shortly after recieving the packet.


This article can be found online at the Debian Administration website at the following bookmarkable URL:

This article is copyright 2005 Steve - please ask for permission to republish or translate.