Wake-on-LAN on Linux with a Linksys WRT54g

My D-Link router died and I bought a Linksys WRT54g thinking I could put Linux on it. Unfortunately, I should have checked a little more before I bought it because I got a v5, which has half of the RAM and flash memory and is not compatible with most 3rd party firmwares. I also found out that I could not forward packets to the broadcast address, which is exactly what I needed to do to get Wake-on-LAN working.

I use a web based Wake on LAN utility to wake up my computer. Since a computer that isn’t powered on does not have an IP address, it listens for a “magic packet”. A magic packet is data sent over the network to every computer that has the MAC address of the computer you want to turn on. I needed to forward the magic packet to the broadcast address, which on my home LAN was UDP port 9 on 192.168.1.255. However, the Linksys WRT54g will not allow you to forward a port to xxx.xxx.xxx.255, so I needed to find another way. After doing some research, I found out that I could change the subnet from 255.255.255.0 to 255.255.255.128, so the broadcast address would then be xxx.xxx.xxx.127, which could then be forwarded in the Linksys WRT54g.

routersubnet.jpg

portforward.jpg

Update: Aaditya Bhatia also suggested turning off Javascript temporarily to disable the error check. This works well, but please use caution as entering something less than 0 or greater than 255 could possibly kill the router permanently.

Next, I needed to turn on Wake on LAN support in Linux. I did an “apt-get install ethtool” and ran “ethtool eth0″ in the console. It read “Wake-on: d”, showing that wake on LAN was disabled. I ran “ethtool -s eth0 wol g” which turned it on. However, it would only work one time and then I would have to run “ethtool -s eth0 wol g” again. I found that if you edit /etc/network/interfaces and add “up ethtool -s eth0 wol g” under “iface eth0″, it would run every time the interface was started.

Thanks to this article for the ethtool info: http://www.debian-administration.org/articles/122

and thanks to this site for the subnet calculator: http://www.subnet-calculator.com/

13 Responses to “Wake-on-LAN on Linux with a Linksys WRT54g”


  1. 1 Marc

    Hi,
    thanks for your this nice manual on how to wol with a wrt54g !
    Could you tell me what Linksys Firmware Version you are using ?
    Thanks a lot…

  2. 2 n01getsout

    I am currently using version 1.02.0, but I believe I was still using version 1.01.1 when I wrote this article. Let me know if you are having any problems.

  3. 3 Marc

    Thanks for the quick answer ;-)

    It seems that the older Linksys WRT54G Router (mine is v2.2) with the *Linux* based original Linksys firmware (mine is v4.30.7) do not manage the forwarding of a magic packet from the internet to the inside LAN. Your WRT54G does use VxWorks as operating system and it seems they have fixed this problem in the different firmware.

    If anyone can prove me wrong, let me know.

    Cheers…

    Marc

  4. 4 Leon

    Hi, Do you have to do the same with your previous Dlink router?
    I have a DI-704P router and have the same problem of not being able to forward to 192.168.0.255.
    Thanks!
    Leon

  5. 5 n01getsout

    Leon, I had two D-Link routers, both a DI-614+ and a DI-514. Neither one of them had this problem, but the solution should still work as it is not router specific. Let me know if you have any problems.

  6. 6 nightrain

    Hi.

    I’ve tried to do this but I’ve not could make it work.

    Some data:

    * I’ve got a wrt54gs v4
    * My board supports wake on pme and it’s on
    * I’ve activate wake on lan in eth card
    * I’ve changed network mask to 255.255.255.128
    * I’ve redirected UDP por 9 to 192.168.1.127

    I think that the problem is this: I have a cable connection; cablemodem gets the eth card mac to authenticate user first time it’s used, so when I installed the wrt54gs I had to clone eth mac in router so that cablemodem recognizes it as a authenticated device. So I have router and eth card with same mac address ¿can this be the problem ? If so, is ther any way to solve this ?

    Thanks

  7. 7 nightrain

    I’ve changed router mac address but it did not work. I could wake up computer from my LAN but not from internet. Something may happen with magick packet but id did not reach its destination.

    So I decided to install a new firmware in the router. I’ve installed dd-wrt firmware; that firmware includes some options for wake on lan that let you wake up a computer from the router’s admin panel. So I created a registry with the eth card mac address and activated remote administration; this way I only have to access the router’s admin panel and wake computer up. This is like waking it up from inside the LAN but it’s accessible from internet. I have to try to wake it up from the internet without accessing router’s admin panel. I haven’t had time yet but I will try and let you know.

  8. 8 nightrain

    Finally I could wape up computer without using wouter’s web admin panel. Bu I could not make it work broadcasting, I followed this tutorial: http://www.dd-wrt.com/wiki/index.php/WOL

  9. 9 Aaditya Bhatia

    I was able to enter 255 for port forward ip, by blocking javascript selectively. Once I did that, I was able to forward the desired port to the broadcast IP. It’s just a javascript validation that you have to bypass. I used noscript plugin with Firefox for the job.

  10. 10 n01getsout

    Great tip, Aaditya! I tested this and it seems to work great. I don’t know why I never thought to try that first. :P If you decide to do this on your router, please double check that the IP address you entered is not less than 0 or greater than 255, as a number outside that range could permanently brick the router.

  11. 11 Vincent

    Great tutorial! One more things about the javascript trick… When using the noscript plugin, I had to disable the “automatically reload affected pages when permission changes”. Otherwise the page is refreshed when the scripting is turned off, and all links and buttons (including the submit button) disappear. But disabling without refreshing still works–just make sure you are on the right page before disabling. The disappearing buttons things might be a new “feature” in more recent models (I have a WRTG54GS v.7 with firmware 7.50.0).

  12. 12 OBrien

    Hello!
    Just as nightrain, I have a v4 WRT54GS and subnet mask changing stuff didn’t work. I also tried the JS method, I disabled refreshing pages but in this case the Apply Changes button didn’t work. And if I enable JS after typing 255 I don’t get the 0..254 error but after applying it says “invalid values”. I don’t want to upload a new firmware if it’s not very necessary. Anyone can help me?
    Thanks:
    OBrien

  13. 13 volkswagner

    Glad I found this. I was stumped. I did not realize the ip would not be recognized with pc off, duh. Changing the subnet in the router worked great. Thanks for posting this solution. Running WRT54G.

Leave a Reply