What is DNS?
DNS stands for "Domain Name System" (server) and is a service that translates domain names to IP addresses and back. Everytime you write google.com in your browser, the request is sent to your main DNS server and translated. The answer, which contains the IP address, is then sent back to your computer so that you can reach your destination. If your main DNS server can't resolve the query (request), it will send it to one of it's forwarding DNS servers to attempt to solve the request. If the next server can't solve it, it will send it to the next one, and so on and so forth.
Installing the DNS server
In this tutorial I will use bind9. Therefore, invoke the following command:
(Don't forget you have to be root to do this, sudo su)
Quote: |
apt-get install bind9 |
Configuring the server
First of all, you have to edit the config file named "named.conf.local". There is a file called "named.conf", but since it's already pre-configured in most cases, you can leave it be. if it, however, is not configured, you will have to edit that one instead (named.conf that is).
Anyway, here we go....
If the named.conf is already configured, it should look something like this:
Quote: |
// prime the server with knowledge of the root servers zone "." { type hint; file "/etc/bind/db.root"; }; // be authoritative for the localhost forward and reverse zones, and for // broadcast zones as per RFC 1912 zone "localhost" { type master; file "/etc/bind/db.local"; }; zone "127.in-addr.arpa" { type master; file "/etc/bind/db.127"; }; zone "0.in-addr.arpa" { type master; file "/etc/bind/db.0"; }; zone "255.in-addr.arpa" { type master; file "/etc/bind/db.255"; }; include "/etc/bind/named.conf.local"; |
If it doesn't look like this, then do editing in the named.conf from here on. If it however looks like this, then you should edit named.conf.local, easy to follow ey?
Anyway, now you have to edit the file called named.conf.local:
Quote: |
nano /etc/bind/named.conf.local |
Quote: |
zone "teresa" { type master; file "/etc/bind/zones/teresa.db"; }; zone "0.0.168.192.in-addr.arpa" { type master; file "/etc/bind/zones/rev.0.168.192.in-addr.arpa"; }; |
zone: This is the zone that the server will refer to for the domains, basically put in your domain name where it says "teresa" (teresa is my server). The second zone is for the reverse lookup. There is a lot to read about zones. This tutorial will not cover much about zones, but if you want to know more then you can refer to the following page:
Quote: |
http://www.bind9.net/manual/bind/9.3.2/Bv9ARM.ch01.html#id2546579 |
type: It's either master or slave. The master is the first DNS that will be used, and in case it breaks down or "something" happens for some reason, then the slave server would still be there to server it. We will only create the master server in this tutorial though.
file: zone definition file. This is where all the zone information is held, with all the domain info, addresses and so on.
0.0.168.192.in-addr.arpa: is the reverse address, and in this case my network address is 192.168.0.0, which means that I should write 0.0.168.192 as the zone name for the reverse lookup.
Now, save the file with "CTRL + O" and then exit to bash with "CTRL + X". Now you have to edit the file called named.conf.options in the same folder, and to do so, invoke the following command:
Quote: |
nano /etc/bind/named.conf.options |
Quote: |
options { directory "/var/cache/bind"; // If there is a firewall between you and nameservers you want // to talk to, you might need to uncomment the query-source // directive below. Previous versions of BIND always asked // questions using port 53, but BIND 8.1 and later use an unprivileged // port by default. //query-source address * port 53; // If your ISP provided one or more IP addresses for stable // nameservers, you probably want to use them as forwarders. // Uncomment the following block, and insert the addresses replacing // the all-0's placeholder. forwarders { 193.111.152.2; }; auth-nxdomain no; # conform to RFC1035 listen-on-v6 { any; }; }; |
Note that the line "query-source address * port 53;" is commented in this config, which means that if you have a firewall on the server, you will have to uncomment it since it will use random ports without it.
forwarders: a DNS server that you forward requests to, for example if you setup this DNS as your main home DNS server, you would want a forwarding DNS to your ISP for example, so that if your DNS can't solve a DNS request (like google.com), it will send it to the next server, which is the forwarding address.
There, now save the file and exit to bash. Now it's time to create the zone definition files.
Quote: |
mkdir /etc/bind/zones nano /etc/bind/zones/teresa.db |
create the directory and edit the file.
Quote: |
teresa. IN SOA ns1.teresa. admin.teresa. ( // Do not modify the following lines! 2006081401 28800 3600 604800 38400 ) // Replace the following line as necessary: // ns1 = DNS Server name // mta = mail server name // example.com = domain name teresa. IN NS ns1.teresa. teresa. IN MX 10 mta.teresa. // Replace the IP address with the right IP addresses. www IN A 192.168.0.6 mta IN A 192.168.0.6 ns1 IN A 192.168.0.6 |
ns1: Stands for "name server 1", which is the DNS server.
mta: Stands for mail transfer agent, which basically is another name for SMTPD (Simple Mail Transfer protocol Deamon).
www: world wide web third-level domain name. Yeah you should know what that is and what it's used for.
MX: The MX record stands for "mail exchange" and is a special domain record for routing mail.
A: Stands for "Address Record", and is a record that simply returns a 32-bit IPv4 address.
SOA: Contains information about the DNS zone, the primary ma,e server, email of the domain administrator, the domain serial number, and timers that are meant for zone refreshing.
If you want to read more about the different record types, then go here:http://en.wikipedia.org/wiki/A_record#A
Quote: |
www IN A 192.168.0.6 |
can basically be described as follows:
Quote: |
domain IN record address |
now, when you are done, save the file and exit to bash. Now you have to edit the create and edit the file.
Quote: |
nano /etc/bind/zones/rev.0.168.192.in-addr.arpa |
Quote: |
@ IN SOA ns1.teresa. admin.teresa. ( 2006081401; 28800; 604800; 604800; 86400 ) IN NS ns1.teresa. 1 IN PTR teresa |
PTR: Points towards the hostname, and is often used in reverse lookups. as in, you ask for an IP's hostname, instead of the other way around.
Now, all you have to do is save the file and exit to bash, and restart bind to make the new changes load.
Quote: |
/etc/init.d/bind9 restart |
Slow resolutions?
Sometimes your server might resolve the requests slowly. To fix this you can try to disable IPv6 by editing the following file:
Quote: |
nano /etc/default/bind9 |
Quote: |
OPTIONS="-4 -u bind" RESOLVCONF=yes |
There, save and exit to bash...
ليست هناك تعليقات:
إرسال تعليق