Today I configured dnsmasq, running on Kamikaze 7.09, to serve out static IP addresses via DHCP to the computers connected to the router, a Linksys WRT54GL. The original firmware that came with the WRT54GL didn't support this feature, hence the major reason for me to use an alternative firmware. I had flashed Kamikaze 7.09 (OpenWrt) on the WRT54GLlast Monday, and I already liked it a lot. I am quite used to working on the command line, so I was not alienated by typing commands in PuTTY to configure the Linksys router.
I also extended the /etc/hosts
file on the router for three (good) reasons: the first one is
that somehow Ubuntu couldn't resolve hostnames from XP machines when I used DHCP. For example,
ping cadwal
didn't work from a computer running Ubuntu, with cadwal running
XP. Yet the original firmware of the Linksys router did recognize the machine as cadwal.
Second, I use virtual hosting a lot for development, and
by extending /etc/hosts on the router, I can access those virtual hosts from
other computers as well, thanks to dnsmasq. And the third reason: being able to block
websites by hostname for all devices connected to the router.
The program that provides the DHCP service on Kamikaze is dnsmasq. Static IP addresses via DHCP are assigned to the connected computers based on the MAC address, a quasi-unique identifier assigned to the network adapter of each computer. The dnsmasq program can use information in /etc/ethers - MAC/IP pairs - to hand-out the IP address for a MAC address it received. So first I needed the MAC address of each device that could connect to the router in our house.
The easiest way I could think of to obtain the MAC addresses was to turn on each computer, and
examine the contents of /tmp/dhcp.leases
on the router using cat
:
946728494 xx:xx:xx:xx:xx:xx 192.168.1.105 claudia 01:xx:xx:xx:xx:xx:xx
946728233 xx:xx:xx:xx:xx:xx 192.168.1.100 ecce *
946728124 xx:xx:xx:xx:xx:xx 192.168.1.101 cadwal 01:xx:xx:xx:xx:xx:xx
946728106 xx:xx:xx:xx:xx:xx 192.168.1.104 WM_Araminta 01:xx:xx:xx:xx:xx:xx
946728062 xx:xx:xx:xx:xx:xx 192.168.1.137 * 01:xx:xx:xx:xx:xx:xx
946728027 xx:xx:xx:xx:xx:xx 192.168.1.102 throy *
Note: I've replaced the actual MAC address of each device
with xx:xx:xx:xx:xx:xx
.
The /tmp/dhcp.leases
has the following fields:
/etc/ethers
Next, I copied the output of cat /tmp/dhcp.leases
from PuTTY, using the middle mouse button, to TextPad, and moved
the data around a bit, and added comments. The end result looked as follows:
# ecce - Dell Vostro 200 ST
xx:xx:xx:xx:xx:xx 192.168.1.100
# cadwal - Compaq Presario SR1505LA
xx:xx:xx:xx:xx:xx 192.168.1.101
# throy - Acer Aspire 4320
xx:xx:xx:xx:xx:xx 192.168.1.102
# wonderland - Dell Inspiron 1525
xx:xx:xx:xx:xx:xx 192.168.1.103
# WM_Araminta - Dell Axim X51v
xx:xx:xx:xx:xx:xx 192.168.1.104
# claudia
xx:xx:xx:xx:xx:xx 192.168.1.105
Note: I've replaced the actual MAC address of each device
with xx:xx:xx:xx:xx:xx
.
Then I typed vi /etc/ethers
in PuTTY to start vi
on the router, and typed 'i' to set vi
in insert mode. Next,
I selected all lines in TextPad, and pasted them in PuTTY. I saved the
lines and quit vi by pressing the ESC key, and typing 'w' followed by 'q'.
Finally, I rebooted the router by typing reboot
. Note that not
all computers got their new IP address according to /etc/ethers this way, they
kept their earlier assigned IP address. Executing ipconfig /renew
with Adminstrator rights on the computers running Windows XP fixed this.
/etc/hosts
Next I extended the /etc/hosts file. An excerpt follows below:
127.0.0.1 localhost.
192.168.1.100 ecce
192.168.1.101 cadwal
192.168.1.101 lc.johnbokma.com
192.168.1.101 lc.castleamber.com
192.168.1.102 throy
192.168.1.103 wonderland
192.168.1.104 axim
192.168.1.105 claudia
# Disable ads in Live Messenger
0.0.0.0 rad.msn.com
The first line was already in the original /etc/hosts
file. The two domains
that start with lc are local versions of two of my websites, currently hosted on cadwal,
see also: Installing and configuring Apache on Windows XP. Those local versions can now be accessed from
any other machine connected to the router, which makes it easier to check those sites in
different browsers, and with different screen sizes.