Ubuntu and DNS/Bind Server: Hands On Lab
Ubuntu and DNS/Bind Server: Hands On Lab
Hands On Lab
Ubuntu and DNS/Bind Server
Table of Contents
Introduction..................................................................................................................................... 2
Goals ............................................................................................................................................... 2
Packages, Resources and Prerequisites .......................................................................................... 2
Document Conventions ................................................................................................................... 3
General Process ............................................................................................................................... 4
Apache Server Setup ....................................................................................................................... 6
BIND9 Configuration Types ............................................................................................................. 7
General BIND9 Notes ...................................................................................................................... 7
BIND9 Server – Preparation ............................................................................................................ 8
BIND9 Server – Installation ............................................................................................................. 8
BIND9 Server – Service Configuration ............................................................................................. 9
BIND9 Server – Zone Configuration .............................................................................................. 10
Configuration Check ...................................................................................................................... 12
Check the Forward Zone ............................................................................................................... 13
Check the Reverse Zone ................................................................................................................ 14
Configure Client and Verify ........................................................................................................... 14
Appendix A – named.conf.local Example ...................................................................................... 16
Appendix B – named.conf.options Example.................................................................................. 17
Appendix C – db.linuxacademy.lab Forward Zone Example ......................................................... 18
Appendix D – db.10 Reverse Zone Example .................................................................................. 19
1
Hands On Lab - Ubuntu and DNS/Bind Server
Introduction
The Domain Name Service (DNS) is a public Internet service that maps one or more IP addresses
and Fully Qualified Domain Names (FQDN) to each other (both forward – name to IP, and reverse
– IP to name).
Servers that run the BIND (Berkley Internet Naming Daemon) service are commonly referred to
as name servers.
Goals
This lab will introduce you to the concepts of DNS/BIND services from a client and server
perspective. By the end of this document, you will have built an Ubuntu 14.04 LTS BIND Server
and created a client configuration to test any created DNS entries for the domain you choose to set
up.
bind9
bind9-doc
bind9utils
apache2
lynx-cur
The resources you will be accessing during the course of this lab are:
2
Hands On Lab - Ubuntu and DNS/Bind Server
Document Conventions
Just a couple of housekeeping items to go over so you can get the most out of this Hands On Lab
without worrying about how to interpret the contents of the document.
When we are demonstrating a command that you are going to type in your shell while connected
to a server, you will see a box with a dark blue background and some text, like this:
linuxacademy@ip-10-0-0-0:~$ sudo apt-get install package
[sudo] password for linuxacademy: <PASSWORD PROVIDED>
3
Hands On Lab - Ubuntu and DNS/Bind Server
General Process
When you are ready to begin the Hands On Lab, log into your Linux Academy Lab+ subscription
and navigate to the “Live Labs” section on the Dashboard. Once you choose the “Configuring
BIND 9 DNS” Lab from the list, you will see the screen below:
4
Hands On Lab - Ubuntu and DNS/Bind Server
Other than those descriptions, you may retry any of the Labs+ labs as many times as you
wish as long as you are a subscriber.
Once you have clicked on the ‘Start Lab’ button that you see above, a process will launch on our
servers that will deploy the two servers we will use in our lab for testing. After a few minutes of
processing (and you will see a status message that says “Creating Lab… Please Wait”), you
should see a screen that looks like this one:
You will see all the information you need to access your servers from another system.
Specifically, you need:
The two server public IP addresses
Access credentials for both
One thing to note is that, in addition to the two IPs that you see above, each server will have
another IP assigned to it in the 10.0.0.x subnet. This is a private IP address and will not route
5
Hands On Lab - Ubuntu and DNS/Bind Server
outside of your private server pool. Server 1 will have a dynamic private address in the 10.0.0.x
subnet while Server 2 will have a static private address of 10.0.0.100.
In our setup, Server 1 will function as an Apache server that we will use to test our DNS server.
Server 2 will function as our primary BIND server for the purposes of this lab. Let’s spend a
quick couple of minutes setting up our Apache server.
This will install a number of packages and modules in addition to the Apache server. It will only
take a moment or two to complete and once it is done, Ubuntu will automatically launch the
Apache server on the default port 80. You can verify that it is listening by executing a local telnet
connection on port 80 and you should see the following:
linuxacademy@ip-10-0-0-162:~$ telnet localhost 80
Trying 127.0.0.1…
Connected to localhost.
Escape character is `^]`.
Pressing the escape character of ‘]’ will return an HTML message to you and close the connection,
but that verifies that our server is answering on port 80. We are now going to create the most basic
of HTML pages so that we can test our web server by name once the DNS server is up and running.
Change to the /var/www/ directory and create the following file called “test.txt” in the /var/www
directory (you can copy and paste):
<HTML>
<BODY>
www.linuxacademy.lab
</BODY>
</HTML>
This file will simply display in our text based browser the name we will be assigning to this Apache
server in DNS. We will use the Lynx text browser in our console to do so after we set up our BIND
server.
6
Hands On Lab - Ubuntu and DNS/Bind Server
Our local Apache server is now completed for now. We will be coming back to reconfigure the
DNS client once we have our BIND server ready so that we get resolution for the IPs that we
created when adding to our customized, but private, domain name.
7
Hands On Lab - Ubuntu and DNS/Bind Server
domain “google.com” which your DNS server does not own the zone for, it will
forward that request to the public DNS server configured and respond to the client
with the appropriate information (this is how we will be doing our lab as you will
see).
Local Host Entry
o Be sure your DNS server has a local host entry for the real hostname (example in
the next section).
The IPv6 information does not have to be there for our purposes since we will not be binding or
using IPv6. The line with our local server IP is setting our host file appropriately using the short
name and a fully qualified domain name. Since we will be using the private domain
‘linuxacademy.lab’ for the purposes of our exercises, that is what we list for the FQDN.
Once that is complete, you can test by pinging the short and FQDN of your local host and be sure
you get a response with the appropriate IP. If you get any errors regarding “Unknown Host”, be
sure your IP, hostname and FQDN are saved properly in the /etc/hosts file as listed above.
8
Hands On Lab - Ubuntu and DNS/Bind Server
We you can also install the BIND9 documentation by including the “bind9-doc” package, but we
are trying to get this done within our two hour window so I am skipping it here. These packages
may also install some dependencies depending on the state of your system when you run the
command but when you are done, you will have a skeleton BIND9 server setup with the BIND9
service running once it is complete. Now, we need to set up our configuration.
One of the first things you will notice you need to be careful of is punctuation in all of our
configuration files. Be sure that if you see a semicolon (;) or a period (.) at the end of any line or
name, you duplicate that. These are required for the BIND9 service to work correctly.
Next up, we need to edit another configuration file called “/etc/bind/named.conf.local”. This
particular configuration file will contain the base zone or zones that your system will be
responsible for replying for. You may have one or more zones, and we add them forward and
reverse like so:
# our forward zone and domain name
zone “linuxacademy.lab” {
type master;
file “/etc/bind/zones/db.linuxacademy.lab”;
};
9
Hands On Lab - Ubuntu and DNS/Bind Server
Once these files are saved, our BIND9 service is configured but we do not have the forward and
reverse zone files referred to within the configuration set up. As an aside, remember that forward
and reverse lookups are name to IP and IP to name. Many times they are required when accessing
a service, sending an email from one server to another, etc. in order for the receiving server to be
sure that the traffic is coming from the expected party rather than from a spoofed connection or
“man in the middle” attack.
Let’s take a look at our zone configuration files next.
Now we need to copy a template file for our use, first up, we will create the forward lookup zone
as follows:
linuxacademy@ip-10-0-0-100:/etc/bind/zones$ sudo cp ../db.local ~
db.linuxacademy.lab
Here is a sample of what that file should be edited to look like once complete (again, this can be
repeated exactly for the purposes of this lab, however, be sure to substitute the IP address of your
Apache server for the one listed below used as an example):
;
; BIND data file for local loopback interface
;
$TTL 604800
@ IN SOA ip-10-0-0-100.linuxacademy.lab. ~
admin.linuxacademy.lab. (
3 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
linuxacademy.lab. IN NS ip-10-0-0-100.linuxacademy.lab.
linuxacademy.lab. IN A 10.0.0.100
ip-10-0-0-100 IN A 10.0.0.100
ip-10-0-0-162 IN A 10.0.0.162
10
Hands On Lab - Ubuntu and DNS/Bind Server
www IN A 10.0.0.162
This file does a number of things. The most important one is that it sets up the entire zone and
binds it to the host name and IP address of the server. The zone is defined to be bound SOA (Start
of Authority) to the hostname “ip-10-0-0-100.linuxacademy.lab.”, please note the trailing period
as we warned of previously. This is one of the most common configuration errors when setting up
DNS. The second value of “admin.linuxacademy.lab.” on the same line is simply the user on the
domain that would receive email from the BIND9 service, you can define this to be any user on
the system.
Inside the configuration brackets are some values, only one of which will you normally change.
The Serial number (‘3’ in this case) is a number that must change to a different number every time
you add or remove a DNS entry from this file or the reverse file. Additionally, the Serial number
in each of the forward and reverse zone files must match exactly or the BIND9 service will fail to
start.
The other values are various timeouts, in milliseconds, for your server to take and respond to
requests from a client. You can change them as needed (be careful you are not too aggressive or
you could cause your DNS request to fail to secondary DNS servers too quickly).
Underneath that configuration are the names and IPs we have to worry about. Our first entry of
“linuxacademy.lab. IN NS ip-10-0-0-100.linuxacademy.lab.” binds the “linuxacademy.lab.”
zone to the FQDN of our server (the reason we added that FQDN to the /etc/hosts file earlier). The
second line adds a binding for the domain name to our BIND9 server IP address. Keep in mind we
are using the 10.0.0.x network as a private network hosting a private domain. If this were a public
server and a public domain you would see appropriate valid IPs and domains.
We then are adding the host name of our two lab servers to the forward zone and a second host
name called “www” to our Apache server from earlier. Although we are adding this as a full DNS
record, we could just as easily added “www” as a “CNAME” (a reference) to the host name of the
Apache server itself rather than the IP.
Let’s create our reverse zone file like so:
linuxacademy@ip-10-0-0-100:/etc/bind/zones$ sudo cp ../db.127 db.10
Here is the sample reverse zone configuration that matches our forward zone file:
;
; BIND reverse data file for local loopback interface
;
$TTL 604800
@ IN SOA ip-10-0-0-100.linuxacademy.lab.
admin.linuxacademy.lab. (
3 ; Serial
604800 ; Refresh
11
Hands On Lab - Ubuntu and DNS/Bind Server
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
IN NS ip-10-0-0-100.
Configuration Check
At this point, our installation and configuration of BIND9 should be done and all we need to do is
restart the service. However, let’s take a moment and check our zone files before we restart the
service.
In order to check our forward lookup zone, you can execute the following command:
linuxacademy@ip-10-0-0-100:~$ sudo named-checkzone linuxacademy.lab
/etc/bind/zones/db.linuxacademy.lab
zone linuxacademy.lab /IN: loaded serial 3
Ok
This verifies that all of the configuration files are formatted correctly for completing a successful
DNS lookup and returning the IP of a server name defined in our zone called “linuxacademy.lab”.
Next, we will do the same thing to check our reverse lookup zone:
linuxacademy@ip-10-0-0-100:~$ sudo named-checkzone linuxacademy.lab
/etc/bind/zones/db.10
zone linuxacademy.lab /IN: loaded serial 3
Ok
Keep in mind that the line in both checks that ends with “serial 3” could be different in your
scenario depending on the serial number you entered when editing your configuration files earlier.
If you have made any mistakes in the configuration file, this utility is kind enough to tell you that
there is an error on line number XXX. Compare your configuration file with our examples to
resolve.
12
Hands On Lab - Ubuntu and DNS/Bind Server
Now we need to edit our DNS resolution configuration file on the server. Your /etc/resolv.conf
file should look something like this:
nameserver 10.0.0.100 # our nameserver
nameserver 10.0.0.2 # AWS nameserver
search linuxacademy.lab
domain linuxacademy.lab
Finally, we just need to restart our BIND9 service, which can be done like so:
linuxacademy@ip-10-0-0-100:~$ sudo /etc/init.d/bind9 restart
You can then check your log file for any errors related to the BIND9 service (ignoring any IPv6
errors that can appear). Check the log as follows:
linuxacademy@ip-10-0-0-100:~$ sudo tail –f /var/log/syslog
At this point, we can conduct some further local testing that will actually query the BIND9 service
locally to be sure everything is responding as expected.
Now the output after the command will vary depending on the hosts that you added to your DNS
server in the forward zone configured in the earlier section. In our examples earlier, we added our
two server host names and a third entry called www (whose FQDN is www.linuxacademy.lab).
We can also execute the following command:
linuxacademy@ip-10-0-0-100:~$ nslookup linuxacademy.lab
Server: 10.0.0.100
Address: 10.0.0.100#53
Name: linuxacademy.lab
Address: 10.0.0.100
13
Hands On Lab - Ubuntu and DNS/Bind Server
You can see from these results that the DNS service is serving the appropriate results to our
forward zone lookups. If you get any error regarding “host unknown”, be sure that your local
/etc/resolv.conf shows the appropriate entries from our example earlier (the first nameserver has
to be our own IP address to have an opportunity for the service to respond).
Ok so we got the expected hostname back for our IP address, let’s try:
linuxacademy@ip-10-0-0-100:~$ nslookup 10.0.0.100
Server: 10.0.0.100
Address: 10.0.0.100#53
100.0.0.10.in-addr.arpa name=ip-10-0-0-100.linuxacademy.lab
Errors that indicate “NXDOMAN” or “SERVFAIL” means that you have a problem with your
zone file configurations. Again, compare them against the examples in this lab to resolve.
This will make sure that our DNS queries go first to our configured BIND9 server that we just
configured but then can failover to a secondary domain server if we get no response. We should
then be able to do the following:
linuxacademy@ip-10-0-0-162:~$ nslookup www.linuxacademy.lab
Server: 10.0.0.100
Address: 10.0.0.100#53
Name: www.linuxacademy.lab
Address: 10.0.0.162
14
Hands On Lab - Ubuntu and DNS/Bind Server
Voila! We got back the DNS entry for the Apache server as configured in the private DNS server
we just set up. Congratulations! You can install the Lynx text browser (lynx-cur) and navigate to
the web server to verify our test page from earlier:
linuxacademy@ip-10-0-0-162:~$ lynx
http://www.linuxacademy.lab/test.txt
You should now see the page we created that contains the simple text “www.linuxacademy.lab”.
At this point, we have completed and validated our setup.
In the following Appendices, you will find the full sample configuration and zone files that we
used during the course of our lab. If you copy them EXACTLY and simply substitute the private
IP address of your Apache server for the address 10.0.0.162 as listed, your server will work
flawlessly. However, don’t let our configuration be the end of your experimenting. Feel free to
experiment with additional entries and then validate your zones. Make sure you update the serial
number entry in both zone files and then restart the BIND9 service for your changes to take effect.
Thanks for joining us on this ride and feel free to ask any questions you may have. Good luck!
15
Hands On Lab - Ubuntu and DNS/Bind Server
//
// Do any local configuration here
//
// Consider adding the 1918 zones here, if they are not used in
// your organization
// include "/etc/bind/zones.rfc1918";
16
Hands On Lab - Ubuntu and DNS/Bind Server
// Local options
options {
directory "/var/cache/bind";
forwarders {
10.0.0.2;
};
dnssec-validation auto;
17
Hands On Lab - Ubuntu and DNS/Bind Server
;
; BIND data file for local private domain
;
$TTL 604800
@ IN SOA ip-10-0-0-100.linuxacademy.lab.
admin.linuxacademy.lab. (
3 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
linuxacademy.lab. IN NS ip-10-0-0-100.linuxacademy.lab.
linuxacademy.lab. IN A 10.0.0.100
ip-10-0-0-100 IN A 10.0.0.100
ip-10-0-0-162 IN A 10.0.0.162
www IN A 10.0.0.162
18
Hands On Lab - Ubuntu and DNS/Bind Server
;
; BIND reverse data file for local private domain
;
$TTL 604800
@ IN SOA ip-10-0-0-100.linuxacademy.lab.
admin.linuxacademy.lab. (
3 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
IN NS ip-10-0-0-100.
162 IN PTR ip-10-0-0-162.linuxacademy.lab.
162 IN PTR www.linuxacademy.lab.
100 IN PTR ip-10-0-0-100.linuxacademy.lab.
19