howto: replace stock dnsmasq with optware dnsmasq

Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Broadcom SoC based Hardware
Author Message
tpak
DD-WRT Novice


Joined: 30 Dec 2011
Posts: 8

PostPosted: Fri Dec 30, 2011 18:54    Post subject: howto: replace stock dnsmasq with optware dnsmasq Reply with quote
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.


How: I upgraded the E3000 to the lastest 18xxx mega series software and then installed optware following the directions from Optware The Right Way on the wiki. http://www.dd-wrt.com/wiki/index.php/Optware%2C_the_Right_Way

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):
Code:

cp /opt/etc/dnsmasq.conf /opt/etc/dnsmasq.local.conf
touch /opt/etc/dnsmasq.local.resolv
touch /opt/etc/dnsmasq.local.hosts

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*$')
Code:

domain-needed
bogus-priv
log-facility=/opt/var/log/dnsmasq
resolv-file=/opt/etc/dnsmasq.local.resolv
local=/localnet/
local=/localdomain/
local=//
local=/local.net/
no-hosts
addn-hosts=/opt/etc/dnsmasq.local.hosts
expand-hosts
domain=local.net
dhcp-range=192.168.1.100,192.168.1.199,1d
dhcp-script=/opt/bin/logger
filterwin2k
dhcp-option=66,192.168.1.50
dhcp-option=150,192.168.1.50
dhcp-lease-max=100
dhcp-leasefile=/opt/etc/dnsmasq.leases
dhcp-authoritative
cache-size=300
neg-ttl=3600
local-ttl=300
version
log-async=50
log-dhcp


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:

Code:

mv /opt/etc/init.d/S56dnsmasq /opt/etc/init.d/T56dnsmasq
cp S55portmap S56dnsmasq
ln -s /opt/etc/init.d/S56dnsmasq /opt/etc/init.d/K56dnsmasq

now edit it and change all occurrences of portmap to dnsmasq. (for the cool kids using vi :1,$s/portmap/dnsmasq/g )
Code:

#!/bin/sh
prefix=/opt
export PATH=${prefix}/bin:${prefix}/sbin:${prefix}/usr/sbin:/sbin:/bin:/usr/sbin:/usr/bin
export LD_LIBRARY_PATH=${prefix}/lib:${LD_LIBRARY_PATH}

NAME=dnsmasq
PROC=dnsmasq
BIN=${prefix}/sbin/dnsmasq
SCRIPT=${0##*/}

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

Thats's it. YMMV
Sponsor
zoomlink
DD-WRT User


Joined: 08 May 2011
Posts: 221

PostPosted: Sun Jan 01, 2012 4:28    Post subject: Reply with quote
Great post, love the clarity (and the sense of humor Smile )

Are you sure you want to link the S56dnsmasq with the K56dnsmasq?

ln -s /opt/etc/init.d/S56dnsmasq /opt/etc/init.d/K56dnsmasq

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.
tpak
DD-WRT Novice


Joined: 30 Dec 2011
Posts: 8

PostPosted: Fri Jan 06, 2012 15:24    Post subject: Reply with quote
zoomlink wrote:
Great post, love the clarity (and the sense of humor Smile )

Are you sure you want to link the S56dnsmasq with the K56dnsmasq?

ln -s /opt/etc/init.d/S56dnsmasq /opt/etc/init.d/K56dnsmasq

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.

Code:
cd /opt/etc/init.d/
mv S56dnsmasq S56dnsmasqoptware
rm K56dnsmasq
ln -s /opt/etc/init.d/S56dnsmasqoptware /opt/etc/init.d/K56dnsmasqoptware


Last edited by tpak on Fri Jan 06, 2012 19:13; edited 1 time in total
zoomlink
DD-WRT User


Joined: 08 May 2011
Posts: 221

PostPosted: Fri Jan 06, 2012 17:32    Post subject: Reply with quote
Well... I clearly showed my scripting expertise (or lack thereof) didn't I Smile

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.
tpak
DD-WRT Novice


Joined: 30 Dec 2011
Posts: 8

PostPosted: Fri Jan 06, 2012 19:14    Post subject: Reply with quote
zoomlink wrote:
Well... I clearly showed my scripting expertise (or lack thereof) didn't I Smile

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.
Smidley
DD-WRT Novice


Joined: 27 Aug 2011
Posts: 9

PostPosted: Tue Dec 04, 2012 20:23    Post subject: Reply with quote
Thank you tpak! This should be in the wiki or at least stickied.

I believe you will have saved me and many others a lot of trial and error.

Edit: And yes, I am a cool vi kid! Wink
crashfly
DD-WRT Guru


Joined: 24 Feb 2009
Posts: 2003
Location: Sol System > Earth > USA > Arkansas

PostPosted: Sat Jan 19, 2013 0:52    Post subject: Reply with quote
These steps do not appear to work with "dnsmasq v2.62-1" as I am getting an error of
Quote:
/opt/sbin/dnsmasq: can't resolve symbol '_dl_app_init_array'

when trying to run dnsmasq.

Anyone got a solution to this?

Notes: Using E3000 with 19545M KongVPN K26

_________________
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.
slobodan
DD-WRT Guru


Joined: 03 Nov 2011
Posts: 1163
Location: Zwolle

PostPosted: Sat Jan 19, 2013 19:49    Post subject: Reply with quote
crashfly wrote:
These steps do not appear to work with "dnsmasq v2.62-1" as I am getting an error of
Quote:
/opt/sbin/dnsmasq: can't resolve symbol '_dl_app_init_array'

when trying to run dnsmasq.

Anyone got a solution to this?

Notes: Using E3000 with 19545M KongVPN K26

Try sudo /opt/sbin/dnsmasq .

_________________
Asus RT-N16 running Kong 22000+ kingkong-nv32k-broadcom with OTRW2

E4200 V1 running Kong 22000+ kingkong-nv60k-broadcom with OTRW2

2 times Linksys WRT610N V2 converted to E3000 running Kong 22000+ usb-ftp-samba3-dlna-nv60k-broadcom with OTRW2 (bridged with LAN cable)


crashfly
DD-WRT Guru


Joined: 24 Feb 2009
Posts: 2003
Location: Sol System > Earth > USA > Arkansas

PostPosted: Sun Jan 20, 2013 16:36    Post subject: Reply with quote
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.
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Broadcom SoC based Hardware All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum