Wake On LAN over the Internet

Having recently set up a linux box at home to host things like VMWare Server and generally provide access to things I want remotely while working away, I also wanted a way to be able to fire up the box only when I wanted it to be running. So, I figured I’d set up the Wake On LAN feature of the box to be exposed to the internet.

Here’s how I did it…

  1. Get the code
  2. Set up the router
  3. Send the packet

1) Get the code

Paul Mutton has put up some Java code that allows you to send a Wake On LAN packet. Now the great thing about Java, as everyone knows, is that it is cross platform so all you need is Java to be installed to be able to run the code.

Now, if like me you’re perhaps worried about bots etc on the net that poke around on known internet ports as they crawl the internet, you might want to change the port number that is exposed to the internet so that its a bit more difficult for someone or somebot to work out that it can send a Wake On LAN packet to the address. I know that you need to also specify the MAC address when you send the packet but I just like the extra layer of disguise.

So, open up the WakeOnLan.java file and edit the following line to a port number that you want to use:

WakeOnLAN Port Number Code

WakeOnLAN Port Number Code

There is no change you need to make to the target ‘sleepy’ computer – port 9 is still the port that will be used to wake it up, but we’ll convert the port 9 to port N that you’ve chosen to expose to the internet at the router level (See next step).

Compile the code by opening a command line up to the location of the WakeOnLan.java file and type:

javac WakeOnLan.java

This should create a WakeOnLan.class file so check that there were no errors and that the file was created.

2) Set up the router

Right, now this bit is going to be specific to your router but here’s what you need to do:

  1. Make sure that your ‘sleepy’ computer is known to the router and either has the same IP assigned to it every time locally OR that the router is intelligent enough to map the firewall rule to the same device each time, regardless of which IP it dishes out to it.
  2. Set up the firewall rule to map your chosen exposed port to port 9 on the ‘sleepy’ computer.

For me, I have an O2 Thomson Router (TG585v7) some people on the internet have described that they’ve had to telnet to the router and set up arpadd, this is necessary to enable the permanent routing of the wake packet  even after the computer has been off for a long time (see below).

Here’s how I’ve set it up on my router, if you’re using a different router you’ll have to try something similar:

  1. Go to the router web page and navigate to Toolbox > Game & Application Sharing.
  2. Click “Create a new Game or Application”
  3. Name it as you like, I’ve called mine WoL
    Firewall Rule Name

    Firewall Rule Name

    Be sure to select “Manual Entry of Port Maps”

  4. Select UDP and enter in the exposed port number range in the first boxes and the target port of 9.
    Port Range

    Port Range

    I’ve used 12345 as an example port exposed to the internet here, but use whichever port you’ve chosen. Click Add when you’re done.

  5. Now we need to assign this rule to the ‘sleepy’ computer… Click on “Assign Game or Application” near the bottom of the page:

    Assign firewall rule link

    Assign firewall rule link

  6. Assign the newly create rule to the computer you want to wake and click Add

    Select device

    Select device

  7. You’ll have to define a static ARP entry on the router, just creating a static IP from within the GUI wasn’t enough for me – after a while if the ‘sleepy’ computer was off-line then the Wake packet seemed to have no effect. I think this is because of the dynamic nature of the router perhaps marking the device as down and no longer forwarding packets. Anyway, based on a similar issue to here, this is what you need to do:
  8. telnet o2wirelessbox.lan
    (Google for the password)

    (If there is an entry for your device then use arpdelete to remove it first)

    Select intf and hit return
    Use the down arrow to select LocalNetwork and hit return
    Fill out the IP and MAC address also

    When done, type arplist and see that there is an entry with STATIC listed

    NOTE: I had this gotcha when I had to redo this on my router after a hard reset… You need to have your target machine powered down once you delete the ARP entry, otherwise it gets assigned another one dynamically – so beware of this if you find that your new entry is still DYNAMIC rather than STATIC.

    If you don’t make sure it is STATIC then the route times out after a while and your WOL packet won’t get sent on.

  9. Tab to cancel to exit the menu
  10. Type “saveall” to persist the configuration after a reboot
  11. Type “exit” to log out of the telnet session.
  12. Done!

3) Send the packet

So hopefully, the router rule is set up with the same port that you’ve coded into the Java class and are ready to send the packet from the internet to the router.

I’ve set up a DynDNS address so that I don’t have to find out the IP address every time. Most modern routers support the ability to update a Dynamic DNS service such as DynDNS, it will mean that you don’t need to know the IP and it will automatically get updated should your internet connection be reset for any reason.

So, the information you need to be able to send the packet using the ‘customised’ code is:

  1. The external IP address of the router OR the Dynamic DNS address that you’ve set up
  2. The MAC address of the network card that’s listening for a Wake on LAN packet on your ‘sleepy’ computer

Upload the code you compiled in step 1) to a computer you’ll be using from outside the local network and execute the code from the command line in the folder you’ve placed the code. For example:

java WakeOnLan your.dyndns.address 00:11:22:33:44:AA

You can swap the dynamic address above for the IP address if you wish.

Next step – give the box some time to boot up!


If you’re setting this up at home and have remote access to a computer outside of your local network, it will help you to be able to test and verify that things are working. You can use the external computer to send the Wake on LAN packet from the outside and watch to see if the computer actually wakes up.

I hope this post is useful to anyone trying the same, I’ve written it up mainly for my own benefit to remember how to do it next time around but let me know in the comments if you’ve found a better way for your set up. I personally like the Java code approach as I can run it anywhere and don’t have to install a program to the external computer that’s doing the waking; I use a variety of computers with differing operating systems so I like the light-weight approach 🙂

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.