{"id":587,"date":"2011-12-31T08:19:00","date_gmt":"2011-12-31T08:19:00","guid":{"rendered":"http:\/\/zensonic.dk\/?p=587"},"modified":"2017-04-09T10:03:05","modified_gmt":"2017-04-09T10:03:05","slug":"using-the-e3000-as-a-caching-dns-server-on-dd-wrt","status":"publish","type":"post","link":"https:\/\/zensonic.dk\/?p=587","title":{"rendered":"Using the E3000 as a caching DNS server (on dd-wrt)"},"content":{"rendered":"<p>Due to <a href=\"https:\/\/zensonic.dk\/?p=564&amp;cpage=1#comment-36684\">popular demand<\/a> I&#8217;ll post this on how to use the E3000 as a generic DNS server. I&#8217;t will be very brief, you have to fill in the blanks yourself.<\/p>\n<p>First you have to get the support tools in place for this. dd-wrt is build for smallish setups as well, so some of the tools are quite limited to say the least. There are basically two routes:<\/p>\n<ul>\n<li>Fiddle with the internal flash so that you can use the built-in ipkg on a jffs2 mounted flashdrive<\/li>\n<li>Mount an USB stick, download ipkg-opt and work from there<\/li>\n<\/ul>\n<p>I choose the latter. Primarily due to the fact that, that option gave me 4GB of space in \/opt. It is actually quite simple<\/p>\n<div id=\"attachment_590\" class=\"wp-caption aligncenter\" style=\"width: 160px\"><a href=\"https:\/\/zensonic.dk\/wp-content\/uploads\/Screenshot1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-thumbnail wp-image-590 \" title=\"dd-wrt usb flash\" src=\"https:\/\/zensonic.dk\/wp-content\/uploads\/Screenshot1-150x150.png\" alt=\"dd-wrt usb flash\" width=\"150\" height=\"150\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">dd-wrt usb flash<\/p>\n<\/div>\n<p>You then install ipkg-opt and companion tools (uclib-opt). You can use <a href=\"http:\/\/www.dd-wrt.com\/wiki\/index.php\/Optware\">this wiki post <\/a>on the dd-wrt wiki.<\/p>\n<p>After that you can install all your extensions through ipkg-opt (or download them by hand). For my DNS resolver needs I choose the wonderful dnsmasq software. It acts as DNS\/DHCP and TFTP software. From my router<\/p>\n<div class=\"codesnip-container\" >root@dd-wrt:\/opt\/sbin# ipkg-opt list | grep -i dnsmasq<br \/>\ndnsmasq &#8211; 2.58-1 &#8211; DNS and DHCP server<\/div>\n<p>The observant reader noticed that dd-wrt calls \/opt\/etc\/config\/startup in the screenshot abov (after having mounted \/opt). This script is the startup script of all your \/opt related stuff. I went with something like<\/p>\n<div class=\"codesnip-container\" >#!\/bin\/sh<\/p>\n<p>unset LD_LIBRARY_PATH<br \/>\nunset LD_PRELOAD<\/p>\n<p>[ -e \/opt\/etc\/profile ] &amp;&amp; mount -o bind \/opt\/etc\/profile \/etc\/profile<\/p>\n<p>grep nobody \/etc\/passwd &gt; \/dev\/null<br \/>\nif [ $? -ne 0 ]; then<br \/>\necho &#8220;nobody:*:65534:65534:nobody:\/var:\/bin\/false&#8221; &gt;&gt; \/etc\/passwd<br \/>\nfi<\/p>\n<p>if [ -d \/opt\/etc\/init.d ]; then<br \/>\nfor f in \/opt\/etc\/init.d\/S* ; do<br \/>\n[ -x $f ] &amp;&amp; $f start<br \/>\ndone<br \/>\nfi<\/p>\n<\/div>\n<p>and have a<\/p>\n<div class=\"codesnip-container\" >root@dd-wrt:\/opt\/sbin# ls -al \/opt\/etc\/init.d\/S56dnsmasq<br \/>\n-rwxr-xr-x\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 1 root\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 root\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 215 Jan\u00c2\u00a0 1\u00c2\u00a0 1970 \/opt\/etc\/init.d\/S56dnsmasq<br \/>\nroot@dd-wrt:\/opt\/sbin# cat \/opt\/etc\/init.d\/S56dnsmasq<br \/>\n#!\/bin\/sh<\/p>\n<p>unset LD_LIBRARY_PATH<br \/>\nunset LD_PRELOAD<\/p>\n<p>if [ -f \/var\/run\/dnsmasq.pid ] ; then<br \/>\nkill `cat \/var\/run\/dnsmasq.pid`<br \/>\nfi<\/p>\n<p>rm -f \/var\/run\/dnsmasq.pid<\/p>\n<p>sleep 2<br \/>\n\/opt\/sbin\/dnsmasq &#8211;conf-file=\/opt\/etc\/dnsmasq.conf<\/p>\n<\/div>\n<p>Finally we are getting there. Before showing the dnsmasq.conf file, I will show a screenshot of the setup on the dd-wrt gui in order to use dnsmasq as DNS and DHCP server:<\/p>\n<div id=\"attachment_591\" class=\"wp-caption aligncenter\" style=\"width: 160px\"><a href=\"https:\/\/zensonic.dk\/wp-content\/uploads\/Screenshot-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-thumbnail wp-image-591\" title=\"dnsmasq setup in dd-wrt\" src=\"https:\/\/zensonic.dk\/wp-content\/uploads\/Screenshot-1-150x150.png\" alt=\"dnsmasq setup in dd-wrt\" width=\"150\" height=\"150\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">dnsmasq setup in dd-wrt<\/p>\n<\/div>\n<p>Notice how the built-in dhcp server is disabled and how I have choosen to use dnsmasq. Now onto the configuration of dnsmasq.conf:<\/p>\n<div class=\"codesnip-container\" >root@dd-wrt:\/opt\/sbin# grep -v &#8220;^#&#8221;\u00c2\u00a0 \/opt\/etc\/dnsmasq.conf\u00c2\u00a0 | grep -v &#8220;^$&#8221;<br \/>\ntftp-no-blocksize<br \/>\nlog-dhcp<br \/>\ninterface=br0<br \/>\nresolv-file=\/tmp\/resolv.conf<br \/>\ndomain=zensonic.dk<br \/>\ndhcp-leasefile=\/tmp\/dnsmasq.leases<br \/>\ndhcp-lease-max=50<br \/>\ndhcp-authoritative<br \/>\ndhcp-range=lan,192.168.1.100,192.168.1.143,255.255.255.0,1440m<br \/>\nstop-dns-rebind<br \/>\ndhcp-host=00:22:FB:BB:C8:E0,kitchen,192.168.1.116,infinite<br \/>\ndhcp-host=00:18:71:E3:22:4d,dl145-1,192.168.1.117,infinite<br \/>\ndhcp-host=00:14:38:bf:a9:16,dl380g4i,192.168.1.119,infinite<br \/>\ndhcp-host=00:14:38:bf:a9:19,dl380g4,192.168.1.121,infinite<br \/>\nenable-tftp<br \/>\ntftp-root=\/opt\/var\/tftproot<br \/>\ndhcp-boot=pxelinux.0<\/div>\n<p>You will immediately notice a couple of things. Notice how I have the range setup for dhcp leases. Notice also how I have static leases. And finally notice how I have tftp enabled. Another blogpost on tftp another time (quite nifty for setting up servers on my vmware backend in minutes using kickstart, yast2 and solaris jumpstart).<\/p>\n<p>You might think: where are the zone records? The answer can be found from the man page for dnsmasq<\/p>\n<blockquote>\n<p>Dnsmasq accepts DNS queries and either answers them from a small, local, cache or forwards them to a real, recursive, DNS server. <strong>It loads the contents of \/etc\/hosts so that local hostnames which do not appear in the global DNS can be resolved and also answers DNS queries for DHCP configured hosts<\/strong>.<\/p>\n<\/blockquote>\n<p>So I simply add my infrastructure to \/etc\/hosts and run \/opt\/etc\/init.d\/S56dnsmasq.<\/p>\n<p>I only had the need for running DNS locally, so my choice was dnsmasq. You can also install a full fledged bind if you have that desire<\/p>\n<div class=\"codesnip-container\" >root@dd-wrt:\/opt\/sbin# ipkg-opt list bind<br \/>\nbind &#8211; 9.6.1.3-4 &#8211; Bind provides a full name server package, including zone masters, slaves, zone transfers, security multiple views.\u00c2\u00a0 This is THE<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Due to popular demand I&#8217;ll post this on how to use the E3000 as a generic DNS server. I&#8217;t will be very brief, you have to fill in the blanks yourself. First you have to get the support tools in place for this. dd-wrt is build for smallish setups as well, so some of the [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,19,22,6],"tags":[],"class_list":["post-587","post","type-post","status-publish","format-standard","hentry","category-fun-projects","category-linux-lvm","category-power-hardware","category-unix"],"_links":{"self":[{"href":"https:\/\/zensonic.dk\/index.php?rest_route=\/wp\/v2\/posts\/587"}],"collection":[{"href":"https:\/\/zensonic.dk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zensonic.dk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zensonic.dk\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/zensonic.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=587"}],"version-history":[{"count":0,"href":"https:\/\/zensonic.dk\/index.php?rest_route=\/wp\/v2\/posts\/587\/revisions"}],"wp:attachment":[{"href":"https:\/\/zensonic.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=587"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zensonic.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=587"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zensonic.dk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=587"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}