The Domain Name System

The DNS translates Internet domain and host names to IP addresses. DNS automatically converts the names we type in our Web browser address bar to the IP addresses of Web servers hosting those sites.

DNS implements a distributed database to store this name and address information for all public hosts on the Internet. DNS assumes IP addresses do not change (are statically assigned rather than dynamically assigned).

The DNS database resides on a hierarchy of special database servers. When clients like Web browsers issue requests involving Internet host names, a piece of software called the DNS resolver (usually built into the network operating system) first contacts a DNS server to determine the server's IP address. If the DNS server does not contain the needed mapping, it will in turn forward the request to a different DNS server at the next higher level in the hierarchy. After potentially several forwarding and delegation messages are sent within the DNS hierarchy, the IP address for the given host eventually arrives at the resolver, that in turn completes the request over Internet Protocol.

DNS additionally includes support for caching requests and for redundancy. Most network operating systems support configuration of primary, secondary, and tertiary DNS servers, each of which can service initial requests from clients. Internet Service Providers (ISPs) maintain their own DNS servers and use DHCP to automatically configure clients, relieving most home users of the burden of DNS configuration.

History
Using a simpler, more memorable name in place of a host's numerical address dates back to the ARPANET era. The staff at Stanford Research Institute created and updated a file named Hosts.TXT that mapped intelligible names to the numerical addresses of computers on ARPANET. SRI transmitted this file, and updates of this file, to each computer connected to ARPANET, which later became the Internet The Internet's rapid growth required an automated system for maintaining and distributing domain names and their corresponding numerical addresses, to replace SRI's centrally maintained, manually entered Hosts.TXT file.

The original UNIX implementation was done by four graduate students in Berkeley in 1984. It was then added to Berkeley UNIX distribution in the mid 1985 and known as BIND (Berkeley Internet Name Domain). It is a open source project.

Bind is available for UNIX/Linux as well as Windows. Since the DNS protocol is standardized. UNIX and non-UNIX DNS implementations can all inter-operate and share data.

In the beginning, BIND was the only DNS implementation in widespread use. Today there are several;
  • BIND, author is ISC.
  • NSD, author is NLnet Labs.
  • PowerDNS, author is PowerDNS BV.
  • djbdns, author is Danbernstein.
  • Microsoft DNS, author is Microsoft.
  • ANS, CNS author is Nominum.
DNS defines;
  • A hierarchical name space for hosts and IP addresses.
  • A distributed database of host name and address information.
  • A resolver to query this database.
  • Improved routing for email.
  • A mechanism for finding services on a network.
  • A protocol for exchanging naming information.
DNS is a client/server system. Servers load the data from your DNS files into memory and use it to answer queries both from internal clients and from clients and other servers out on the Internet.

The DNS Name space.

The DNS name space is an important part of DNS, as it gives an understanding of why domain names look the way they do, and how DNS works. The namespace refers to the hierarchical layout of DNS names; the DNS namespace is laid out in an inverted tree. This means the root of the tree is at the top, and the branches of the tree grow downwards. At the top of the DNS namespace is the root (dot); all domain names start at the root which is defined by a null character. Note that domain names read from right to left, that is the highest level of the name space, the root, is the furthest right portion of the DNS name. The root is not normally explicitly specified in user applications, as most applications assume it. It is often explicitly specified in DNS server configuration files and is denoted by a trailing period. Below the root in the DNS namespace, are the top level domains or TLDs. These are the highest names in the name space, for example, .com or .net. These TLDS are maintained by the Internet corporation for assigned names and numbers, or ICAN, for Internet use. 

The DNS name space is organized into a tree structure, each domain name corresponds to a node in the tree. One branch of the DNS naming tree maps host names to IP addresses called the forward mapping, data file associated with it are called forward zone files. The second branch maps IP addresses back to host names called reverse mapping and its data files called reverse zone files. 

In the USA, top level domains originally described organizational and political structure were given three letter names such as com or edu. Some of these domains are used outside the USA as well, they are called generic top-level domains or gTLDs for short.

The top level domains were fixed by ICANN. Most important gLDs,

.eduUSA educational Institutions
.govUSA governmental
.milUS military

