How to configure the Comtrend’s HG532c ADSL router ARP table for (WOL) Wake On Lan from internet using expect

Several months ago I finally got the (WOL) Wake On Lan feature of my RTL8111/8168B NIC card working. The problem was that a new driver (other than the provided by Debian) and a special PCI configuration was needed.

The other problem I had to deal with was the ADSL Router (Comtrend HG532c, The one provided by the Spanish ISP Jazztel) configuration:

  • Open the required port: This was an easy one just opening the 7 a 9 port and forwarding them to the server we want to WOL from the internet
  • Make the router remember the server’s tuple MAC/IP address. That was easy too, but some manual work was needed as when router is restarted the ARP table is flushed.  🙁

In my current job I had to change recently some configuration and restart more than 600 IP phones. To perform such titanic task I created a quick and dirty script using expect. It worked like a charm and made me think about automatize the way I set the ARP table in my Comtrend HG532c ADSL router.

The scripts is very easy to understand. It just simulates a Telnet session with your router:

  1. Login and password
  2. Set the required MAC/IP tuple
  3. Displays the ARP table

Here you are:

  1. #!/usr/bin/expect -f
  2. set timeout 10
  3. set env(TERM)
  5. set router "router"  #your router's dns name or IP
  6. set login "admin"    #your router's login. admin is the default
  7. set password "admin" #your router's password. admin is the default
  8. set ip "" #your server's IP address (not the dns name)
  9. set mac "2f:1e:8a:84:2a:f9" #your server's MAC 
  11. spawn telnet $router
  12. expect "Login: "
  13. send -- "$login\r"
  14. expect "Password: "
  15. send -- "$password\r"
  16. expect "ATP>"
  17. send "sh\r"
  18. expect "# "
  19. send "arp -s $ip $mac\r"
  20. expect "# "
  21. ## check that all is right
  22. send "arp -a\r"
  23. expect "# "

The output must be similar to:

juan@mediacenter:~/bin$ ./
spawn telnet router
Connected to router.
Escape character is '^]'.
-----Welcome to ATP Cli------

Login: admin

BusyBox vv1.9.1 (2011-05-25 16:23:47 CST) built-in shell (ash)
Enter 'help' for a list of built-in commands.

# arp -s 00:1e:8c:84:2a:f9
# arp -a
? ( at 2F:1E:8A:84:2A:F9 [ether] PERM on br0

As can be seen in the last line the router have set the ARP entry as permanent…. permanent till router next restart. 🙁 But at least every time this script is run the ARP is set automagically 🙂

The next thing to do is to put this script in a crontab job, /etc/rc.local, etc of one of your servers. This way every time it runs you will be sure that you can restart your server from the internet.

My decision was add a line in my server’s /etc/rc.local file like this:

  1. #### Sets the MAC/IP tuple in ADSL router for WOL from internet
  2. /path/to/ |mail -s "`hostname` MAC para el WOL" email@domain.tld

This has 2 added benefits:

  1. I will know when my server is started
  2. I will know that my router configuration is ready for wake on lan

The last step is have at least to ways to start your computer from the internet. Mine are:

  1. Online Wake-On-LAN web page.
  2. Wol Wake on Lan Wan for my Android phone.

I have created a github project: expect-update-arp-table-ADSL-router-for-wol (just in case other features can be added later) where you can download also the source code.



2 thoughts on “How to configure the Comtrend’s HG532c ADSL router ARP table for (WOL) Wake On Lan from internet using expect

  1. Thanks a lot for that one I’d been telneting to portforward my Router before and ATP just needs some extra steps. Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.