Posted: Fri Dec 30, 2011 18:54 Post subject: howto: replace stock dnsmasq with optware dnsmasq
Posting this because it took me a bit of digging to figure out and I did not find a tutorial or howto anywhere else. There may be better ways, if that is the case please let me know - I am still a dd-wrt newb. Hopefully it helps a few of you. It might belong on the wiki but that does not want to let me create an account so I'm posting it here for now.
Here is how I did it and why:
Why: I had a dying computer that was hosting dnsmasq for my SOHO LAN. I have a few computers, some Android devices, VOIP, DNLA, blah blah blah going and I like dnsmasq for the control it gives me over DHCP and DNS. Caching DNS helps as well. I need to retire this poor old PC and move on. I'm not sure why but the built in dnsmasq did not like the configuration options I had in my old dnsmasq.conf and I got tired of trying to figure out what the problem was and decided to just use the optware version which as of this writing is the latest and greatest and is also the same as was running on my Ubuntu computer that was dying. I also had some static addresses that I wanted to assign, etc.
Everything works fine for me at this point except dnsmasq which as I said above, doesn't like whatever I am trying to do.
Once installing optware core was complete I ran into a couple of challenges.
1. How to get the new dnsmasq installed? I'm new to optware and so wasn't real sure.
2. How to get the installed optware version of dnsmasq working?
3. How to get the default to stay shutdown?
4. How to get the optware version to run at startup.
So, I am not a newb when it comes to linux but as I said I am new to dd-wrt and optware.
The blow by blow:
To find out what packages are available (optware must be installed and working) use ipkg:
Code:
ipkg list
That is going to be a ton of crap so try this:
Code:
ipkg list|grep dnsmasq
and you should get this:
Code:
root@fsmsouth:~# ipkg list|grep dnsmasq
dnsmasq - 2.59-1 - DNS and DHCP server
OK, so now install it:
Code:
root@fsmsouth:~# ipkg install dnsmasq
Installing dnsmasq (2.59-1) to /opt/...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/ddwrt/cross/stable/dnsmasq_2.59-1_mipsel.ipk
Configuring dnsmasq
To complete the installation, you should check /opt/etc/dnsmasq.conf,
and then run /opt/etc/init.d/S56dnsmasq to start dnsmasq.
Now we have it installed but the default dnsmasq supplied with dd-wrt is still running. To complete the next few step it would be helpful if you were using a wired ethernet connection to the router and using a static IP address in case something goes wrong. Something like dnsmasq or the built in dhcp not giving out addresses on the network while you are messing with the router. Just saying you might want to stop right here and assign yourself a fixed IP for a few minutes.
So now that we are using a wire and have a fixed IP (you were paying attention right?), we will proceed.
Go to Setup->Network Address Server Settings (DHCP)
Disable DHCP Server and all DNSMasq options here
Save (down at the bottom of the page)
Go to Services->DNSMasq and disable dnsmasq
Save
Apply Settings
Wait for the router to let you back in (right about now you are wishing you had a static IP address since DHCP is now completely off and dns is shutdown and if you don't have a static ip you are bummed out and I am the honeybadger )
We need a working dnsmasq config and we want it to survive subsequent dnsmasq upgrades etc. The default conf file for the optware version is /opt/etc/dnsmasq.conf so, ssh to the router (or telnet if that is your thing):
and now lets edit the default file with vi (you are a cool kid eh? or do you use some other editor?)
Code:
vi /opt/etc/dnsmasq.conf
go to the last line of the file and add this (or be a wild child and put it as the first line, it doesn't matter, the whole of the default file is commented out)
Code:
conf-file=/opt/etc/dnsmasq.local.conf
":wq" i.e. save and exit
Now edit /opt/etc/dnsmasq.local.conf and configure it however you want. Most of my version is below, all comment lines are stripped out for your enjoyment (grep -ve "^\#" dnsmasq.local.conf |grep -v '^\W*$')
Yes, I know, /opt/etc/dnsmasq.leases is not really the places to be writing things to but I like having all my dnsmasq stuff in one place - I'm lazy that way.
contents of /opt/etc/dnsmasq.local.hosts - this can be used to replace /etc/hosts when using dnsmasq - but read the man pages for details
Code:
192.168.1.50 copper
contents of /opt/etc/dnsmasq.local.resolv
Code:
# these are the dns servers at opendns.com - put whatever name servers you want here
nameserver 208.67.222.222
nameserver 208.67.222.220
Now we need a service to run. ipkg will have installed a startup script in /opt/etc/init.d called S56dnsmasq but it will not run on my Csico E3000 - it pukes out some errors and doesn't list correctly as a service, have proper start, stop, and status options so I backed up the original, copied the init script from portmap and changed it to run dnsmasq - it could probably be cleaned up even more but this one works for me, we'll also create a link to a shutdown script while we are at it:
if [ -z "$1" ] ; then
case `echo "$0" | sed 's:^.*/\(.*\):\1:g'` in
S??*) rc="start" ;;
K??*) rc="stop" ;;
*) rc="usage" ;;
esac
else
rc="$1"
fi
# Start/Stop/Status dnsmasq
case "$rc" in
status)
if pidof ${PROC} >/dev/null ; then
echo "${NAME} is running"
else
echo "${NAME} is not running"
fi
;;
start)
if pidof ${PROC} >/dev/null ; then
echo "${NAME} already running"
else
optlog "${SCRIPT}" "Starting ${NAME}:"
${BIN}
fi
;;
stop)
if ! pidof ${PROC} >/dev/null ; then
echo "${NAME} is already stopped"
else
optlog "${SCRIPT}" "Stopping ${NAME}:"
n=1
while [ $n -lt 20 ] ; do
killall ${PROC} >/dev/null 2>&1
pidof ${PROC} >/dev/null || break
sleep 1
let n+=1
done
killall -9 ${PROC} >/dev/null 2>&1
fi
;;
restart)
"$0" stop
sleep 1
"$0" start
;;
*)
echo "Usage: $0 (start|stop|restart|status|usage)"
;;
esac
exit 0
make it executable set it to on and start it, check that it is actually running:
Code:
chmod 755 /opt/etc/init.d/S56dnsmasq
service dnsmasq on
service dnsmasq start
service dnsmasq
ps aux|grep dnsmasq
reboot the router and make sure that dnsmasq comes back - if you set up log-facility and version options in the config you should see messages from dnsmasq in the logs
Looks like you are linking the start script with the kill script.
I would have thought you wanted to disable the stock DNSMasq on the Router's webgui (SERVICES tab) and let the S56dnsmasq optware script start when the Optware scripts get called.
Looks like you are linking the start script with the kill script.
I would have thought you wanted to disable the stock DNSMasq on the Router's webgui (SERVICES tab) and let the S56dnsmasq optware script start when the Optware scripts get called.
Maybe I missed something.
@ zoomlink glad you enjoyed it
Sorry for the delayed response - just wandered back to the forum.
In order to successfully get the stock dnsmasq to stay disabled I had to disable it in the two places that I mentioned.
The link to the kill script is a common technique for scripts that support start and stop as a parameter. The S series scripts in init.d get called in alpha numberical order during startup and the K ones during shutdown. So I am cleanly shutting down dnsmasq. However, re-reading your comment did give me pause to go and move my modified S56dnsmasq scripts so that they don't get clobbered during future optware upgrades.
Well... I clearly showed my scripting expertise (or lack thereof) didn't I
You seem to have a good command of scripting techniques. I on the other hand, am just reading and trying to teach myself.
Thanks for the response... I will give your guide a test drive and see how it goes.
No problem - my explanation is a bit crude - do a little googling for "understanding init.d". It is a little more complex in most cases but still good stuff to know.
Joined: 24 Feb 2009 Posts: 2026 Location: Sol System > Earth > USA > Arkansas
Posted: Sun Jan 20, 2013 16:36 Post subject:
slobodan wrote:
Try sudo /opt/sbin/dnsmasq .
That is actually not even related to the problem.
If dnsmasq has what it considers "errors" in its configuration file, it dies and gives the above error. This is not limited to the problem of running as root. Therefore one must put the "user=root" option in the configuration file to properly work under DD-WRT.
So many quirks with DD-WRT. So little information. _________________ E3000 22200M KongVPN K26
WRT600n v1.1 refirb mega 18767 BS K24 NEWD2 [not used]
WRT54G v2 16214 BS K24 [access point]
Try Dropbox for syncing files - get 2.5gb online for free by signing up.
Read! Peacock thread
*PLEASE* upgrade PAST v24SP1 or no support.