.aero air-transport industry
.asia Asia-Pacific region
.biz business
.cat Catalan
.com commercial
.coop cooperatives
.info information
.int international organizations
.jobs companies
.mobi mobile devices
.museum museums
.name individuals, by name
.net network
.org organization
.post postal services
.pro professions
.tel Internet communication services
.travel travel and tourism industry related sites
.xxx adult entertainment

Country code Top-Level Domain.



.ac
Ascension Island
.ci
Cote d'Ivoire
.ad
Andorra
.ck
Cook Islands
.ae
United Arab Emirates
.cl
Chile
.af
Afghanistan
.cm
Cameroon
.ag
Antigua and Barbuda
.cn
People's Republic of China
.ai
Anguilla
.co
Colombia
.al
Albania
.cr
Costa Rica
.am
Armenia
.cs
Czechoslovakia
.an
Netherlands Antilles
.cu
Cuba
.ao
Angola
.cv
Cape Verde
.aq
Antarctica
.cx
Christmas Island
.ar
Argentina
.cy
Cyprus
.as
American Samoa
.cz
Czech Republic
.at
Austria
.dd
East Germany
.au
Australia
.de
Germany
.aw
Aruba
.dj
Djibouti
.ax
Åland
.dk
Denmark
.az
Azerbaijan
.dm
Dominica
.ba
Bosnia and Herzegovina
.do
Dominican Republic
.bb
Barbados
.dz
Algeria
.bd
Bangladesh
.ec
Ecuador
.be
Belgium
.ee
Estonia
.bf
Burkina Faso
.eg
Egypt
.bg
Bulgaria
.eh
Western Sahara
.bh
Bahrain
.er
Eritrea
.bi
Burundi
.es
Spain
.bj
Benin
.et
Ethiopia
.bm
Bermuda
.eu
European Union
.bn
Brunei
.fi
Finland
.bo
Bolivia
.fj
Fiji
.br
Brazil
.fk
Falkland Islands
.bs
Bahamas
.fm
Federated States of Micronesia
.bt
Bhutan
.fo
Faroe Islands
.bv
Bouvet Island
.fr
France
.bw
Botswana
.ga
Gabon
.by
Belarus
.gb
United Kingdom
.bz
Belize
.gd
Grenada
.ca
Canada
.ge
Georgia
.cc
Cocos (Keeling) Islands
.gf
French Guiana
.cd
Democratic Republic of the Congo
.gg
Guernsey
.cf
Central African Republic
.gh
Ghana
.cg
Republic of the Congo
.gi
Gibraltar
.ch
Switzerland
.gl
Greenland
.gm
The Gambia
.lc
Saint Lucia
.gn
Guinea
.li
Liechtenstein
.gp
Guadeloupe
.lk
Sri Lanka
.gq
Equatorial Guinea
.lr
Liberia
.gr
Greece
.ls
Lesotho
.gs
South Georgia and the South Sandwich Islands
.lt
Lithuania
.gt
Guatemala
.lu
Luxembourg
.gu
Guam
.lv
Latvia
.gw
Guinea-Bissau
.ly
Libya
.gy
Guyana
.ma
Morocco
.hk
Hong Kong
.mc
Monaco
.hm
Heard Island and McDonald Islands
.md
Moldova
.hn
Honduras
.me
Montenegro
.hr
Croatia
.mg
Madagascar
.ht
Haiti
.mh
Marshall Islands
.hu
Hungary
.mk
Macedonia
.id
Indonesia
.ml
Mali
.ie
Ireland
.mm
Myanmar
.il
Israel
.mn
Mongolia
.im
Isle of Man
.mo
Macau
.in
India
.mp
Northern Mariana Islands
.io
British Indian Ocean Territory
.mq
Martinique
.iq
Iraq
.mr
Mauritania
.ir
Iran
.ms
Montserrat
.is
Iceland
.mt
Malta
.it
Italy
.mu
Mauritius
.je
Jersey
.mv
Maldives
.jm
Jamaica
.mw
Malawi
.jo
Jordan
.mx
Mexico
.jp
Japan
.my
Malaysia
.ke
Kenya
.mz
Mozambique
.kg
Kyrgyzstan
.na
Namibia
.kh
Cambodia
.nc
New Caledonia
.ki
Kiribati
.ne
Niger
.km
Comoros
.nf
Norfolk Island
.kn
Saint Kitts and Nevis
.ng
Nigeria
.kp
Democratic People's Republic of Korea
.ni
Nicaragua
.kr
Republic of Korea
.nl
Netherlands
.kw
Kuwait
.no
Norway
.ky
Cayman Islands
.np
Nepal
.kz
Kazakhstan
.nr
Nauru
.la
Laos
.nu
Niue
.lb
Lebanon
.nz
New Zealand
.om
Oman
.tc
Turks and Caicos Islands
.pa
Panama
.td
Chad
.pe
Peru
.tf
French Southern & Antarctic lands
.pf
French Polynesia
.tg
Togo
.pg
Papua New Guinea
.th
Thailand
.ph
Philippines
.tj
Tajikistan
.pk
Pakistan
.tk
Tokelau
.pl
Poland
.tl
East Timor
.pm
Saint-Pierre and Miquelon
.tm
Turkmenistan
.pn
Pitcairn Islands
.tn
Tunisia
.pr
Puerto Rico
.to
Tonga
.ps
State of Palestine[20]
.tp
East Timor
.pt
Portugal
.tr
Turkey
.pw
Palau
.tt
Trinidad and Tobago
.py
Paraguay
.tv
Tuvalu
.qa
Qatar
.tw
Taiwan
.re
Réunion
.tz
Tanzania
.ro
Romania
.ua
Ukraine
.rs
Serbia
.ug
Uganda
.ru
Russia
.uk
United Kingdom
.rw
Rwanda
.us
United States of America
.sa
Saudi Arabia
.uy
Uruguay
.sb
Solomon Islands
.uz
Uzbekistan
.sc
Seychelles
.va
Vatican City
.sd
Sudan
.vc
Saint Vincent and the Grenadines
.se
Sweden
.ve
Venezuela
.sg
Singapore
.vg
British Virgin Islands
.sh
Saint Helena
.vi
United States Virgin Islands
.si
Slovenia
.vn
Vietnam
.sj
Svalbard and Jan Mayen Islands
.vu
Vanuatu
.sk
Slovakia
.wf
Wallis and Futuna
.sl
Sierra Leone
.ws
Samoa
.sm
San Marino
.ye
Yemen
.sn
Senegal
.yt
Mayotte
.so
Somalia
.yu
SFR Yugoslavia, FR Yugoslavia
.sr
Suriname
.za
South Africa
.ss
South Sudan
.zm
Zambia
.st
São Tomé and Príncipe
.zw
Zimbabwe
.su
Soviet Union


