Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have setup wake on lan service on my server. Everything works fine on local area network:

root@server$: poweroff
user@local$ wakeonlan AA:BB:CC:DD:EE:FF

and the server wakes up.

AA:BB:CC:DD:EE:FF is a MAC address of my server, which has IP 192.168.1.2 and hostname: example.com. It is connected to the router, which has IP 192.168.1.1 (public: xxx.xxx.xxx.xxx)

When the server is up, I can ping:

ping example.com

or login via ssh:

ssh user@example.com

So far, so good. Now I'm able to wake the server up from local area, but how to wake the server from the remote location?

I tried: user@local$ wakeonlan -i xxx.xxx.xxx.xxx AA:BB:CC:DD:EE:FF, but it does not work (nothing happens;).

Do I have to configure my router somehow to forward magic packets? How?

The solution

After Ragnar's answer the solution looked very easy.

But actually, it was a bit tricky.

My router is Linksys WAG200g, which does not support Wake on LAN by default. Furthermore, it does not allow to forward to triplets above 254 (my broadcast address was 192.168.1.255).

The solution was to forward UDP port 7 to the address of the server, which was 192.169.1.2, then call:

wakeonlan -i example.com -p 7 AA:BB:CC:DD:EE:FF

Also I installed new firmware:

which is a great router options upgrade (e.g. adds Wake on LAN option).

I also changed my netmask from 255.255.255.0 to 255.255.255.128, so my broadcast is now 192.168.1.127 and passes the router validation rules.

Here is the script I use to connect to the machine, and wake it up if needed:

#!/bin/bash
## This sends magic packets to Wake on Lan
## please note, you must formard port 7 to the target machine on your router

## host to wake up
host="example.com"
## mac address of the machive to wake up
mac="AA:BB:CC:DD:EE:FF"
## user to login
user="administrator"

echo "Looking for $host..."
wget -q --tries=2 --wait=1 --waitretry=5 http://$host/
if [ $? -ne 0 ];
then
    echo "$host is not available."
    echo "Waking up $host."
    wakeonlan -p 7 -i $host $mac
    echo "$host is booting up.  Please wait..."
    sleep 30
    wget -q --waitretry=5 --wait=5 http://$host/
    echo ^G
    echo $host is up! Lucky you!
fi
ssh "$user@$host"

Don't forget to install: wakeonlan

share|improve this question

1 Answer 1

up vote 2 down vote accepted

You need to forward UDP port 9 to the broadcast address in your network (192.168.1.255, or alike).

share|improve this answer
    
Additionally, some routers have a WOL function built into them, so if you connect to your router, you can issue the WOL that way. –  Scaine Jan 1 '11 at 18:03
    
Thanks. And welcome aboard! –  takeshin Jan 2 '11 at 12:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.