<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>OpenBSD and FreeBSD resources &#187; DJBDNS</title>
	<atom:link href="http://purebsd.com/tag/djbdns/feed" rel="self" type="application/rss+xml" />
	<link>http://purebsd.com</link>
	<description></description>
	<lastBuildDate>Tue, 01 Jun 2010 06:01:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Setting up DJBDNS</title>
		<link>http://purebsd.com/setting-up-djbdns.html</link>
		<comments>http://purebsd.com/setting-up-djbdns.html#comments</comments>
		<pubDate>Tue, 01 Jun 2010 04:59:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Daemons]]></category>
		<category><![CDATA[OpenBSD]]></category>
		<category><![CDATA[DJBDNS]]></category>
		<category><![CDATA[Setting up]]></category>

		<guid isPermaLink="false">http://purebsd.com/?p=33</guid>
		<description><![CDATA[Didactic assumptions You want to run a secure DNS service on your system(s). (BIND is not secure, nor reliable.) Read DJBDNS&#8217;s security guarantee. You have three network interfaces: 127.0.0.1 &#8211; the IP address of the localhost/loopback interface. 192.168.0.3 &#8211; the IP address of the internal network interface. 131.174.117.141 &#8211; the IP address of the external network [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Didactic assumptions</strong></p>
<ul>
<li>You want to run a secure DNS service on your system(s). (BIND is not secure, nor reliable.) Read DJBDNS&#8217;s <a href="http://cr.yp.to/djbdns/guarantee.html">security guarantee</a>.</li>
<li>You have three network interfaces:<br />
127.0.0.1 &#8211; the IP address of the localhost/loopback interface.<br />
192.168.0.3 &#8211; the IP address of the internal network interface.<br />
131.174.117.141 &#8211; the IP address of the external network interface.</p>
<p>I assume that 127.0.0.1 needs no clarification. 192.168.0.3 is the IP with which the server babbles with the rest of the machines on your intranet. 131.174.117.141 is the IP address that your ISP provided to you in order to TCP/IP you into the scary dungeons of the internet.</li>
<li>Your intranet domain name is &laquo;intranet.purebsd.com&raquo; and your domain name is &laquo;purebsd.com&raquo;.</li>
<li>The secondary name server is setup the same way like our server.</li>
<li>You like to install machine dependend things into <code>/usr/local</code> and stuff that can grow into <code>/var</code>.</li>
</ul>
<p><strong>Goal</strong></p>
<p>We are going to create a split-horizon DNS service:</p>
<ul>
<li>The intranet machines will contact your server for resolving DNS queries.</li>
<li>The intranet machines will contact your server to query the private intranet domain &laquo;intranet.purebsd.com&raquo;.</li>
<li>The intranet machines will contact your server to query the public internet domain &laquo;purebsd.com&raquo;.</li>
<li>The server itself will be able to do all of the above.</li>
<li>The server will transfer its primary zones to its secondary nameserver by means of the dnszxfr &laquo;program&raquo;.</li>
<li>The server will receive its secondary zones from its primary nameserver by means of the dnszxfr &laquo;program&raquo;.</li>
<li>The machines on the internet will only be able to query the public internet domain &laquo;purebsd.com&raquo;.</li>
</ul>
<p><strong>Roadmap to the DJBDNS solution</strong></p>
<p>This page documents one possible roadmap to install, configure and use DJBDNS.</p>
<p><em>Getting the software</em></p>
<p>For DJBDNS you need to download three tarballs:</p>
<ol type="1">
<li>The latest djbdns package: <a href="http://cr.yp.to/djbdns/djbdns-1.05.tar.gz">djbdns-1.05.tar.gz</a><br />
DJBDNS, obviously.</li>
<li>The latest daemontools package: <a href="http://cr.yp.to/daemontools/daemontools-0.76.tar.gz">daemontools-0.76.tar.gz</a><br />
Daemontools is a collection of tools for managing UNIX services. DJBDNS makes use of it.</li>
<li>The latest ucspi-tcp package: <a href="http://cr.yp.to/ucspi-tcp/ucspi-tcp-0.88.tar.gz">ucspi-tcp-0.88.tar.gz</a><br />
Ucspi-tcp is a collection of tools to create and accept TCP connections.</li>
</ol>
<p><em>Installing the framework</em></p>
<p>To install these three packages:</p>
<ol type="1">
<li>First, create a <code>package</code> directory in <code>/usr/local</code>:<br />
<code>mkdir -p /usr/local/package<br />
chmod 1755 /usr/local/package<br />
ln -s /usr/local/package /package<br />
cd /package<br />
</code><br />
Extract the daemontools sources in <code>/package</code>:<br />
<code>tar xpfz daemontools-0.76.tar.gz<br />
cd admin/daemontools-0.76<br />
</code><br />
To compile and setup daemontools:<br />
<code>package/install<br />
</code><br />
The directories <code>/command</code> and <code>/service</code> are created by the installation script.<code>/command</code> is populated by symbolic links to programs located in <code>/package</code> or<code>/usr/local/package</code>. Symbolic links located in <code>/service</code> are used by <code>svscan</code> to start (daemontools compatible) services under supervision of <code>supervise</code>. DJBDNS, daemontools and ucspi-tcp need those directories by default. If you don&#8217;t like them and want to change the names or locations of those directories, make sure you know exactly what you&#8217;re doing when hacking the Makefiles and source code.</p>
<p>Note: <code>/command/svscanboot</code> is automatically added to <code>/etc/rc.local</code></li>
<li>Extract the ucspi-tcp sources somewhere:<br />
<code>tar xvfz ucspi-tcp-0.88.tar<br />
cd ucspi-tcp-0.88<br />
</code><br />
To compile and install ucspi-tcp:<br />
<code>make<br />
make setup check<br />
</code></li>
<li>Extract the djbdns sources somewhere:<br />
<code>tar xvfz djbdns-1.05.tar<br />
cd djbdns-1.05<br />
</code><br />
To compile and install djbdns:<br />
<code>make<br />
make setup check<br />
</code></li>
</ol>
<p>Edit the <code>/etc/dnsroots.global</code> file to reflect the new IP address of j.root-servers.net:</p>
<ul>
<li>Replace <code>198.41.0.10</code> with <code>192.58.128.30</code>.</li>
</ul>
<p>Now setup some nice system accounts for DJBDNS:</p>
<ol type="1">
<li>Add &laquo;dnscache&raquo;, &laquo;dnslog&raquo;, &laquo;tinydns&raquo; and &laquo;dnszxfr&raquo; as new accounts to the system by adding the following <strong>four</strong> lines to <code>/etc/master.passwd</code>:
<p><code> dnscache:*:90:90::0:0:dnscache:/nonexistent:/sbin/nologin<br />
dnslog:*:91:91::0:0:dnslog:/nonexistent:/sbin/nologin<br />
tinydns:*:92:92::0:0:tinydns:/nonexistent:/sbin/nologin<br />
dnszxfr:*:93:93::0:0:DNS zone transfer agent:/var/djbdns/public-dnszxfr:/bin/sh<br />
</code><br />
<strong>Note:</strong> make sure that each account entry is just one line. Do not spread over multiple lines or you will corrupt the file.</p>
<p>Then run <code>pwd_mkdb -p /etc/master.passwd</code> to activate the changes.</li>
<li>Add four new groups to <code>/etc/group</code>:<br />
<code>dnscache:*:90:<br />
dnslog:*:91:<br />
tinydns:*:92:<br />
dnszxfr:*:93:<br />
</code></li>
<li>Change dnszxfr&#8217;s password with a string of about 10 random characters found on your keyboard:<br />
<code>passwd dnszxfr</code></li>
</ol>
<p>Now we can create the data directories of the various DJBDNS programs:</p>
<ol type="1">
<li>First, create a directory where DJBDNS data directories will reside:<br />
<code>mkdir /var/djbdns</code></li>
<li>Create a caching DNS service:<br />
<code>dnscache-conf dnscache dnslog \<br />
/var/djbdns/private-dnscache 192.168.0.3</code></li>
<li>Create an authorative DNS service for the intranet:<br />
<code>tinydns-conf tinydns dnslog \<br />
/var/djbdns/private-tinydns 127.0.0.1</code></li>
<li>Create an authorative DNS service for the internet:<br />
<code>tinydns-conf tinydns dnslog \<br />
/var/djbdns/public-tinydns 131.174.117.141</code></li>
<li>Create a directory for the zone transfer dnszxfr:<br />
<code>mkdir /var/djbdns/public-dnszxfr<br />
chown dnszxfr:dnszxfr /var/djbdns/public-dnszxfr<br />
chmod 700 /var/djbdns/public-dnszxfr<br />
</code></li>
</ol>
<p><em>Getting ready</em></p>
<p>The data directories are created and already filled with some files that form the framework. We have to finetune some of these files or create some new files in order to let things run smoothly on our server.</p>
<ol type="1">
<li>Edit <code>/var/djbdns/private-tinydns/run</code> to increase the softlimit:<br />
<code>... vdir ./env softlimit -d500000 /usr/loc ...<br />
</code></li>
<li>Edit <code>/var/djbdns/public-tinydns/run</code> to increase the softlimit:<br />
<code>... vdir ./env softlimit -d500000 /usr/loc ...<br />
</code></li>
<li>To enable the intranet to use dnscache&#8217;s services:<br />
<code>cd /var/djbdns/private-dnscache/root/ip<br />
touch 192.168.0<br />
chmod 600 192.168.0<br />
</code></li>
<li>In order to have <code>dnscache</code> resolve 192.168.0.* and *.intranet.purebsd.com, it has to know where to look:<br />
<code>cd /var/djbdns/private-dnscache/root/servers<br />
echo 127.0.0.1 &gt; 0.168.192.in-addr.arpa<br />
echo 127.0.0.1 &gt; intranet.purebsd.com<br />
</code><br />
127.0.0.1 is the IP address that <code>private-tinydns</code>, which knows about 129.168.0.* and *.intranet.purebsd.com, listens on.</li>
<li>Edit <code>/var/djbdns/private-tinydns/root/Makefile</code> to read:<br />
<code>data.cdb: data<br />
/usr/local/bin/tinydns-data</p>
<p>data: private-zones-primary<br />
cat private-zones-primary &gt; data<br />
</code></li>
<li>Edit <code>/var/djbdns/public-tinydns/root/Makefile</code> to read:<br />
<code>data.cdb: data<br />
@echo -n "[3] Creating 'data.cdb' from 'data'.. "<br />
@/usr/local/bin/tinydns-data<br />
@echo "OK"</p>
<p>data: public-zones-primary public-zones-secondary<br />
@echo -n "[1] Creating 'data' from 'public-zones-primary' \<br />
and 'public-zones-secondary'.. "<br />
@cat public-zones-primary public-zones-secondary &gt; data<br />
@echo "OK"</p>
<p>@echo -n "[2] Copying primary zone to DNSZXFR transfer \<br />
directory.. "<br />
@/bin/cp -f public-zones-primary /var/djbdns/public-dnszxfr/<br />
@echo "OK"<br />
</code><br />
<strong>Note:</strong>All indented lines should be indented with tabs instead of spaces. Make will complain if you fail to meet this requirement.</li>
</ol>
<p><em>Prime time</em></p>
<p>Now we are ready to run the DJBDNS services:</p>
<ol type="1">
<li>Go to the <code>/service</code> directory:<br />
<code>cd /service</code></li>
<li>Make symbolic links to <code>public-tinydns</code>, <code>private-tinydns</code> and <code>private-dnscache</code>:<br />
<code>ln -s /var/djbdns/private-dnscache .<br />
ln -s /var/djbdns/private-tinydns .<br />
ln -s /var/djbdns/public-tinydns .<br />
</code></li>
<li>The services should be started automatically within seconds. To verify: <code>svstat /service/*</code><br />
The output will be something similar to:<br />
<code>/service/private-dnscache: up (pid 17170) 686536 seconds<br />
/service/private-tinydns: up (pid 15258) 686536 seconds<br />
/service/public-tinydns: up (pid 22261) 686536 seconds<br />
</code></li>
<li>You should let your system&#8217;s DNS resolver(s) know what IP address should be used to submit DNS queries to. Create/edit <code>/etc/resolv.conf</code> to have it use <code>dnscache</code>&#8216;s IP address:<br />
<code>nameserver 192.168.0.3</code></li>
</ol>
<p><em>Serving DNS records</em></p>
<p>The <code>dnscache</code> program is already providing resolving DNS services to your system and intranet. But nothing is known about *.intranet.purebsd.com (the intranet domain) nor *.purebsd.com (the public internet domain).<br />
First, we&#8217;re going to inform private-tinydns (the tinydns instance that knows about *.intranet.purebsd.com) what it should know about the intranet.</p>
<ol type="1">
<li>The tinydns data format is very simple (and easy to parse for programs). Make yourself acquaintable with the <a href="http://cr.yp.to/djbdns/tinydns-data.html">tinydns data format</a>.</li>
<li>Now that you know all about the tinydns data format, go to the <code>private-tinydns</code>directory to which tinydns chroot()&#8217;s:<br />
<code>cd /var/djbdns/private-tinydns/root</code></li>
<li>There you create the file <code>private-zones-primary</code>. It could look like this:<br />
<code># Zone: *.intranet.purebsd.com<br />
#<br />
.intranet.purebsd.com::atlantis.intranet.purebsd.com<br />
@intranet.purebsd.com::atlantis.intranet.purebsd.com:10<br />
'purebsd.com:PureBSD intranet<br />
=antarctica.intranet.purebsd.com:192.168.0.1<br />
=aldebaran.intranet.purebsd.com:192.168.0.2<br />
=atlantis.intranet.purebsd.com:192.168.0.3<br />
</code></li>
<li>To have <code>tinydns</code> load the new private (primary) zone file just run <code>make</code>. <code>make</code> processes the <code>Makefile</code> file. That copies <code>private-zones-primary</code> to <code>data</code> and calls<code>tinydns-data</code> to generate <code>data.cdb</code> out of <code>data</code>.
<p>The usage of <code>private-zones-primary</code> looks a bit clumsy or overdone, but I found it to be more consistent with the public-tinydns approach I took.</li>
</ol>
<p>Now we&#8217;re going to have public-tinydns publish our beloved purebsd.com domain.</p>
<ol type="1">
<li>Go to the <code>public-tinydns</code> directory to which tinydns chroot()&#8217;s:<br />
<code>cd /var/djbdns/public-tinydns/root</code></li>
<li>There you create the file <code>public-zones-primary</code>. It could look like this:<br />
<code># Zone: *.purebsd.com<br />
#<br />
.purebsd.com::ns1.purebsd.com<br />
.purebsd.com::ns2.purebsd.com<br />
@purebsd.com::mail1.purebsd.com:10<br />
@purebsd.com::mail2.purebsd.com:20<br />
'purebsd.com:PureBSD - BSD resources<br />
+ns1.purebsd.com:131.174.117.141<br />
+ns2.purebsd.com:131.174.119.121<br />
+mail1.purebsd.com:131.174.117.141<br />
+mail2.purebsd.com:131.174.119.121<br />
+www.purebsd.com:131.174.117.141<br />
</code></li>
<li>To have <code>tinydns</code> load the new public (primary) zone file just run <code>make</code>. <code>make</code> processes the <code>Makefile</code> file. That copies <code>public-zones-primary</code> and <code>public-zones-secondary</code> to <code>data</code> and calls <code>tinydns-data</code> to generate <code>data.cdb</code> out of <code>data</code>.
<p>Make also copies the file <code>public-zones-primary</code> to the DNSXFR directory so that DNSXFR can transfer it to the secondary nameserver(s).</li>
</ol>
<p><em>Zone transfers</em></p>
<p>The setup and configuration of the The DNS zone transfer program &laquo;dnszxfr&raquo; will be coverend when the rest of the DJBDNS setup is completed (and documented here <img src='http://purebsd.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</p>
<p><strong>More reading</strong></p>
<p>For more in-depth documentation for the DJBDNS, daemontools and ucspi-tcp programs:</p>
<ul>
<li>DJBDNS:<br />
- <a href="http://cr.yp.to/djbdns.html">Official DJBDNS site</a></li>
<li>Daemontools:<br />
- <a href="http://cr.yp.to/daemontools.html">Official daemontools site</a></li>
<li>Ucspi-tcp:<br />
- <a href="http://cr.yp.to/ucspi-tcp.html">Official ucspi-tcp site</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://purebsd.com/setting-up-djbdns.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