.sv
El Salvador


.sx
Sint Maarten


.sy
Syria


.sz
Switzerland




DNS Configuration.
Port 53 is used for DNS. Here we describe the basic setup for BIND and PowerDNS.

BIND.
BIND is an implementation of the Domain Name System (DNS) protocols. The name BIND stands for “Berkeley Internet Name Domain”, because the software originated in the early 1980s at the University of California at Berkeley. In recent years, the word BIND has become, like “radar” and “laser”, more word than acronym.
The DNS protocols are part of the core Internet standards. They specify the process by which one computer can find another computer on the basis of its name. ‘An implementation of DNS protocols’ means our software distribution contains all of the software necessary for asking and answering name service questions.
The BIND software distribution has three parts:
A Domain Name System server
A program called “named” (pronounced “name-dee”), which stands for Name Daemon, answers all received questions by following the rules specified in the DNS protocol standards. You can provide DNS services on the Internet by installing this software on a server computer and giving it correct information about your domain names.
A Domain Name System resolver library
resolver is a program that resolves questions about names by sending those questions to appropriate servers and responding appropriately to the servers’ replies. A resolver library is a collection of software components that a programmer can add to software being developed, which will give that software the ability to resolve names. For example, a programmer who was programming a new web browser does not need to create the part of it that looks up names in DNS; he or she can plug in the resolver library and then send questions to the library software components. This saves time (the programmer does not need to re-invent that particular wheel) and helps ensure that the new browser correctly follows the DNS standards.
Software tools for testing servers
These are the tools we use, and we include them in the distribution to assist you with your own diagnostics.
When you install an operating system on your computer, that operating system will contain whatever resolver library its developers selected for it. When you set up a server computer, its vendor usually has provided some DNS server software (usually BIND) so that the server will work as delivered. Because BIND faithfully implements the DNS protocols, there is no need for the resolver (which asks questions) and the server (which answers questions) to be running the same software.

