How To Install and Setup Bind9 On Ubuntu Server
| |So you knew how to manually install and setup a Linux, Apache, MySQL and PHP (also known as LAMP Stack) on a server based on Ubuntu. You may be wondering how to make your server being accessible by domain not by IP address. Well, there are several ways you can do that but the key method is simple: by using DNS Server. There are two methods to have DNS Server connecting your domain to your server: First, you can simply use DNS management service which is usually offered freely by most of domain registrar like GoDaddy and NameCheap; Another method is to install and setup your own DNS server right inside your operating system to manage how the way your domain resolves to your server. I will explain the first method another day while today in this page you’ll see the second method.
p.s: When I say “server” it refers to both VPS or Dedicated server
Requirements
- This tutorial is done on Ubuntu-based server. I am running Ubuntu 12.0.4 (see my playground server).
- Windows users should download Putty while Mac and Linux users can simply use Terminal
- You’ll also need a basic skill to use Putty and to navigate through SSH. Read: Most common Unix commands used to SSH.
- In this tutorial I will use Bind9 which is a free DNS management software available for most Operating System including Unix-based OS. I will not explain what is BIND and what are its key features as Wikipedia covers that topics better.
Read: What is DNS Management Software and comparison of available software. - You may firstly install LAMP stack or any other stack you wish.
- About 15 minutes of your time and a cup of tea if you like.
Step 1. Login to your server
Launch Putty (or Terminal) and login to your server via SSH connection. Please remember if you’ve followed our very basic guide here, you may already have disabled root login or changing default SSH port from 22 to other numbers. If you really did disable root login, then login by using new username and password you created then type following command once you logged in, otherwise you can simply skip this command:
sudo su
then you have to enter root password.
Step 2. Install Bind9
Type this command then hit enter:
apt-get install bind9
Once done you’ll see a message saying:
* Starting domain name service... bind9 [OK]
Step 3. Basic Configuration
So you have installed BIND9 on your server. It is time to show you a basic configuration how to setup your domain to resolve to your server. Here’s what I did. Type following command then hit Enter on your keyboard:
nano /etc/bind/named.conf.local
Nano editor screen will appear. Copy-paste command below into your favorite text editor like Notepad, Notepad2 or Notepad++:
zone "domain.com" { type master; file "/etc/bind/zones/domain.com.db"; }; zone "3.2.1.in-addr.arpa" { type master; file "/etc/bind/zones/rev.3.2.1.in-addr.arpa"; };
Again, in any command in this page you’ll need to replace “domain.com” with your own domain name and corresponding TLD. E.g: servermom.com. Also, you have to replace xxx.xxx.xxx.xxx with IP address of your server.
Once you’ve done editing necessary values, you can paste it to Nano editor screen. You can also simply type command syntax above to Nano editor screen while replacing necessary value during your typing.
Now hit Control+O on your keyboard to save the file then hit Control+X to exit Nano editor.
Then go to bind directory to make things easier. Type this command:
cd /etc/bind
Create new directory called “zones” inside it.. Use this command:
mkdir zones
Now go enter that directory as well..
cd zones
Then create new file called “nano domain.com.db
“. Type this command:
nano domain.com.db
of course at this part you’ll also need to replace “domain.com” with your own domain name. Example:
nano servermom.com.db
That command brings Nano editor screen up once again. Next, you can either copy these syntax to Notepad first then edit it or simply type it in Nano editor directly:
; BIND data file for domain.com ; $TTL 14400 @ IN SOA ns1.domain.com. host.domain.com. ( 201006601 ; Serial 7200 ; Refresh 120 ; Retry 2419200 ; Expire 604800) ; Default TTL ; domain.com. IN NS ns1.domain.com. domain.com. IN NS ns2.domain.com. domain.com. IN MX 10 mail.domain.com. domain.com. IN A xxx.xxx.xxx.xxx ns1 IN A xxx.xxx.xxx.xxx ns2 IN A xxx.xxx.xxx.xxx www IN CNAME domain.com. mail IN A xxx.xxx.xxx.xxx ftp IN CNAME domain.com. domain.com. IN TXT "v=spf1 ip4:xxx.xxx.xxx.xxx a mx ~all" mail IN TXT "v=spf1 a -all"
Here’s an example of mine:
; BIND data file for servermom.com ; $TTL 14400 @ IN SOA ns1.servermom.com. host.servermom.com. ( 201006601 ; Serial 7200 ; Refresh 120 ; Retry 2419200 ; Expire 604800) ; Default TTL ; servermom.com. IN NS ns1.servermom.com. servermom.com. IN NS ns2.servermom.com. servermom.com. IN MX 10 mail.servermom.com. servermom.com. IN A 141.0.170.144 ns1 IN A 141.0.170.144 ns2 IN A 141.0.170.145 www IN CNAME servermom.com. mail IN A 141.0.170.144 ftp IN CNAME servermom.com. servermom.com. IN TXT "v=spf1 ip4:141.0.170.144 a mx ~all" mail IN TXT "v=spf1 a -all"
If you have two IPs, you can replace “ns2 IN A xxx.xxx.xxx.xxx” with your second IP address. Otherwise simply use the same IP.
Once done editing, hit Control+O to save that file then hit Control+X to exit Nano editor.
Next step, it’s time to define reverse DNS lookup. Sounds not so familiar? Don’t worry simply repeat my steps. Type this command syntax:
nano /etc/bind/zones/rev.3.2.1.in-addr.arpa
That will open Nano editor screen again but this time you will edit another file. Add following lines inside that file..
@ IN SOA domain.com. host.domain.com. ( 2010081401; 28800; 604800; 604800; 86400 ); IN NS ns1.domain.com. 4 IN PTR domain.com.
Replace “host.domain.com” with your own server’s host name. Once done, press Control+O to save followed by Control+X to exit.
Example:
@ IN SOA servermom.com. host.servermom.com. ( 2010081401; 28800; 604800; 604800; 86400 ); IN NS ns1.servermom.com. 4 IN PTR servermom.com.
screenshot:
That’s not done yet. There is another file you have to edit. Run this command:
nano /etc/resolv.conf
Now add following line at very top of any lines you see there:
search domain.com
Example:
Once done, press Control+O to save followed by Control+X to exit. That is it. But to make sure that Bind9 can apply all recent changes above, you better restart Bind9 service using this command:
/etc/init.d/bind9 restart
To conclude, in your Putty screen it will show all the command syntax used which is something like this:
Step 4. Change Nameserver In Your Domain Registrar
I will not explain this last step because the way it can be done is really vary. It depends on which registrar you purchased the domain from. E.g: GoDaddy, NameCheap, Name, and so on.
The key point is to add ns1.domain.com and ns2.domain.com there. Once done, wait for about 24 hours for your domain to resolve to your server but sometimes it takes faster and done within few hours.
You can confirm it easily via web browser then type your newly configured domain name:
Step 5. Test Your DNS
In this case lets install additional tool called “DNS Utility”. Here’s how to install it:
apt-get install dnsutils
Once the install process finished, type following command:
dig domain.com
If everything is set correctly you’ll see something like this one below..
You can also test it using third-party service like Pingdom.com DNS test tool here.
Amazing post, a clear and direct howto… Thank you very much!
I agree, yet it is missing one thing, forwarding the port. The “internet” can’t see it without forwarding that port to the router
You should add that to the article.
Hey, thanks for this amazing website…
I followed all the steps, and everything looks fine.
But, when I try to update the nameservers of my domain.com on Godaddy, (with dns1.domain.com and dns2.domain.com) I get “You must enter a registered nameserver.”
1- Do I have to wait some time so server propagate?
2- Do I have to have 2 different IPs?
1- Do I have to wait some time so server propagate? YES
2- Do I have to have 2 different IPs? NO. You can use 1 IP
You will have to add the child name servers which will point to your IP address. Add 2 child name servers ( ns1. yourdomain.com, ns2.yourdomain.com ) and point both to same IP.
Hello There. I discovered your blog the use of msn. That is a really smartly written article. I will make sure to bookmark it and come back to read extra of your helpful information. Thanks for the post. I will definitely return.
You have written 4 IN PTR domain.com ? Elaborate this please
Hello
When i try to update ты servers for my domain i see this message:
http://joxi.ru/ZudaUtg5CbAxeMWBuQM
Red message in english: IP addresses should be unique
My VDS on digitalocean.com
Excellent post. Help me a lot and save me a lot of time.
Thanks!
I get a 500 internal error code in the browser when i setup LEMP+ WordPress using the tuxlite script. I restart nginx i
Thank you so much for this article! I was able to get bind9 working and my domain pointed in literally less than 5 minutes. It took longer to find this post!
thank’s mom, it works for me 🙂
it simply rocks, thank’s !!!
Thank you for the great guide. I’m a webdevelopment baby not yet weaned. I’d appreciate it if you could answer a couple of questions.
I used django, postgres, apache, mod_wsgi on ubuntu 12.04 to successfully run my website on localhost. I’ve purchased a domain with godaddy, and now I’m in the process of trying to point that to the static IP address of my ubuntu system. And I followed your directions to do that, but dig is not returning my IP. Maybe I made mistakes in some areas, and so here’s my questions:
1. In “3.2.1.in-addr.arpa” does “3.2.1” need to be replaced with my reverse IP address? For example, if my IP is w.x.y.z, change it to y.x.w?
2. You said “host.servermom.com” is my server’s hostname. My hostname in /etc/hostname is currently “django-svr”; is this what I change it to? or should it be “djang-svr.servermom.com”?
Hi I had a question about, how can you access your server directly with internet?
I mean, How you get your public ip for your server?
thanks
Did you mean how to access your server directly via IP on your web browser? If so, simply edit your virtual hosts file (apache) or edit your nginx .conf file if it is on nginx 🙂
Do I have to configure a domain.db template and rev.3.2.1.in-addr.arpa for every site I add?
What is the best solution in this case?
Does Zpanel can be installed after i followed the tutorial install LAMP and LNMP Stack On Ubuntu?
Thanks 🙂
Great tut!
I have one questions… if i add more than one site i have to add each site on the template nano /etc/bind/named.conf.local or tuxlite will do it for me?
AFAIK, tuxlite does not have DNS management feature so you have to do that by yourself. 🙂 Confused? Why don’t you try using third-party -and free- DNS provider like CloudFlare or CloudNS.net 🙂
I just install tuxlite in my new domain with your tutorial. Thanks.
But I need to create sub domain, can you tell me how?
I think you can just follow the same steps but enter your subdomain instead your main domain
Very very good post , thansk
Rekomdasi untuk layanan dns murah apa mbak? Terima kasih.
I have working everithing what u have write in this tutorial but i’t not working …
root@test:/etc/bind# dig amd-electronics.ba
; <> DiG 9.8.1-P1 <> amd-electronics.ba
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 28476
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;amd-electronics.ba. IN A
;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Tue May 27 18:39:33 2014
;; MSG SIZE rcvd: 36
Hello bu, saya sudah coba tutorial ini di VPS dan berhasil. VPS saya dapat 1 IP jadi 1 IP ini untuk namaserver ns1.domain.com dan ns2.domain.com yg pointing ke IP yg 1 itu. Nah, saya mau install website baru (jadi totalnya mau 2 website di satu VPS ini), itu nameserevr yg satunya lagi gimana? Apa saya harus menggunakan nameserver yg sudah saya pakai pada website pertama? Thanks.
Hi please help me ,
have installed the bind9 in Ubuntu, it was successful in install and able to see the bind9 running,
then did a config based on my needs, now am not able to restart the bind.
please check the syslog am getting , it says some file permission issue,
6 20:22:56 telxsi-desktop named[19659]: automatic empty zone: 9.E.F.IP6.ARPA
Jul 16 20:22:56 telxsi-desktop named[19659]: automatic empty zone: A.E.F.IP6.ARPA
Jul 16 20:22:56 telxsi-desktop named[19659]: automatic empty zone: B.E.F.IP6.ARPA
Jul 16 20:22:56 telxsi-desktop named[19659]: automatic empty zone: 8.B.D.0.1.0.0.2.IP6.ARPA
Jul 16 20:22:56 telxsi-desktop named[19659]: command channel listening on 127.0.0.1#953
Jul 16 20:22:56 telxsi-desktop named[19659]: command channel listening on ::1#953
*******Jul 16 20:22:56 telxsi-desktop named[19659]: isc_stdio_open ‘/var/log/syslog’ failed: permission denied
Jul 16 20:22:56 telxsi-desktop named[19659]: configuring logging: permission denied
Jul 16 20:22:56 telxsi-desktop named[19659]: loading configuration: permission denied*******
Jul 16 20:22:56 telxsi-desktop named[19659]: exiting (due to fatal error)
Absolutely brilliant tutorial. For me, as a novice this is the definitive reference guide on how to setup my DNS.
The tutorial was well detailed an easy to follow. Thank you for taking the time to put this on the internet. 🙂
a ttodos los amigos foristas estos programadores que hacen estos programas quriendo imitar a windox son unos pobre diablos ni ellos mismo no an podido arreglar estos errores de montar un servidores publicos
We have network environment
Internet >>Cyberoam Router ….>>Switch…>>Ubuntu Server with Bind9 dns server installed.
Have configured the domain settings.
ISP IP is configured in router , registered the hosts ns1.domain.in & ns2.domain.in @ godaddy.
then used these nameservers
in domain.in.db file have to add the ns enteries with Ubuntu server local IP address ..right instead of Public ISP IP address.
Regards,
Vijay Kadadi
In “3.2.1.in-addr.arpa” does “3.2.1″ mean the reverse order of DNS IP from ISP from example for me 196.46.100.2 => 100.46.196 or the exact public ip my server example for me: 41.59.4.45 => 4.59.41 ?
The best tutorial that l have seen so far
l have only one question, as you mentioned here in the last words ” Change Nameserver In Your Domain Registrar ” because l don’t get my page with domain name ?
Hi Sawiyati, I have been following your posts for a while now.
I am a beginner in web development, and i just set up a fully functionnal web server. However, when i try to add ns1.[mydomain].fr in my domain registrar (I registered my domain at namecheap), namecheap throwed the following lines : “Unable to Update Nameservers
We encountered some issues when setting nameservers. The reported problem is: 3031166 Command failed – – 504 Missing required attribute; GLUE REQUIRED FOR HOST [ns1.serveurbronx.fr]”
Did you ever encountered such problems ?
Thanks in advance and keep the good work !
Greetings from France
Unfortunately I never experienced such problem. Have you asked their CS?
Hi There,
Assuming i have two nameserver namely ns1 & ns2, both of these server will have public ip address;
ns1 : 210.x.x.143
ns2 : 122.y.y.147
ns1 is located outside my office, where ns2 in located in the office.
Both of these ns1 & ns2 are also configured to run mail services.
mx1 : 210.x.x.143
mx2 : 122.y.y.147
How would i configure the zone files? Can you please help me?
Thank you. 😉
I’d just like to say thanks for this and all other posts you make. It is very helpful and easy to understand.
Please keep up the amazing work you’re doing 🙂
thank you so much you helped me with my project i appreciate your work
Please how to I configure two or more domain names using the same Ip address?
Hello,
I have installed Cpanel on my server. I want to host my website on that server. I do not know, what is the name server of my server. and how to update it? can you help me on that?
thank you great tut mom !
Very simple and clean! Thanks a lot, I spent two hours finding a decent tutorial.
Thank you
Hi Sawiyati.You explained everything very good but i’m stuck on nameservers.Please make it more clear with examples.I dont know where to find those nameservers and how to change them in domain…
If what you mean is to setting up nameserver in your domain, then that will be different according to which registrar you bought your domain from.
Thank you for this post. Your instructions helped me to point my domain to my Ubuntu server.
Hi Sawiyati… It’s really nice post and helpful. I want to ask about how to add secondary/another domain to our server.
Example: I have domain1.com with ns1.domain1.com & ns2.domain2.com. I want to add domain2.com that will point to ns1.domain1.com & ns2.domain1.com.
How to do this? Do we need to add another master zone in bind?
Suppose I have created one domain with this step and hosted it using your another post. Let’s say abc.com. So nameservers will be ns1.abc.com.
Next I need to host another website (xyz.com) on the same vps server using ns1.abc.com as nameserver. So do I need to follow this same step or what will be the changes?
Please help me, that ip thoughts, local (192.168… ) or public (fixed iP 89.111….)???
The question refers to this “Also, you have to replace xxx.xxx.xxx.xxx with IP address of your server.”?
hello;
i suppose u to help me in:
how to connect a DHCP with the DNS and configure them.
How to use many NS on VULTR mom?.
You can check on https://help.ubuntu.com/lts/serverguide/dns-configuration.html
Amazing post, I get important thing
nano /etc/resolv.conf
will be shown ;
1. search yourdomain.com
2. # nameserver 2001:14f0:200:1704::6
3. nameserver 8.8.8.8
don’t forget to change 8.8.8.8 with original IP
my resolve.conf file is like this :
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND — YOUR CHANGES WILL BE OVERWRITTEN
nameserver 217.218.127.127
nameserver 4.2.2.4
now how should be then ?
Hi Sawiyati,
Thank You for this very informative website.
I was able to setup my home server through your guides.
I am also able to access my website on the internet using my public IP.
My problem though, I am not able to access my website through the internet if I type my domain name. Locally, I am able to access it using the domain name I set. Is there a special setup to make my domain name work through the internet?
Thank You and Regards,
kurusuchan
is your home public IP can really be accessed through internet? Is your home IP a static or a dynamic one? If so, you may need something like Dynamic DNS which you better or simply use third-party DNS hosting service. Don’t worry, there are several free ones out there. Check this: List of free DNS hosting providers.
Hi Sawiyati,
Yes, my home public IP can be accessed through the net. My IP is static. I will try free DNS hosting providers.
Thank You very much,
kurusuchan
Awsome! Your great tutorial saved my day 🙂 The other tutorials I went through today were either outdated, written for local domains, wrong or too difficult to understand. I’ve got confused until I found this blog where things are explained clear and easy to understand. A big THANK YOU 🙂
Excellent post
I have one doubt , I need to setup only rdns for example
xxx.xxx.xxx.xxx test1.mydomain.com
yyy.yyy.yyy.yyy test2.mydomain.com
xxx and yyy are additional ip’s ,
can you tell me how can I do that
Please suggest
thanks for tutorial. i have added reverse DNS as said in this tutorial. but all my emails (config via postfix) goes to spam box of gmail. i tried http://www.allaboutspam.com and the result was :
Reverse DNS does not exist for Email server. Ask your ISP to set reverse DNS for Email server IP to match your Mail server Host name (in FQDN format).
as i config reverse DNS why this error raised?
What are the steps for adding a sub-domain after accomplishing this? I have just added virtual-hosts but it is not working.