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.
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.
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.
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.
D. Now, let’s define the zones.
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.
3. Let’s restart Bind to activate our latest changes.
4. Finally, let’s test our new domain and DNS entries.
Dig
Nslookup
5. That’s it.


(6 votes, average: 3.33 out of 5)
Thanks… after three other how to’s this one worked fof my setup. I was going crazy trying to figure out why my internal ip’s wouldn’t resolve.
Todd, I’m glad you found it useful.
Awesome HowTo, exactly what I was looking for. Thanks…
Hey Ulyssesr!
Nice work man!
That was simple, clear and fast!
Thank you for writing this!
I just study Linux. And I want to know how to set up DNs, Mail Sever and Web Server in my Linux(Only one pc or labtop).
Thanks for reply,..
Great work.
Liked it loads, easy to understand.
I have a question though:
I have about 10 windows work station and two linux boxes. i want to be able to refer to each PC or System with its name. Say, i want to be able to ping them by their names e.g instead of pinging a system with it’s IP address, i want to ping it with it’s name; like thing : ping PC-ubuntu-desktop instead of ping 192.168.0.20. How can i achieve this please.
Hi Kay,
1. First, you will need to assign a static ip addresses to all your workstations. The last thing you need is a host with a different ip address each time you are connected to the network.
2. Second, you need to enter several A records to your zone file, e.g. /etc/bind/zones/mydomain.com.db in this example.
ubuntudesktop-1 IN A 192.168.0.11
ubuntudesktop-2 IN A 192.168.0.12
ubuntudesktop-3 IN A 192.168.0.13
ubuntudesktop-4 IN A 192.168.0.14
and so forth….
3. For reverse lookup, make the appropriate entries to your reverse DNS file, rev.0.168.192.in-addr.arpa in this example. Here, we are making a reverse DNS entry for ubuntudesktop-1 at ip 192.168.0.11.
11 IN PTR ubuntudesktop-1.mydomain.com.
Don’t forget that period in the end of the domain.
Hope that helps.
Dear Ulysses,
What do I need to do if I need to use the same DNS server for several subnets, such as:
192.168.100.0 255.255.255.0
192.168.110.0 255.255.255.0
192.168.120.0 255.255.255.0
Would it work if I made a separate reverse dns entry in named.conf.local for each subnet and create a separate file for each entry?
Yes, creating 3 reverse DNS entries in named.conf.local and making 3 separate reverse files in /etc/bind/zones/ should do the trick. Let me know how it goes.
I haven’t gotten it to work. The actual subnets I am using are:
192.168.1.252 255.255.255.252
192.168.20.0 255.255.255.0
I have the Ubuntu Server 7.10 named GutsyServer at:
192.168.1.254 255.255.255.252
I have the Windows XP client named Client-B3 at:
192.168.20.11 255.255.255.0
I wonder if I named the reverse-dns files correctly. If I want to use just one reverse-dns file for a 192.168.0.0 255.255.0.0 network, could I just create a file named rev.168.192.in-addr.arpa. In the file I made reference to Client-B3 such:
11.20 IN PTR Client-B3.Gutsy.org
Is that the correct way to do it?
I have tried using two separate reverse-dns files, one for 192.168.1.252 and one for 192.168.20.11, but I could not get it to work. In each file I stated the SOA. Is that correct? I wonder if that is the source of my error.
I am able to do a tracert from Client-B3 to GutsyServer, but for some reason the browser will not work with the internet? It seems like internally the DNS server works, but will not work with the ISP’s DNS server? I made sure the forwarders are correct. Is there something else that needs to be configured?
Daniel, I thought about this for a little bit. I haven’t use multiple multiple networks locally, much more use DNS across 2 or multiple networks. The rule is to always get your network working first. Make sure you can ping the DNS server from all the networks.
I have already gotten the network working. When I use Windows 2003 Server everything works smoothly. When I use Ubuntu as a DNS Server I am able to resolve dns names from the server itself, including http://www.microsoft.com. I checked it with nslookup. When I try to use nslookup from one of the clients that I’ve assigned to the DNS Server with the A command and the PTR command, I am successful. But when I do nslookup for http://www.microsoft.com from the client, I get a message saying that the query was denied. It seems that the ISP’s DNS servers are rejecting my DNS server’s request for a query when I do the request from a client. This is odd to me. I’ve looked at about a dozen tutorials. None of them address this issue. I wonder if there is something else involved rather than DNS, like perhaps ldap.
In any case, thanks for the reply.
Daniel
sir dns server is exalent but i want nis server
I have a dns cache defined as “home”
—————————————————
$TTL 3D
@ IN SOA ns1.home. admin.home. (
2006081401
28800
3600
604800
38400
);
home. IN NS ns1.home.
server1 IN A 192.168.1.3
www IN CNAME server1
————————————————–
and my reverse lookup is
————————————————–
$TTL 3D
@ IN SOA ns1.home. admin.home. (
2006081401;
28800;
604800;
604800;
86400
);
IN NS ns1.home.
3 IN PTR server1.home.
———————————————————
I have just installed apache and havent touched its default config yet. When I type
server1.home –> it works (apache default page)
but, when I type
home –> Works (apache default page)
or
server2.home — > Works (apache default page)
Why?
When I type any other canonical, like server3.home or server100.home, it doesnt work.
I have cleared cache in firefox, but still result is the same. From where is it finding server2 or just home?
I am a bit confused, any tip would help. Thanks.
I read the stuff about the ibuntu server and i think you did an excellent job.I have been for sometime now been working how to configure an ubuntu dns server.The stuff is very simple and i wish to say CONGRATULATIONS.I have learnt lots more from you.
I want to know if you also do anything on configratioon of an ubuntu proxy server.
Best wishes to you.You are just too wonderful.
Hi Ulysses,
I liked your tutorial about setting up DNS for a local network and followed directions to try and set up mine. Apparently I overlooked that it was for a local network so after a day of trying (and not getting it to work) I woke up the next day and realized I may need a tutorial for a web server rather than a local network. Duh! So, do you have a tutorial to set up DNS for a web server? If not can you point me one? I am trying to set up Apache on ubuntu on a server at home and want to handle my own DNS. I have a few towers and am wondering if I should setup DNS on the same tower I have my www files/Apache on, or set DNS up on a seperate tower? I have 5 static IP addresses I can use.
Thanks Ulysses!!
thanks you..
Ya hurre
But can you tell me that how to add the ubuntu clients in the dns and how to add the windows machines in this domain e.g. mydomain.com
hey
I was wondering if i set up a dns server from home do i not need to register my domain name? or if can it work as a redirect service for people trying to access my site externally?