Source: http://ulyssesonline.com/2007/11/07/how-to-setup-a-dns-server-in-ubuntu/
Overview
Would you like to setup a DNS Server in Ubuntu? How about setting up a private internal domain name at home? Well, you’ve come to the right place. There are number of tutorials on the internet showing you how to setup a DNS Server with Ubuntu using Bind 9. So, why another how-to document? That’s a good question. I’ve decided I needed to write a simple tutorial that anyone with a little bit of Linux knowledge would be able to follow. In the process, I hope readers are also able to learn how DNS works. Ok, let’s jump right to it!
What is DNS?
First of all, let’s cover the basics. What is DNS? DNS stands for Domain Name Server. It’s a service that runs on a server that translates humanly recognizable domain names such as www.yahoo.com or www.google.com into its assigned IP addresses. If the DNS server does not recognize the domain name being requested, it will forward the domain name request to another DNS server and so on until the name is resolved.
A typical DNS request is when someone is accessing a website. Let’s use the www.yahoo.com domain as an example. When a user clicks a Yahoo link or types the Yahoo URL on the address bar of the browser, the DNS server processes the domain request. If it doesn’t find www.yahoo.com on its DNS table, it will forward the request to another DNS server with a higher authority and so on until it finds a server with the URL entry. The IP address information is then sent back to the user’s browser. If the domain name is not found, a “server not found” message is displayed on the browser.
Assumptions
Enough with the DNS background. Let’s now start configuring our own DNS server. Let’s assume that we have the following: we want to create a private internal domain name called mydomain.com, our private internal network is 192.168.0.x and our router and gateway is set at 192.168.0.1. Let’s assume all devices are going to be configured with static IP addresses. Normally, most computer systems nowadays are configured to automatically obtain IP addresses from the DHCP server/router. In this example, we will use static IP addresses to show how DNS works. Finally, we have 3 computers connected to our network:
- Ubuntu Server, the DNS server – 192.168.0.9
- Ubuntu Desktop – 192.168.0.10
- PC – 192.168.0.11
Instructions
1. To install the DNS server, we need to install Bind 9.
sudo apt-get install bind9
2. Let’s configure Bind. We need to touch 5 files.
We will edit 3 files.
- /etc/bind/named.conf.local
- /etc/bind/named.conf.options
- /etc/resolv.conf
We will create 2 files.
- /etc/bind/zones/mydomain.com.db
- /etc/bind/zones/rev.0.168.192.in-addr.arpa
A. First step. Lets add our domain zone – mydomain.com.
sudo vi /etc/bind/named.conf.local
# Our domain zone
zone "mydomain.com" {
type master;
file "/etc/bind/zones/mydomain.com.db";
};
# For reverse DNS
zone "0.168.192.in-addr.arpa" {
type master;
file "/etc/bind/zones/rev.0.168.192.in-addr.arpa";
};
Save file. Exit.
We just created a new domain. Please note: later we will create two files named mydomain.com.db and rev.0.168.192.in-addr.arpa files. Also, notice the reverse IP address sequence in the reverse DNS section.
B. Let’s add the DNS servers from your ISP. In my case, I’m using Comcast DNS servers. You can place the primary and secondary DNS servers here separated by semicolons.
sudo vi /etc/bind/named.conf.options
forwarders {
68.87.76.178;
};
Save file. Exit.
C. Now, let’s modify the resolv.conf file found in /etc and place the IP address of our DNS server which is set to 192.168.0.9.
$ sudo vi /etc/resolv.conf
search mydomain.com.
nameserver 192.168.0.9
D. Now, let’s define the zones.
sudo mkdir /etc/bind/zones
sudo vi /etc/bind/zones/mydomain.com.db
$TTL 3D
@ IN SOA ns.mydomain.com. admin.mydomain.com. (
2007062001
28800
3600
604800
38400
);
mydomain.com. IN NS ns.mydomain.com.
ubuntudesktop IN A 192.168.0.10
www IN CNAME ubuntudesktop
pc IN A 192.168.0.11
gw IN A 192.168.0.1
TXT "Network Gateway"
The TTL or time to live is set for 3 days
The ns.mydomain.com nameserver is defined
ubuntudesktop, pc and gateway are entered as an A record
An alias of www is assigned to ubuntudesktop using CNAME
E. Let’s create a “rev.0.168.192.in-addr.arpa” file for reverse lookup.
sudo vi /etc/bind/zones/rev.0.168.192.in-addr.arpa
$TTL 3D
@ IN SOA ns.mydomain.com. admin.mydomain.com. (
2007062001
28800
604800
604800
86400
)
IN NS ns.mydomain.com.
1 IN PTR gw.mydomain.com.
10 IN PTR ubuntudesktop.mydomain.com.
11 IN PTR pc.mydomain.com.
3. Let’s restart Bind to activate our latest changes.
sudo /etc/init.d/bind9 restart
4. Finally, let’s test our new domain and DNS entries.
Dig
$ dig mydomain.com
Nslookup
nslookup gw
-------------------------------------------------------------
DNS Zones Overview
A DNS
zone is the contiguous portion of the DNS domain name space over which a DNS server has authority, or is
authoritative. A zone is a portion of a namespace . it is not a domain. A domain is a branch of the DNS namespace. A
DNS zone can contain one or more contiguous domains. A DNS server
can be authoritative for multiple DNS zones. A
noncontiguous namespace cannot be a DNS zone.
A zone contains the resource records for all of the names within the particular zone. Zone files are used if DNS
data is not integrated with Active Directory. The zone files contain the DNS database resource records which define the
zone. If DNS and Active Directory are integrated, then DNS data is stored in Active Directory.
The different types of zones used in Windows Server 2003 DNS are listed below:
- Primary zone
- Secondary zone
- Active Directory-integrated zone
- Reverse lookup zone
- Stub zone
IP addresses to
resource names on the network. A reverse lookup zone can be either of the following zones:
- Primary zone
- Secondary zone
- Active Directory-integrated zone
-
Iterative queries: The DNS server provides the best answer it can. This can be:
- The resolved name
- A referral to a different DNS server
- Recursive queries: The DNS server has to reply with the requested information, or with an error. The DNS server cannot provide a referral to a different DNS server
- Start of Authority (SOA) resource records of the zone.
- Resource records that list the authoritative DNS servers of the zone
- Glue address (A) resource records that are necessary for contacting the authoritative servers of the zone.
- You want to delegate administration of a DNS domain to a department or branch of your organization.
- You want to improve performance and fault tolerance of your DNS environment . you can distribute DNS database management and maintenance between several DNS servers.
Understanding DNS Zone Transfer
A zone transfer can be defined as the process that occurs to copy the resource records of a zone on the primary DNS server to secondary DNS servers. Zone transfer enables a secondary DNS server to continue handling queries if the primary DNS server fails. A secondary DNS server can also transfer it zone data to other secondary DNS servers, who are beneath it in the DNS hierarchy. In this case, the secondary DNS server is regarded as the master DNS server to the other secondary servers. The zone transfer methods are:-
Full transfer: When you configure a secondary DNS server for a zone, and start the secondary DNS server, the
secondary DNS server requests a full copy of the zone from the primary DNS server. A full transfer is performed of all
the zone information. Full zone transfers tend to be resource intensive. This disadvantage of full transfers has
led to
the development of incremental zone transfers.
-
Incremental zone transfer: With an incremental zone transfer, only those resource records that have since
changed in a zone are transferred to the secondary DNS servers. During zone transfer, the DNS databases on the primary
DNS server and the secondary DNS server are compared to determine whether there are differences in the DNS data. If the
DNS data of the primary and secondary DNS servers are the same, zone transfer does not take place. If the DNS data of
the two servers are different, transfer of the delta resource records starts. This occurs when the serial number on the
primary DNS server database is higher than that of secondary DNS server.s serial number. For incremental zone transfer
to occur, the primary DNS server has to record incremental changes to its DNS database. Incremental zone transfers
require less
bandwidth than full zone transfers.
- Active Directory transfers: These zone transfers occur when Active Directory-integrated zones are replicated to the domain controllers in a domain. Replication occurs through Active Directory replication.
- DNS Notify is a mechanism that enables a primary DNS server to inform secondary DNS servers when its database has been updated. DNS Notify informs the secondary DNS servers when they need to initiate a zone transfer so that the updates of the primary DNS server can be replicated to them. When a secondary DNS server receives the notification from the primary DNS server, it can start an incremental zone transfer or a full zone transfer to pull zone changes from the primary DNS servers.
Understanding DNS Resource Records (RRs)
The DNS database contains resource records (entries) that are used to resolve name
resolution queries sent to the
DNS server. Each DNS server contains the resource records (RRs) it needs to respond to name resolution queries for the
portion of the DNS namespace for which it is authoritative. There are different types of resource records.
A few of the commonly used resource records (RR) and their associated functions are described in the Table.
| Resource Records Type | Name | Function |
| A | Host record |
Contains the IP address of a specific host, and maps the FQDN to this 32-bit IPv4
addresses.
|
| AAAA | IPv6 address record | Ties a FQDN to an IPv6 128-bit address. |
| AFSDB | Andrews files system |
Associates a DNS domain name to a server subtype: an AFS version 3
volume or an authenticated name server using DCE/NCA
|
| ATMA | Asynchronous Transfer Mode address |
Associates a DNS domain name to the ATM address of the
atm_address field.
|
| CNAME | Canonical Name / Alias name | Ties an alias to its associated domain name. |
| HINFO | Host info record |
Indicates the CPU and OS type for a particular host.
|
| ISDN | ISDN info record | Ties a FQDN to an associated ISDN telephone number |
| KEY | Public key resource record | Contains the public key for zones that can use DNS Security Extensions (DNSSEC). |
| MB | Mailbox name record | Maps the domain mail server name to the mail server.s host name |
| MG | Mail group record | Ties th domain mailing group to mailbox resource records |
| MINFO | Mailbox info record | Associates a mailbox for an individual that maintains it. |
| MR | Mailbox renamed record | Maps an older mailbox name to its new mailbox name. |
| MX | Mail exchange record |
Provides routing for messages to mail servers and backup
servers.
|
| NS | Name server record | Provides a list of the authoritative servers for a domain. Also provides the authoritative DNS server for delegated subdomains. |
| NXT | Next resource record | Indicates those resource record types that exist for a name. Specifies the resource record in the zone. |
| OPT | Option resource record | A pseudo-resource record which provides extended DNS functionality. |
| PTR | Pointer resource record | Points to a different resource record, and is used for reverse lookups to point to A type resource records. |
| RT | Route through record | Provides routing information for hosts that do not have a WAN address. |
| SIG | Signature resource record | Stores the digital signature for an RR set. |
| SOA | Start of Authority resource record | This resource record contains zone information for determining the name of the primary DNS server for the zone. The SOA record stores other zone property information, such as version information. |
| SRV | Service locator record |
Used by Active directory to locate domain controllers, LDAP servers,
and global catalog servers.
|
| TXT | Text record | Maps a DNS name to descriptive text. |
| X25 | X.25 info record | Maps a DNS address to the public switched data network (PSDN) address number. |
- Owner; the DNS domain that contains the resource record
-
TTL (Time to Live); indicates the time duration that DNS servers can
cache resource record information,
prior to discarding the information. This is however an optional resource records field.
- Class; is another optional resource records field. Class types were used in earlier implementations of the DNS naming system, and are no longer used these days.
- Type; indicates the type of information contained by the resource record.
- Record-Specific Data; a variable length field that further defines the function of the resource. The format of the field is determined by Class and Type.
- Delegation records: These are Name Space (NS) resource records in a parent zone. The delegation record specifies the parent zone as being authoritative for the delegated zones.
- Glue records: These are A type resource records for the DNS server who is authoritative for delegated zone.
- Start of Authority (SOA), Name Server (NS), Host (A), Alias (CNAME), Mail exchanger (MX), Pointer (PTR), Service location (SRV)
Start of Authority (SOA) Resource Record
This is the first record in the DNS database file. The SOA record includes information on the zone property information, such as of the primary DNS server for the zone, and version information. The fields located within the SOA record are listed below:- Source host; the host for who the DNS database file is maintained
- Contact e-mail; e-mail address for the individual who is responsible for the database file.
- Serial number; the version number of the database.
- Refresh time; the time that a secondary DNS server waits, while determining whether database updates have been made, that have to be replicated via zone transfer.
- Retry time; the time for which a secondary DNS server waits before attempting a failed zone transfer again.
- Expiration time; the time for which a secondary DNS server will continue to attempt to download zone information. Old zone information is discarded when this limit is reached.
- Time to live; the time that the particular DNS server can cache resource records from the DNS database file.
Name Server (NS) Resource Record
The Name Server (NS) resource record provides a list of the authoritative DNS servers for a domain, as well authoritative DNS server for any delegated subdomains. Each zone must have one (or more) NS resource records at the zone
root. The NS resource record indicates the primary and secondary DNS servers for the zone defined in the SOA
resource record. This in turn enables other DNS servers to look up names in the domain.
Host (A) Resource Record
The host (A) resource record contains the IP address of a specific host, and maps the FQDN to this 32-bit IPv4 addresses. Host (A) resource records basically associates the domain names of computers (FQDNs) or hosts names to their associated IP addresses. Because a host (A) resource record statically associates a host name to a specific IP address, you can manually add these records to zones if you have machines who have statically assigned IP addresses. The methods which are used to add host (A) resource records to zones are:- Manually add these records, using the DNS management console.
- You can use the Dnscmd tool at the command line to add host (A) resource records.
-
TCP/IP client computers running Windows 2000, Windows XP or Windows Server 2003 use the
DHCP Client service to both
register their names, and update their host (A) resource records.
Alias (CNAME) Resource Record
Alias (CNAME) resource records ties an alias name to its associated domain name. Alias (CNAME) resource records are referred to as canonical names. By using canonical names, you can hide network information from the clients who connect to your network. Alias (CNAME) resource records should be used when you have to rename a host that is defined in a host (A) resource record in the identical zone.Mail exchanger (MX) Resource Record
The mail exchanger (MX) resource record provides routing for messages to mail servers and backup servers. The mail MX resource record provides information on which mail servers processes e-mail for the particular domain name. E-mail applications therefore mostly utilize MX resource records. A mail exchanger (MX) resource record has the following parameters:- Priority
- Mail server
Pointer (PTR) Resource Record
The pointer (PTR) resource record points to a different resource record, and is used for reverse lookups to point to A resource records. Reverse lookups resolve IP addresses to host names or FQDNs. You can add PTR resource records to zones through the following methods:- Manually add these records, using the DNS management console.
- You can use the Dnscmd tool at the command line to add PTR resource records.
Service (SRV) Resource Records
Service (SRV) resource records are typically used by Active directory to locate domain controllers, LDAP servers, and global catalog servers. The SRV records define the location of specific services in a domain. They associate the location of a service such as a domain controller or global catalog server; with details on how the particular service can be contacted. The fields of the service (SRV) resource record are explained below:- Service name
-
The
protocol used
- The domain name associated with the SRV records.
- The port number for the particular service
- The Time to Live value
- The class
- The priority and weight.
- The target specifying the FQDN of the particular host supporting the service
The Zone Database Files
If you are not using Active Directory-integrated zones, the specific zone database files that are used for zone data are:-
Domain Name file: When new A type resource records are added to the domain, they are stored in this file.
When a zone is created, the Domain Name file contains the following:
- A SOA resource record for the domain
- A NS resource record that indicates the name of the DNS server that was created.
- Reverse Lookup file: This database file contains information on a reverse lookup zone.
- Cache file: This file contains a listing of the names and addresses of root name servers that are needed for resolving names which are external to the authoritative domains.
-
Boot file: This file controls the startup behavior of the DNS server. The boot file supports the commands
listed below:
- Directory command; this command defines the location of the other files specified in the Boot file.
- Primary command; defines the domain for which this particular DNS server has authority.
- Secondary; specifies a domain as being a secondary domain.
- Cache command; this command defines the list of root hints used for contacting DNS servers for the root domain
Planning DNS Zone Implementations
When you divide the up the DNS namespace, DNS zones are created. Breaking up the namespace into zones enables DNS to more efficiently manage available bandwidth usage, which in turn improves DNS performance. When determining how to break up the DNS zones, a few considerations you should include are listed below:-
DNS traffic patterns: You can use the System
Monitor tool to examine DNS performance counters, and to obtain DNS
server statistics.
- Network link speed: The types of network links that exist between your DNS servers should be determined when you plan the zones for your environment.
- Whether full DNS servers or caching-only DNS servers are being used also affects how you break up DNS zones
- Active Directory replication is faster, which means that the time needed to transfer zone data between zones is far less.
- The Active Directory replication topology is used for Active Directory replication, and for Active Directory-integrated zone replication. There is no longer a need for DNS replication when DNS and Active Directory are integrated.
- Active Directory-integrated zones can enjoy the security features of Active Directory.
- The need to manage your Active Directory domains and DNS namespaces as separate entities is eliminated. This in turn reduces administrative overhead.
- When DNS and Active Directory are integrated; the Active Directory-integrated zones are replicated, and stored on any new domain controllers automatically. Synchronization takes place automatically when new domain controllers are deployed.
- A client sends a query to the DNS server for name resolution.
- The DNS server checks its DNS database file to determine whether it can resolve the query with its zone data.
- The DNS server also checks its DNS server cache to resolve the request.
- If the DNS server is not configured to use forwarding, the server uses recursion to attempt to resolve the query.
- If the DNS server is configured to forward the query for a specific domain name to a DNS forwarder, the DNS server then forwards the query to the IP address of its configured DNS forwarder.
- You should only implement the DNS forwarders that are necessary for your environment. You should refrain from creating loads of forwarders for your internal DNS servers.
- You should avoid chaining your DNS servers together in a forwarding configuration.
- To avoid the DNS forwarder turning into a bottleneck, do not configure one external DNS forwarder for all your internal DNS servers.
How to create a new zone
- Click Start, Administrative Tools, and then click DNS to open the DNS console.
- Expand the Forward Lookup Zones folder
- Select the Forward Lookup Zones folder.
- From the Action menu, select New Zone.
- The New Zone Wizard initiates.
- On the initial page of the Wizard, click Next.
- On the Zone Type page, ensure that the Primary Zone. Creates A Copy Of A Zone That Can Be Updated Directly On This Server option is selected. This option is by default selected.
- Uncheck the Store The Zone In Active Directory (Available Only If DNS Server Is A Domain Controller) checkbox. Click Next.
- On the Zone Name page, enter the correct name for the zone in he Zone Name textbox. Click Next.
- On the Zone File page, ensure that the default option, Create A New File With This File Name is selected. Click Next.
- On the Dynamic Update page, ensure that the Do Not Allow Dynamic Updates. Dynamic Updates Of Resource Records Are Not Accepted By This Zone. You Must Update These Records Manually option is selected. Click Next.
- The Completing The New Zone Wizard page is displayed next.
- Click Finish to create the new zone.
How to create subdomains
- Click Start, Administrative Tools, and then click DNS to open the DNS console.
- In the console tree, select the appropriate zone.
- From the Action menu, select New Domain.
- The DNS Domain dialog box opens.
- Enter the name for new subdomain.
- Click OK to create the new subdomain.
How to create a reverse lookup zone
- Click Start, Administrative Tools, and the select DNS to open the DNS console.
- Select the appropriate DNS server in the console tree.
- Right-click the DNS server, and then select New Zone from the shortcut menu.
- The New Zone Wizard starts.
- Click Next on the first page of the New Zone Wizard.
- On the Zone Type page, ensure that the Primary Zone option is selected. Click Next.
- On the following page, select the Reverse lookup zone option. Click Next.
- Enter the IP network in the Network ID box, for the domain name that you are creating this new reverse lookup zone for. Click Next.
- Accept the default zone file name. Click Next.
- On the Dynamic Update page, select the Allow both nonsecure and secure dynamic updates option, and then click Next.
- .The Completing The New Zone Wizard page is displayed next.
- Click Finish to create the new reverse lookup zone.
How to create a stub zone
- Click Start, Administrative Tools, and then click DNS to open the DNS console.
- Expand the Forward Lookup Zones folder
- Select the Forward Lookup Zones folder.
- From the Action menu, select New Zone.
- The New Zone Wizard initiates.
- On the initial page of the Wizard, click Next.
- On the Zone Type page, select the Stub Zone option.
- Uncheck the Store The Zone In Active Directory (Available Only If DNS Server Is A Domain Controller) checkbox. Click Next.
- On the Zone Name page, enter the name for the new stub zone in the Zone Name textbox, and then click Next.
- Accept the default setting on the Zone file page. Click Next.
- On the Master DNS Servers page, enter the IP address of the master server in the Address text box. Click Next.
- On the Completing The New Zone Wizard page, click Finish.
How to add resource records to zones
- Click Start, Administrative Tools, and then click DNS to open the DNS console.
- In the console tree, select the zone that you want to add resource records to.
-
From the Action menu, select the resource record type that you want to add to the zone. The options are:
- New Host (A)
- New Alias (CNAME)
- New Mail Exchanger (MX)
- Other New Records
- Select the New Host (A) option.
- The New Host dialog box opens.
- In the Name (Use Parent Domain Name If Blank) textbox, enter the name of the new host.
- When you specify the name of the new host, the resulting FQDN is displayed in the Fully qualified domain name (FQDN) textbox.
- In the IP Address box, enter the address for the new host.
- If you want to create an associated pointer (PTR) record, enable the checkbox.
- Click the Add Host button.
- The new host (A) resource record is added to the particular zone.
- A message box is displayed, verifying that the new host (A) resource record was successfully created for the zone.
- Click OK.
- Click Done to close the New Host dialog box./li>
How to create a zone delegation
- Click Start, Administrative Tools, and then select DNS to open the DNS console.
- Right-click your subdomain in the console tree, and then select New Delegation from the shortcut menu.
- The New Delegation Wizard initiates.
- Click Next on the first page of the New Delegation Wizard.
- When the Delegated Domain Name page opens, provide a delegated domain name, and then click Next.
- On the Name Servers page, click the Add button to provide the names and the IP addresses of your DNS servers that should host the delegation
- On the Name Servers page, click Next.
- Click Finish.
How to enable dynamic updates for a zone
- Click Start, Administrative Tools, and the select DNS to open the DNS console.
- Right-click the zone you want to work with in the console tree, and then select Properties from the shortcut menu.
- When the Zone Properties dialog box opens, on the General tab, select Yes in the Allow Dynamic Updates list box.
- Click OK.
How to configure a zone to use WINS for name resolution
You can configure your forward lookup zone to use WINS for name resolution in instances where the queried name is not found in the DNS namespace.- Click Start, Administrative Tools, and the select DNS to open the DNS console.
-
In the console tree, proceed to expand your DNS server
node, and then expand the Forward Lookup Zones folder.
- Locate and right-click the zone which you want to configure and then select Properties from the shortcut menu.
- When the Zone Properties dialog box opens, click the WINS tab.
- Enable the Use WINS Forward Lookup checkbox.
- Type the WINS server IP address. Click Add, and then click OK.
- On the General tab, select Yes in the Allow Dynamic Updates list box.
- Click OK.