Saturday, January 24, 2009

Send Hostname to Router

I have Tomato firmware on my Linksys WRT-54GL wireless router. I purchased the router so I could put Tomato or another open source firmware version.

One of the things that I wanted with this was to assign the same ip address to each computer through DHCP and get my internal DNS working without setting up bind. The tool that performs this duty and comes with most of these firmwares is Dnsmasq. It's a very easy to setup DNS and DHCP server.

The Tomato web interface makes it easy to assign an ip address to the specific MAC address of the ethernet or wireless network card. If the machine has one interface this isn't a problem. This becomes an issue for laptops that connect either via the wireless card or the ethernet cable. The problem is that Dnsmaq (and most other DHCP software) will not allow the same ip address to be assigned to two different mac addresses.

Most DHCP clients have the ability to send a hostname so that the DHCP server can assign a specific address to the machine everytime no matter the interface being used. This prevents tying the ip address to a specific MAC addresss. This ability is easy to enable in the Dnsmasq interface in Tomato.

Go to the Advanced -> DHCP/DNS. Enter the following in the custom configuration section:
dhcp-host=MyHostname.domain.what, 192.168.xx.xx

Change the information to be what you want it to be for your internal network. I don't use a "domain.com" or "domain.anything" that is could be a real domain name.

In Windows, change the computer name to match "MyHostname" and reboot. After rebooting, go to Start -> Run -> type cmd and click Run. A command window should have appeared. Type ipconfig[ENTER] to see the IP Address assigned. I had no problem setting this up in Windows.

Under Fedora 10, I ran into more difficulty. I used the normal Network Admin tools to attempt to set the "DHCP-Hostname". After starting the interfaces a few dozen times, I was never able to get the IP assigned in this manner.

NetworkManager is used to control the interfaces on the laptops. If it used to edit the connection information, there is an option on the IPv4 Settings tab for DHCP Client ID. This is not the same as sending the hostname.

In the man page for dhclient.conf, there's an option for sending the hostname:
send host-name "MyHostname.domain.what";

The problem is that NetworkManager does not read the file called /etc/dhclient.conf. NetworkManager generates it's own .conf file to pass to dhclient. Finally I came across a post that mentioned creating a file called /etc/dhclient-ifname.conf. In my case, the files are called:
/etc/dhclient-eth0.conf
/etc/dhclient-wlan0.conf

I placed the above configuration option for sending the hostname into these files and restarted NetworkManager. NetworkManager or the dhclient program picked up these file for the interface and sent the host-name. So it works for me now.

This is what's in my /etc/dnsmasq.conf file on the router:

interface=br0
domain=doman.internal
resolv-file=/etc/resolv.dnsmasq
addn-hosts=/etc/hosts.dnsmasq
expand-hosts
min-port=4096
dhcp-range=192.168.xx.mm,192.168.xx.rr,255.255.255.0,1440m
dhcp-option=3,192.168.99.2
dhcp-authoritative
dhcp-host=00:15:C5:BB:37:3C,192.168.xx.aa,1440m
dhcp-host=00:0B:82:04:03:E7,192.168.xx.bb,1440m
dhcp-host=00:04:F2:02:27:62,192.168.xx.cc,1440m
dhcp-host=MyHostname.domain.internal,192.168.xx.hh


If you don't want to maintain a /etc/hosts file on all of your machines, ssh into the router and edit the /etc/hosts file. Any ip and name pair will resolve when doing the following from the command line:
host machine-name

The /etc/hosts/file looks like this: This doesn't work

192.168.xx.aa MyHostname
192.168.xx.bb AnotherHostname



Update: Modifying the /etc/hosts files directly doesn't work. This post describes what you need to do. Go to Basic ->Static DHCP and add an entry. Don't fill out a mac address.

Update: Added a semi-colon to the send host-name line.

No comments: