Setting up a DNS server using BIND in Linux - nijil/erpnext GitHub Wiki
Lets see how to setup a basic DNS( Domain Name System)server in a Linux environment.I am on Ubuntu 10.10 and using BIND distribution for the DNS server.If you are going to setup a DNS Server for a production environment I suggest you do it on a stripped down version suited for servers with only the minimum required services running.(Cent OS is what we use). If you are doing it for fun then Ubuntu is more than enough.For those of you who are not familiar with DNS and its terminology lets do a quick crash course before we get our hands dirty as we are likely to come across these a lot.(Advanced users might want to skip that part).
- *What is a Domain Name System ?
- Wiki says "The Domain Name System (DNS) is a hierarchical distributed naming system for computers, services, or any resource connected to the Internet or a private network."Take note of the word distributed. Lets look at an example. Suppose I want to register a domain: 'www.domain-for-me.com'. I go to any domain selling website, pay a small amount and I buy one if its available. Now I can either host it using any online hosting website for a fee or I can host it in my server.Either ways you have to register an IP associated with your domain. When you do so what happens is that your Service provider/whoever you registered your domain with adds a new DNS records ( will explain what a record is later) in its DNS server which is registered with a central authority( aka ICANN). So the next time some one types your domain address 'www.domain-for-me.com' into their browser, it will check with the DNS registry, find this domain entry, figure out its mapped IP and fetch the page from that IP address.
*Why would you require your own DNS server ? Imagine a LAN network with local domains.You can have your own local 'www.google.com' redirected to whatever you want( that would be stupid though - am just saying its possible), you could have sub domains mapped to different terminal etc etc. Another scenario would be if you have to manage multiple sub domains and Mail Servers over the net, it makes more sense to have your own DNS server than depending on your Service provider.All you have to do is get your DNS server registered to the central authority so that the mappings stored inside are visible on the Internet.Care should also be taken to properly manage and secure these servers.
*Zone files and Records It is a text file storing the details usually of a single domains and the IP maps available for that domain.The naming conventions for a zone file is db.domainname - so in our case it would be db.domain-for-me.com.Following would be a sample zone file.
- domain-for-me.com. IN SOA ns1.domain-for-me.com. id.mail.com. (
-
2006081401;serial number of this zone- DONT MODIFY THESE LINES
28800;slave refresh time- All in seconds
3600;slave retry time
604800
38400
) domain-for-me.com. IN NS ns1.domain-for-me.com.
domain-for-me.com. IN MX 10 mta.domain-for-me.com.
www IN A 192.168.0.106
subdom IN A 192.168.0.3
ns1 IN A 192.168.0.106
subdom1 IN A 192.168.0.106
; Replace the following line as necessary: ; ns1 = DNS Server name ; mta = mail server name ; domain-for-me.com = domain name ;MAKE SURE YOU ADD THE '.' AT THE END ;Replace the IP address with the right IP addresses.
We have different type of records namely 'A','CNAME','NS','MX','PTR' and some more.These are the most commonly encountered one's.In this 'NS' is a name-space record and the mapping will be used for assigning it as a name server. 'MX' is used for mapping the mail server. An 'A' record is a direct IP map to any sub domain mapping.A 'CNAME' record is alias map for any defined name.Here id.mail.com is the email id of the DNS Server admin and the '@' is replaced by a '.'.
If you want to know more about underlying DNS working principles please go through this amazing link http://www.zytrax.com/books/dns/
Setting up BIND 9
- 1:Open Terminal
- sudo apt-get update sudo apt-get install bind9
2:This should also install dnsutils along with it - If any dependency error shows up install those packages also using same -> sudo apt-get install 'whatever-package'
3:Setting up apache also would be: good idea if you want to test it on the same server.
4:Following are the bind config files /etc/bind/named.conf /etc/bind/named.conf.options /etc/bind/named.conf.local You can include the 2nd and 3rd in named.conf which is the main file from which the zones get loaded. 5:Setting up forwarder or caching servers : If certain queries cannot be resolved by your DNS server, we set up servers where the requests will get redirected to.Add this in in your named.conf.options. forwarders{ 8.8.8.8 ;or any ISP DNS server or public DNS server 8.8.4.4 }; 6:Also add directory options in the above file: directory "/etc/bind"; So finally it will look like
- options {
- forwarders { 8.8.4.4; 8.8.8.8; }; directory "/etc/bind"; managed-keys-directory "/etc/bind";
};
7:Create a folder for your zone files and ideally place it under /etc/bind/zones/
8:Now its time to edit the named.conf file.
- zone "domain-for-me.com" {
type master; file "/etc/bind/zones/db.domain-for-me.com";};
we are specifying this as our master.There are other options too like allow-update, allow-query etc.Lets keep it at minimum to get our DNS server up and running first and later add as many options as you want.
9: // Will add the rest soon
NOT COMPLETE