Install BIND
root@debian:#apt-get install bind

  • Edit named file.
root@debian:#nano /etc/bind/named.conf
On the last part can see one line include "/etc/bind/named.conf.local"; Use Ctrl + K (Cut) the line and use Ctrl +U to paste it twice. Now change the name to preffered one.
include "/etc/bind/named.conf.local";
include "/etc/bind/growwithlinux.com.conf";
  • Copy named.conf to growwithlinux.com.conf
root@debian:#cp /etc/bind/named.conf /etc/bind.growwithlinux.com.conf
  • Edit growwithlinux.com.conf
root@debian:#nano /etc/bind/growwithlinux.com.conf
Keep the below part and delete rest all on that file.
zone "localhost" {
        type master;
        file "/etc/bind/db.local";
};

zone "127.in-addr.arpa" {
        type master;
        file "/etc/bind/db.127";
};

 Change the above file to

zone "growwithlinux.com" {
        type master;
        file "/etc/bind/growwithlinux.com.f";
};

zone "16.168.in-addr.arpa" {

        type master;
        file "/etc/bind/growwithlinux.com.r";

};
Here in forward zone give the prescribed data and in reserve zone give the network part of the IP address in reserve example the IP address In B Class is 168.16.56.29 just 16.168. If C Class IP address 192.168.29.50 just 29.168.192.


  • Copy the forward and reverse files.
root@debian:#cp /etc/bind/db.local /etc/bind/growwithlinux.com.f
root@debian:#cp /etc/bind/db.127 /etc/bind/growwithlinux.com.r


  • Edit the forward file.
root@debian:#nano /etc/bind/growwithlinux.com.f
;
; BIND data file for local loopback interface
;
$TTL    604800
@       IN      SOA     growwithlinux.com. root.growwithlinux.com. (
                                                                  2         ; Serial
                                                                 604800         ; Refresh
                                                                 86400         ; Retry
                                                                 2419200         ; Expire
                                                                 604800 )       ; Negative Cache TTL
;
@            IN      NS     growwithlinux.com.
               IN     MX0    mail.growwithlinux.com.
               IN      A       168.16.56.29
 www      IN      A        168.16.56.29
mail      IN     A        168.16.56.30
game   IN     A        168.16.56.31


  • Edit the reverse file
root@debian:#nano /etc/bind/growwithlinux.com.r
;
; BIND reverse data file for local loopback interface
;
$TTL    604800
@       IN      SOA    growwithlinux.com. root.growwithlinux.com. (
                                                               1         ; Serial
                                                               604800         ; Refresh
                                                               86400         ; Retry
                                                               2419200         ; Expire
                                                               604800 )       ; Negative Cache TTL
;
@       IN      NS      growwithlinux.com.
29.56   IN      PTR     growwithlinux.com.
29.56   IN      PTR     www.growwithlinux.com.
30.56   IN      PTR     mail.growwithlinux.com.
31.56   IN      PTR    game.growwithlinux.com.
  • Restart the Service 
root@debian:#/etc/init.d/bind restart

Don't forget to update the serial number and reload the name servers.
Don't forget to add dot at the end of the hostname in the PTR reverse entry.

For checking the DNS use;
#dig {address.com}

Install PowerDNS
PowerDNS is a DNS server, written in C++ and licensed under the GPL. It runs on most Unix derivatives. PowerDNS features a large number of different backends ranging from simple BIND style zonefiles to relational databases and load balancing/failover algorithms. A DNS recursor is also included as a separate program.PowerDNS is a product of the Dutch company PowerDNS.COM BV, with numerous contributions from the open source community. The principal author is Bert Hubert.
  • Database Configuration
Install MariaDB
# apt-get install MariaDB-server
# apt-get install MariaDB-client

Configure MariaDB
#nano /etc/my.cnf.d/server.conf
[server]
bind-address=127.0.0.1

# service mysql start
# /usr/bin/mysql_secure_installation

Create an sql script to create mariadb database for storing DNS records
# nano /root/pdns.sql
CREATE DATABASE pdb;
GRANT ALL ON pdb.* TO 'growwithlinux'@'localhost' IDENTIFIED BY 'password';
GRANT ALL ON pdb.* TO 'growwithlinux'@'localhost.localdomain' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;

