Name your home machines using Tomato
April 16th, 2008
Update (February 2009): thanks to an email I have just received asking how the mechanism described below is better than just assigning host names in Tomato “normally”, I have discovered that this whole post was rather pointless. There is already a way to assign host names in Tomato: click on “Basic” then on “Static DHCP”, and enter your IP addresses and corresponding host names there. I had thought, from its name, that the “Static DHCP” entries were only relevant when machines were booting (when they use DHCP to ask for their host name), but I was wrong: the host names are also returned by the Tomato DNS server for both forward and reverse DNS requests. So while this post is still useful reading if you want to understand better why you might want to use host names for your home machines, the actual mechanism described below is much more trouble than is actually necessary.
I am enjoying my first weeks of using the Tomato Firmware. I purchased a Linksys WRT54GL wireless router because of its admirable support for third-party firmware like Tomato, which replaces the traditional Linksys setup screens with an alterative system with many more configuration options. I can also connect directly to Tomato over SSH and use it as a very small Linux system! This opens endless possibilities for writing fancy firewall rules and running small embedded applications right at the border of my home network.
The Tomato firmware uses a small DNS server named dnsmasq to answer the steady stream of domain name requests from my home computers. It converts domain names that I type, like rhodesmill.org or google.com, into the low-level IP addresses with which computers identify each other.
But I also like using hostnames for the machines sitting right in my home, even though they do not have “real names” out on the Internet. I recommend placing local hostnames inside of a top-level domain that is local to your own network. Choose a suffix that differs from all of the top-level domains that exist out on the Internet — avoid .com, .net, or .uk, for example, in favor of something like .home or .myhouse instead. How, I wondered, could I add extra host names to dnsmasq?
After my first glance through the dnsmasq documentation, I thought that a series of address options might be the best way to provide my local hosts with names. So I visited its Tomato setup screen, which is under the DHCP / DNS section of the Advanced configuration options, and entered something like this into the “Custom Configuration” file:
local-ttl=1 address=/mail.home/192.168.1.2 address=/gamebox.home/192.168.1.3 address=/printer.home/192.168.1.5
The local-ttl option is necessary because the default value, zero, encourages the host(1) command on my Linux machine to issue a warning message for every host I look up.
This setup seemed to work fine, and made it possible to use hostnames like gamebox.home when connecting from one machine to another on my home network. But I noticed delays when creating SSH connections between home machines, as well as errors in my system logs, and, as a result, discovered that this configuration was only working in the forward direction: dnsmasq knew that gamebox.home was a name for the IP address 192.168.1.3, but it could not answer the reverse question, “What name belongs to the IP address 192.168.1.3?”
I returned to the dnsmasq documentation, read more thoroughly, and learned that it publishes both forward and reverse names for hosts that it finds in the /etc/hosts file. While the Tomato firmware does not seem to support an editable /etc/hosts file whose contents will reappear when the Linksys router reboots, it does provide an auxiliary flash-based filesystem. So I was able to solve my problem in three steps:
- I visited the JFFS2 screen in dnsmasq, under the Administration section, and enabled it. This creates a writable flash-based filesystem that gets mounted at /jffs every time the router boots up. After pressing “Save” and waiting for Tomato to apply the change, reboot the router to make sure that the new filesystem gets properly mounted.
- I created a /jffs/hosts file by connecting to Tomato with SSH and using vi to edit and save the file. It looks like a normal /etc/hosts file:
192.168.1.2 mail.home 192.168.1.3 gamebox.home 192.168.1.5 printer.home
- Finally, I removed all of the host names from the dnsmasq configuration itself, and simply provided the path to my new hosts file instead:
local-ttl=1 addn-hosts=/jffs/hosts
With this improvement, both forward and reverse name lookups now work perfectly! To add or remove a host name in the future, I can simply re-edit the file. Though I once dreaded the inflexibility of small embedded appliances, Tomato has finally convinced me to replace the large, noisy Linux box at the edge of my network with something far more tidy and sleek.
Posted:
Wednesday, April 16th, 2008 at 10:38 pm
Categories: Computing
If you respond on your own blog, trackback to this entry!
[...] setting ip dnsmasq, I ran across this helpful post. I just want to add that you have to reboot the modem to get the jffs filesystem mounted before [...]
May 24th, 2008 at 6:46 pm