<?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>Doug Jaworski &#187; Linux</title>
	<atom:link href="http://www.dougjaworski.com/blog/tag/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dougjaworski.com/blog</link>
	<description></description>
	<lastBuildDate>Sun, 25 Jul 2010 17:03:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Install Bind 9 DNS Server (CHROOT) &#8211; Debian Etch and Ubuntu</title>
		<link>http://www.dougjaworski.com/blog/install-bind-9-dns-server-chroot-debian-etch-and-ubuntu/</link>
		<comments>http://www.dougjaworski.com/blog/install-bind-9-dns-server-chroot-debian-etch-and-ubuntu/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 23:15:10 +0000</pubDate>
		<dc:creator>Doug</dc:creator>
				<category><![CDATA[HowTo]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.dougjaworski.com/blog/?p=50</guid>
		<description><![CDATA[BIND (Berkley Internet Name Domain) is the most common of all DNS servers and generally a standard on most Linux and UNIX distributions. For a more detailed look at Bind and its technical history take a look at the Wikipedia article on Bind. CHROOT is commonly referred to as JAIL and is often used to [...]]]></description>
			<content:encoded><![CDATA[<p><strong>BIND</strong> (Berkley Internet Name Domain) is the most common of all DNS servers and generally a standard on most Linux and UNIX distributions.</p>
<p>For a more detailed look at Bind and its technical history take a look at the Wikipedia article on <a href="http://en.wikipedia.org/wiki/BIND" target="_blank">Bind</a>.</p>
<p><strong>CHROOT</strong> is commonly referred to as JAIL and is often used to change the root of an application to another location for the reasons of security. Often times CHROOT is used for services that run under root user and can be insecure so it is a way of protecting the root operating system in the event of an application compromise.</p>
<p>In this HowTo, we will be installing BIND9 and CHROOTing bind to live in an restricted portion of the Linux file system. For the purposes of this HowTo we will be using a running installation of Debian Etch.</p>
<p><strong>Assumptions</strong></p>
<p>1. Bind will be configured as an authoritative DNS master resolving for specific domain names</p>
<p>2. You have limited knowledge of Linux editors such as <a href="http://en.wikipedia.org/wiki/Vi" target="_blank">vi</a></p>
<p>3. Utilization of Sudo. If you do not use <a href="http://en.wikipedia.org/wiki/Sudo" target="_blank">sudo</a>, simply eliminate <em>sudo</em> from any commands however you will need to be logged in as a root user</p>
<p><strong>Install Bind 9</strong></p>
<blockquote><p>sudo apt-get install bind9</p></blockquote>
<p><strong>CHROOT Bind 9</strong></p>
<blockquote><p>sudo /etc/init.d/bind9 stop</p></blockquote>
<p>Edit <em>/etc/default/bind9</em> and configure bind to run as an unprivileged user and chrooted to <em>/var/lib/named</em> as follows:</p>
<blockquote><p>OPTIONS=&#8221;-u bind -t /var/lib/named&#8221;</p>
<p># Set RESOLVCONF=no to not run resolvconf</p>
<p>RESOLVCONF=yes</p></blockquote>
<p>Create the necessary directories <em>/var/lib</em></p>
<blockquote><p>sudo mkdir -p /var/lib/named/etc</p>
<p>sudo mkdir /var/lib/named/dev</p>
<p>sudo mkdir -p /var/lib/named/var/cache/bind</p>
<p>sudo mkdir -p /var/lib/named/var/run/bind/run</p></blockquote>
<p>Move the default bind config directory from <em>/etc</em> to <em>/var/lib/named/etc</em></p>
<blockquote><p>sudo mv /etc/bind /var/lib/named/etc</p></blockquote>
<p>Create a symbolic link to the new config directory form the old location to the new locations</p>
<blockquote><p>sudo ln -s /var/lib/named/etc/bind /etc/bind</p></blockquote>
<p>Make null and random devices and set the correct file permissions</p>
<blockquote><p>sudo mknod /var/lib/named/dev/null c 1 3</p>
<p>sudo mknod /var/lib/named/dev/random c 1 8</p>
<p>sudo chmod 666 /var/lib/named/dev/null /var/lib/named/dev/random</p>
<p>sudo chown -R bind:bind /var/lib/named/var/*</p>
<p>sudo chown -R bind:bind /var/lib/named/etc/bind</p></blockquote>
<p>Modify syslogd to log to the right location</p>
<blockquote><p>sudo vi /etc/default/syslogd</p></blockquote>
<p>Modify the line <em>SYSLOGD=””</em> so it reads <em>SYSLOGD=&#8221;-a /var/lib/named/dev/log&#8221;</em></p>
<blockquote><p>#</p>
<p># Top configuration file for syslogd</p>
<p>#</p>
<p>#</p>
<p># Full documentation of possible arguments are found in the manpage</p>
<p># syslogd(8).</p>
<p>#</p>
<p>#</p>
<p># For remote UDP logging use SYSLOGD=&#8221;-r&#8221;</p>
<p>#</p>
<p>SYSLOGD=&#8221;-a /var/lib/named/dev/log&#8221;</p></blockquote>
<p>Restart syslogd and start bind</p>
<blockquote><p>sudo /etc/init.d/sysklogd restart</p>
<p>sudo /etc/init.d/bind9 start</p></blockquote>
<p>Check for logs by tailing <em>/var/log/syslog</em> for any error messages</p>
<blockquote><p>sudo cat /var/log/syslog</p></blockquote>
<p>or</p>
<blockquote><p>sudo tail –f /var/log/syslog</p></blockquote>
<p><strong>Testing</strong></p>
<p>Now that Bind 9 is installed, you will want to test and this can be done with the following command:</p>
<blockquote><p>dig @localhost <a href="http://www.yahoo.com">www.yahoo.com</a></p></blockquote>
<p><strong></strong></p>
<p><strong>Configure Bind 9</strong></p>
<p>The next step is to create a master zone directory followed by a zone template. It is extremely important to be cognizant of file permissions. If you get these wrongs, Bind will not resolve for your domains. Each zone file needs to be owned by the user and group bind. So if you create a new zone make sure to assign the right permissions to the new zone file</p>
<blockquote><p>sudo mkdir -p /etc/bind/zones</p>
<p>sudo chown bind:bind /etc/bind/zones</p>
<p>sudo chmod 700 /etc/bind/zones</p></blockquote>
<p>Create a template zone file</p>
<blockquote><p>sudo vi /etc/bind/zones/template</p></blockquote>
<blockquote><p>;</p>
<p>; SOA</p>
<p>;</p>
<p>$TTL    1h</p>
<p>@               IN      SOA     dns1.example.com. hostmaster.example.com. (</p>
<p>                        2007010101      ; Serial number</p>
<p>                        1h              ; Slave refresh</p>
<p>                        15m             ; Slave retry</p>
<p>                        2w              ; Slave expire</p>
<p>                        1h              ; Negative Cache TTL</p>
<p>                        )</p>
<p>;</p>
<p>; NS RECORDS</p>
<p>;</p>
<p>@               IN      NS              dns1.example.com.</p>
<p>@               IN      NS              dns2.example.com.</p>
<p>;</p>
<p>; MAIL RECORDS</p>
<p>;</p>
<p>                IN      MX      10      mx01.example.com.</p>
<p>                IN      MX      10      mx02.example.com.</p>
<p>;</p>
<p>; MAIL HOSTS</p>
<p>;</p>
<p>mx01            IN      A               1.2.3.4</p>
<p>mx02            IN      A               1.2.3.4</p>
<p>mail01          IN      A               1.2.3.4</p>
<p>mail02          IN      A               1.2.3.4</p>
<p>;</p>
<p>; WWW RECORDS</p>
<p>;</p>
<p>@               IN      A               1.2.3.4</p>
<p>www             IN      A               1.2.3.4</p>
<p>blog            IN      A               1.2.3.4</p>
<p>;</p>
<p>; CUSTOM RECORDS</p>
<p>;</p>
<p>server-a        IN      A               1.2.3.4</p>
<p>server-b        IN      A               1.2.3.4</p></blockquote>
<p>Again, ensure you have the right permissions for the zone file.</p>
<blockquote><p>sudo chown bind:bind /etc/bind/zones/template</p></blockquote>
<blockquote><p>sudo chmod 600 /etc/bind/zones/template</p></blockquote>
<p><strong>Create a New Zone</strong></p>
<p>Copy the zone file template from above and edit as needed.</p>
<blockquote><p>sudo cp -p /etc/bind/zones/template db.example.com</p></blockquote>
<p>At the very minimum the serial number and edit the file as needed.</p>
<p>Next, enable the zone file in /etc/bind/named.local</p>
<blockquote><p>sudo /etc/bind/named.conf.local</p></blockquote>
<blockquote><p>zone &#8220;example.com&#8221; {</p>
<p>        type master;</p>
<p>        file &#8220;/etc/bind/zones/db.example.com&#8221;;</p>
<p>        notify yes;</p>
<p>     };</p></blockquote>
<p>Reload Bind and test</p>
<blockquote><p>sudo tail -f /var/log/syslog</p>
<p>sudo tail -f /var/log/daemon.log</p>
<p>dig @localhost example.com MX</p></blockquote>
<p>Feel free to contact me with any questions or revisions.</p>
<p>Special thanks to the following sites for contrbuting information:</p>
<p><a href="http://doc.ubuntu.com/ubuntu/serverguide/C/dns-configuration.html">http://doc.ubuntu.com/ubuntu/serverguide/C/dns-configuration.html</a></p>
<p><a href="http://www.howtoforge.org/perfect_setup_debian_etch_p4">http://www.howtoforge.org/perfect_setup_debian_etch_p4</a></p>
<p><a href="http://www.besy.co.uk/debian/how_to_setup_a_bind_9_dns_server">http://www.besy.co.uk/debian/how_to_setup_a_bind_9_dns_server</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dougjaworski.com/blog/install-bind-9-dns-server-chroot-debian-etch-and-ubuntu/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
