dnsmasq, OpenWrt and my Netgear WNDR3700

So: I just acquired a NetGear WNDR3700 and I've been playing around with it.
One of the main reasons for purchasing this routing powerhorse, was to be a "drop-in" replacement for a lot of services that I'd since crammed into my trusty old ReadyNAS NV.

The prime example was dnsmasq. I had installed the dnsmasq add-on (courtesy of readynasfreeware.com) on my ReadyNAS because every DNS/DHCP service available on my network appliances (my Comcast DOCSIS 3.0 cable modem and my multiple wireless routers) are basically rubbish. With dnsmasq, I can easily edit the dhcp reservations, configure DNS in a simple, easy to manage way, and basically really make things  things my way

I had thought about going fullscale BIND, but my needs are not that complex, and dnsmasq is really lightweight so as to not tax my ReadyNAS, which should really not have to carry extra load.

dnsmasq even comes with a TFTP and PXE server, which I put to use to set up recovery images for my now growing home IT environment.

The disadvantage of this setup was that if my ReadyNAS was dormant (disks spun-down), we'd have to wait for the disks to spin up just for the ReadyNAS to issue or renew a dhcp lease. It also meant I had to keep the ReadyNAS powered on all the time.

My new WNDR3700 running OpenWrt is just a way better upgrade for this configuration :)

The trick was to migrate the service. There was a lot of tricky re-IP'ing and network cable swapping, but the juicy bit was migrating the dnsmasq config files that were already loaded with a lot of MAC/IP/hostname/domain data and other tweaks...

The file locations in the ReadyNAS dnsmasq files were different too: they referred to a /opt/rfw/etc/dnsmasq.d/ and /var/lib/misc/dnsmasq.leases locations.

I realized then that I wanted to keep the files 100% compatible (or close enough)in case I ever needed to switch back to the ReadyNAS.

Here's how I did this:


ssh root@router

# conf files
mkdir -p /opt/rfw/etc/dnsmasq.d
scp root@nas:/opt/rfw/etc/dnsmasq.d/* /opt/rfw/etc/dnsmasq.d/
scp root@nas:/opt/rfw/etc/dnsmasq.conf /etc/
ln -s /opt/rfw/etc/dnsmasq.d /etc/

# leases file
mkdir -p /var/lib/misc/
ln -s /var/lib/misc/dnsmasq.leases /tmp/dhcp.leases

# back up init script, just in case
mv /etc/init.d/dnsmasq ~/dnsmasq.original #backup, just in case

# write init script (OpenWrt uses config commands, which would defeat the point here)
cat <<EOF >/etc/init.d/dnsmasq
#!/bin/sh /etc/rc.common
# Copyright (C) 2007 OpenWrt.org
# Adapted 2011/06/11 jorgeATzaptusDOTcom

start() {
echo "Starting dnsmasq..."
/usr/sbin/dnsmasq
}

stop() {
echo "Stopping dnsmasq..."
[ -f /tmp/resolv.conf ] && {
rm -f /tmp/resolv.conf
ln -s /tmp/resolv.conf.auto /tmp/resolv.conf
}
pkill -f /usr/sbin/dnsmasq
}

restart() {
stop
start
}
EOF

# (re)start dnsmasq [make sure you stop it on your previous service so you don't have competing DHCP servers)
/etc/init.d/dnsmasq restart

For follow-up I just had to make sure that DNS servers were configured correctly as DHCP option and anywhere they were manually defined (such as the router NICs).

Perhaps, I have forgotten a step or two in the middle of all this, but this was the gist of it. I hope this is helpful to anyone who happens to go through the same.

Comments

Popular posts from this blog

Gargoyle on OpenWrt BackFire 10.03

WebGL Camp #3