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.comNslookup
nslookup gw
5. That’s it.
If you enjoyed this article, please share it with others using the social buttons below. If you like to be updated when a new article is published, please subscribe via email, RSS or follow me on Twitter: @ulyssesonline.
Hi Andrew, thanks for sharing the solution. When you ping, do you use the host name only or the fully qualified domain name? Just curious. It looks like adding the DNS entry in Windows fixes that issue.
Thank you for this very concise and helpful information. This is sooo exactly what I was looking for I can’t even explain it. The one thing I had to figure out was to replace ‘ns’ in a few places with the hostname I’d given the server hosting the DNS server.
No luck,
trying this on Ubuntu server 10.10, and it doesn’t work. I’ve actually copied the examples straight from the site just for the heck of it to see if I could get it to work using your example.
Nslookup and DIG both give me SERVFAIL results.
I’m having the same problem.
The odd part is that I’ve been able to empty out my resolve.conf and named.conf.options file completely and outside DNS requests still work (despite restarting bind). How is it getting that information?
For giggles I’m restarting the server… very odd.
Even weirder.. Reverse lookup works… but forward lookup doesn’t. I used named-checkzone and both of the zone files are happy. Not sure why this is failing.
Now I’ve got reverse lookup fully working, however the best I can get for forward lookup is an “NXDOMAIN” status in DIG (which is a step up from SERVFAIL from before).
Correction… and this is really odd. I had fatfingered my resolv.conf file to use my router’s IP address (gateway). With this set up… forward lookups were in a an NXDOMAIN state, and reverse lookups were in an NOERROR state. Correcting it to the DNS server address of 192.168.1.200 has now put it back in a SERVFAIL state. For the hell of it, I’ve completely unplugged any external source just to see if I can get this working as a private setup without any forwarding.
Thanks, i tried this and really works for me. Great post
Hi Ulysses, thanks a lot for this very good tutorial. But I am stuck somewhere at the Comcast IP. Suppose I only want a local connection between my server and another terminal laptop and I want to use the default domain (mydomain.com). I have a wireless router whose control panel is activated by http://192.168.1.1 and this router has already given two IP addresses to my server and my other laptop (server 192.168.1.101) the other laptop was given (192.168.1.100). I imagine that after the setup has completed I would be able to open the website (mydomain.com) hosted on my server from the other machine.
I would be so grateful if you would be able to explain for me what to do in terms of IP addresses and any other thing. Much thanks
I hope I’m able to answer your question correctly. You would like to be able to connect to any desktop, laptop or server on your local network using a hostname or a fully qualified domain name. To do this you need to point the DNS entry of each machine to your DNS server. In this example, let’s assume your DNS server is 192.168.1.10. Typically, the DNS entries point to your router, 192.168.1.1. If you make that change to every machine on your network, you should be able to resolve a hostname in your local network as well as the internet, assuming your DNS server is routing properly.
Thanks for your reply. Let us suppose that I am at the stage of
sudo vi /etc/bind/named.conf.options
forwarders {
68.87.76.178;
};
what IP address I should put instead of 68.87.76.178 (because this is not my ISP address). Did you mean that I should put 192.168.1.10 instead? How to point the DNS entry of each machine to my DNS server- can u please explain practically how to do this. My assumed server IP is 192.168.1.101 and my other terminal laptop is 192.168.1.100.
Assume also that I am going to put a web page hosted on my server so that it can be reached from my terminal just by writing the domain name mydomain.com
Your help is very much appreciated as I am still very new in this field, very interested in learning.
The forwarders should be the DNS server of your ISP. To resolve your local domain, you need to change the network settings of your terminal laptop to use 192.168.1.101 as DNS instead of 192.168.1.1.
In Windows, you need to go to Control Panels, Network Connections, Properties, TCP/IP and then enter 192.168.1.101 as your DNS.
I hope that makes sense.
I thought that you might help me better if I explain my environment settings. I have two laptops and I am intending to make one of them as a server for learning purposes. My router has given the server the IP 192.168.1.100 and the other was given the IP 192.168.1.101. I am intending to make the first one as the server. The router IP is 192.168.1.1 . As I am still new in this field, I was totally confused on the number of parameter used on your tutorial. I am especially confused about the IP to use for the DNS server. Suppose I am not able to get the static IP; will it be possible to use the local IP(s) mentioned in this message?. And then what IP should be used in the forwarder. My Terminal shows the prompt
sarmad@sarmad-HP-G61-Notebook-PC:~$
I would be so grateful if you reformulate your tutorial in view of my environment settings to enable me to build the local domain mydomain.com
If your DNS server is 192.168.1.100, then you need to change the DNS network setting on your laptop to point to 192.168.1.100. Simple.
Had same problem but all I did is restart the bind9 process anyway and that was all. I used the line below:
$ sudo service bind9 restart
To explicitly confirm bind9 is running, use this line:
$ service bind9 status
Thanks a lot for all. I could reinstall Bind again and no problem with it now. Now I installed apache22 on a Windows 7 and and I created a testing site on a folder I called c:\mysites and a server name I called it site1.local. And all the necessary setting I have done in the httpd.conf file. I also tweaked the hosts file inside Windows 7. I am intending to request the name http://site1.local from my other laptop browser (Ubuntu 10.10) but I am not succeeding. I am getting the error (Forbidden
You don’t have permission to access / on this server) please note that I also opened port 80.
I had a problem with the setup until i deleted the cache, after that everything worked ok
[...] This one on ulyssesonline (http://ulyssesonline.com/2007/11/07/how-to-setup-a-dns-server-in-ubuntu/) [...]
i m getting following error-
sudo /etc/init.d/bind9 restart
* Stopping domain name service…bind9 rndc: connect failed: 127.0.0.1#953: connection refused
Whenever i am trying this domain name system for my ubuntu system. it is not running. is any additional configuration or packages need to config dns. now i m using ubuntu 10.10. please help me..
[...] Here is a good tutorial show you how to Setup DNS Server in Ubuntu: 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! [...]
[...] setup a DNS server today on Ubuntu, following this tutorial. My intent was to setup my network for dns-name resolving on the private LAN within a single zone [...]
This seems kinda pointless. To quote yourself ..
“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. ”
Why give an example that is not applicable to “most computer systems nowadays”?
I think you are confusing DHCP which automatically assigns IP addresses to computers vs DNS which makes server names stick that’s accessible from any computer in the same network. That’s what we are after here. We want DNS to work internally as well as forward outside of the internal domain.