Tomato firmware: Remote desktop through SSH, using Wake-On-Lan and configuring LAN Hostnames

August 13th, 2008 | Category: How-To

Hi,

I’ve been using 3rd party firmware for my Linksys WRT54GL router for some time.  I’ve used DD-WRT, OpenWRT and finally Tomato.   I switched from DD-WRT (for a reason I can’t remember) to go with OpenWRT.  I learned a lot on OpenWRT and really like their Kamikaze version.  The work they did for making it more like a standard distribution (no more NVRAM variables) is really cool.  Finally I recently moved to Tomato because of the lack of User Interface of OpenWRT (Yes I could use X-WRT but I tried it before and prefered to explore Tomato…).  When I feel lazy I prefer to use a GUI than go to the CLI…

Now that I am more familar with my WRT (thanks to OpenWRT and all its documentation), it has been pretty easy to configure Tomato (firmwares are different, but in the end, they often use the same tools… busybox, dnsmasq, etc.).  I have some specific needs that drove me to install a 3rd party firmware in the first place:

  1. I need to be able to access my computers from the internet using remote desktop

  2. But I don’t want to leave my computers open all day long for nothing, so I need to be able to use Wake-On-Lan to power them up remotely

  3. I don’t want to open remote desktop port (3389) on the firewall

  4. I want to use DHCP server, but I need to set some specific address (static DHCP) on some computers
    (so port forwarding is always configure correctly for my P2P machine…)

  5. I need to be able to use the same domain name (ex: mysite.dyndns.org) with my laptop no matter if I connected to my LAN or to a public network (through the Internet)

My Solution:

Feature Tomato Configuration
Access my computers from the internet using remote desktop.
  1. I setup an account with dynDNS. It is free up to 5 domain names (if I remember correctly).This account allows me to use a software to update a domain name with my new IP address when my ISP changes it. From the internet I can just connect to my router using example.dyndns.org.Most routers supports dynDNS (and some others as well) natively.
  2. I enabled the SSH Deamon
    (Administration / Admin access)Enabled at Startup: checked
    Remote Access: checked
    Remote Port: [your choice]
    Allow Password Login: checked
  3. When I want to connect to my computers, I use a SSH client software (PuTTY) to connect to my router.PuTTY allows me to configure SSH Tunnels so I can redirect a local port to a remote machine on my LAN without opening any additionnal ports.
I need to power up my computers only when needed. This requires the Wake-On-Lan feature.Most modern computer has this feature (My old Pentium 2 266Mhz had it back in 1998) but you usually have to turn the feature ON in your computer BIOS because it is often disabled by default.When you want to power-up a computer, all you need is its mac address (in Windows, you can find it by running IPCONFIG at the command line) and a software that will broadcast a “magic packet” on your LAN.Tomato has a built-in software called ether-wake that does the job.My configuration is like this:On startup of the router, generate a file called wakeup-mycomputer.sh that will be placed in the root home directory. This file will contain the command able to wake-up the computer you want.

Then when you logon to your router using SSH (from the LAN or the Internet), you can issue this command “sh wakeup-mycomputer.sh” and you’re done.

You wait a little bit (until your computer responds to ping) and use the steps of the previous feature to connect remotely…

How to achieve this:

  1. In the Initialization script of the firmware (Administration / Scripts / Init tab), type this:
    echo "/usr/bin/ether-wake 01:23:45:67:89:AB" > /tmp/home/root/wakeup-mycomputer.sh
    (change 01:23:45:67:89:AB to the mac address of the computer you want to wake-up)
  2. Save and reboot the router, you should see the file “wakeup-mycomputer.sh” appear in the root home directory when you connect using SSH.
  3. Try it “sh wakeup-mycomputer.sh”

Note: for the wake-on-lan to work, the computer must have been turn off (soft off). After a power outage or a hard off (unplug, press power off for 5 seconds) the wake-on-lan may not work. Just turn on the computer manually and perform a shutdown.

Note2: I found out that some Linux distribution does not “soft off”. With Ubuntu 8.04, for example, I needed to add a command in the shutdown script… can’t remember. Just post a comment if you want me to digg it again…

Configure static DHCP addresses. This is easy, just navigate to the Tomato “Basic / static DHCP” menu item. Use the mac address of the computer you want a fix address and the address you want for it.
Use the same domaine name inside the LAN and outside (from the Internet).

When I am connected from the Internet, my domain “example.dyndns.org” resolve to my router public address which forward the port to the right LAN machine.When I am on the LAN, I want to be able to connect using “example.dyndns.org”. But if this domaine resolve to the public address of the router while you are already in the LAN, it does not work. To correct the problem, you could use a host file on your LAN computers, but when you have a laptop that is sometimes on the LAN, sometimes on an external network, you would need to enable/disable your host file every time…The way I succeed to anwer my need, is by providing a host file to the router. I found 2 ways with the Tomato firmware:

First way is explained here on Tomato FAQ.  Unfortunately, I needed to provide multiple host names (domain name) to the same IP address, you can do it by separating them with a space, but Tomate host name field is not wide enough for me.

So my solution goes like this:

  1. Create a host file with my ip / host bindings at router boot time (before firewall is started).
    In “Administration / Scripts” menu item, on “Init” tab, place the following lines (use your IP addresses and domain names):
    echo "192.168.1.xxx  example.dyndns.org" > /tmp/hosts.local
    echo "192.168.1.yyy  example2.dyndns.org" >> /tmp/hosts.local
  2. Configure the firewall (dnsmasq) to use this additional host file.
    In “Advanced / DHCP/DNS” menu item, in custom configuration, place this to enable your custom host file:
    addn-hosts=/tmp/hosts.local
  3. Save and reboot the router.
  4. Test by doing a ping of you domain names (ping example.dyndns.org).
    The result should be your configured local IP addresss, not the router’s public IP address.
47 comments