UnixServerAdmin

Server Administration & Management

How to startup server using ether-wake

Wake-on-LAN is a useful feature on most network cards that allows you to remotely boot up a computer. The ethtool utility (found in the ethtool RPM) can tell you if your network card supports Wake-on-LAN:

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

Look for the “Supports Wake-on” line. It should list one or more letters, including “g” (WoL using Magic Packet). In the example above, Wake-on-LAN is currently disabled (“d”). The Wake-on-LAN setting does not persist. It needs to be configured every time the machine boots. On RHEL, this is usually done from /etc/init.d. Create a script called /etc/init.d/wol with the following content:

==============================================
#!/bin/bash
#
# wol Wake-on-LAN configuration script
#
# chkconfig: – 99 01
# description: Wake-on-LAN allows a machine to be started using a WoL network packet.
# This script configured WoL on interfaces listed in $NIC.
# processname: –
# config: –
# pidfile: –

# Source function library.
. /etc/rc.d/init.d/functions
# List of NICs to configure for WoL.
# Note: on Xen hosts, use peth0 instead of eth0.
NIC=”eth0?

if [ “$1” != “start” ]; then
exit 0
fi

echo -n “Enabling Wake-on-LAN for:”
for nic in ${NIC};
do
echo -n ” ${nic}”
[ -x /sbin/ethtool ] && /sbin/ethtool -s ${nic} wol g >/dev/null 2>&1
done

# Note: no error checking – ethtool does not return a useful exit code
success
echo

# EOF
==============================================

Add the script to the start-up sequence:

# chkconfig –add wol

# chkconfig wol on

The script will now be run on every reboot. You can check the result using ethtool eth0; it should now display “Wake-on: g“.

You should now be able to shutdown your computer, and wake it by sending a “WoL Magic Packet” from another computer. On Linux, use ether-wake (from the net-tools RPM) or wol (from the wol RPM) to send the Magic Packet:

# /sbin/ether-wake -i eth0 00:04:23:C0:FF:EE

Advertisements

January 31, 2012 Posted by | Tips & Tricks, Unix/Linux | , , , , | Leave a comment