CREATE TABLE domains (

id INT auto_increment,
name VARCHAR(255) NOT NULL,
master VARCHAR(128) DEFAULT NULL,
last_check INT DEFAULT NULL,
type VARCHAR(6) NOT NULL,
notified_serial INT DEFAULT NULL,
account VARCHAR(40) DEFAULT NULL,
primary key (id)
);
CREATE UNIQUE INDEX name_index ON domains(name);
CREATE TABLE records (
id INT auto_increment,
domain_id INT DEFAULT NULL,
name VARCHAR(255) DEFAULT NULL,
type VARCHAR(10) DEFAULT NULL,
content VARCHAR(64000) DEFAULT NULL,
ttl INT DEFAULT NULL,
prio INT DEFAULT NULL,
change_date INT DEFAULT NULL,
primary key(id)

);
CREATE INDEX nametype_index ON records(name,type);
CREATE INDEX domain_id ON records(domain_id);
CREATE TABLE supermasters (
ip VARCHAR(64) NOT NULL,
nameserver VARCHAR(255) NOT NULL,
account VARCHAR(40) DEFAULT NULL
);

Create database from sql script
#mysql -u root -p < /root/pdns.sql
  • PowerDNS Configuration.
Install PowerDNS
#apt-get install pdns pdns-backend-mysql

Configure mysql backend credentials in PowerDNS
#nano /etc/pdns/pdns.conf
launch=gmysql
gmysql-host=127.0.0.1
gmysql-user=padmin
gmysql-password=p1234
gmysql-dbname=pdb

Start PowerDNS
#service pdns start

Install Apache webserver
#apt-get install httpd

Install php
#apt-get install php php-devel php-gd php-imap php-ldap php-mysql php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt gettext php-pear-DB php-pear-MDB2-Driver-mysql

Configure Apache webserver
#nano /etc/httpd/conf/httpd.conf
ServerName 10.10.10.3:80

Start Apache webserver
#service httpd start

Check php configurations by looking at http://10.10.10.3/info.php after saving below file
#nano /var/www/html/info.php
<?php
phpinfo();
?>

Download PowerAdmin
# wget https://github.com/downloads/poweradmin/poweradmin/poweradmin-2.1.6.tgz
# tar -xvzf poweradmin-2.1.6.tgz
# cp -pr poweradmin-2.1.6 /var/www/html/poweradmin
# chown -R root:root /var/www/html/poweradmin

Login to PowerAdmin web install
http://10.10.10.3/poweradmin/install
Select option “I prefer to proceed in English” in installation step 1
Proceed to next page in installation step 2
Enter below details in installation step 3
Username=growwithlinux
Password=password
Database type=MySQL
Hostname=127.0.0.1
DB Port=3306
Database=pdb
Poweradmin administrator password=admin1234

Enter below details in installation step 4
Username=admin
Password=admin1234
Hostmaster=hostmaster.test.lab
Primary nameserver=ns1.test.lab
Secondary nameserver=ns2.test.lab

Run the sql query displayed in installation step 5 inside MariaDB
#mysql -u root -p

Save the contents printed on the page to /var/www/html/poweradmin/inc/config.inc.php in installation step 6

Remove install directory and login to poweradmin website using the specified link and credentials in installation step 7
# rm -rf /var/www/html/poweradmin/install
  • DNS Record Creation.
Create a master zone example.com and below records in it
www.growwithlinux.com A 192.168.10.10
internal.growwithlinux.com A 192.168.10.20
mail.growwithlinux.com MX internal.growwithlinux.com
chat.growwithlinux.com CNAME www.growwithlinux.com
192.168.10.20 PTR internal.growwithlinux.com

Install DNS client dig
# apt-get install bind-utils

Query PowerDNS server using dig to return above records
# dig @10.10.10.3 www.growwithlinux.com A
# dig @10.10.10.3 internal.growwithlinux.com A
# dig @10.10.10.3 mail.growwithlinux.com MX
# dig @10.10.10.3 chat.growwithlinux.com
# dig @10.10.10.3 192.168.10.20.growwithlinux.com PTR

Log in to MariaDB and show stored DNS records in database
# mysql -u root -p
mysql> use pdb;
mysql> select * from domains;
mysql> select * from records;
mysql> exit;

No comments:

Post a Comment