Thursday, December 11, 2008

Linux Wake on LAN

WakeOnLan allows you to switch your PC without physically accessing it by sending a magic packet to it.For more information visit this Wikipedia's page

Check weather WOL is supported by your NIC

Downlad and install ethtool and then issue the command sudo ethtool eth0 { or what ever your ethernet device is and you will get something like this

linux@ubuntu:~$ sudo ethtool eth0
Settings for eth0:
Supported ports: [ TP ]
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: Twisted Pair
PHYAD: 0
Transceiver: internal
Auto-negotiation: on
Supports Wake-on: pg
Wake-on: d
Current message level: 0x000000ff (255)
Link detected: yes

check out the line Supports Wake-on ( as highlighted above) if it contains a g flag the your NIC supports WOL


Enabling WOL


To enable WOL issue the command sudo ethtool -s eth0 wol g this can be verified by checking the Wake-on flag

linux@ubuntu:~$ sudo ethtool eth0
Settings for eth0:
Supported ports: [ TP ]
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: Twisted Pair
PHYAD: 0
Transceiver: internal
Auto-negotiation: on
Supports Wake-on: pg
Wake-on: g
Current message level: 0x000000ff (255)
Link detected: yes




Note down the mac address of the machine


To get the mac address use the command sudo ifconfig eth0

linux@ubuntu:~$ sudo ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:1d:72:04:59:25 inet addr:192.168.155.6 Bcast:192.168.159.255 Mask:255.255.248.0 inet6 addr: fe80::21d:72ff:fe04:5925/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:14840 errors:0 dropped:0 overruns:0 frame:0 TX packets:2521 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:2362485 (2.3 MB) TX bytes:608765 (608.7 KB) Interrupt:16



Install wakeonlan package on a different machine

Install the wakeonlan package in the machine from where you need to send the magic packet to switch on your server.

Finally, Switch ON the machine remotely without physical access
When the server is not up, execute the following command from another machine which is connected to the same LAN. Once the magic packet is sent, the remote system will start to boot.


Enabling WOL across multiple reboots


The WOL feature has to be enabled manually after every reboot in order to avoid this problem just install the following script in /etc/rc.d directory by using chkconfig (Red hat or fedora) or update-rc.d (ubuntu or debian)

#!/bin/bash
DEV="eth0"
FEATURE="wol"
FLAG="g"
ETTOOL="ethtool"
$ETTOOL -s $DEV $FEATURE $FLAG
n=$?
if [ $n -eq 0 ]
then
echo "WOL enabled successfully "
else
echo "Cannot enable WOL"
fi

1 comment:

VIVEK KUMAR said...

great man....u hav jst solved a very big problem of mine...looking forward to some more technical stuffs..thanks techno