Bind DNS-- domain name resolution protocol

1, dns concept:
the DNS (Domain the Name System) is a service on the Internet as a distributed database of domain names and IP addresses will be mapped each other, can make people more convenient access to the Internet.
The DNS system is used to query the network, then naturally it requires listening port. DNS using port 53 , can be seen in / etc / services (search domain) this file. Normally this DNS UDP is faster data transfer protocol to query, but can not find any complete information, will once again re-TCP protocol to this query. So when you start DNS, TCP and UDP will also start the port53.
1.1 Internet domain structure
due to the large number of Internet users, the Internet is used in naming naming hierarchical tree structure. Any connected to the Internet host or router, has a unique name of the hierarchy, that is, the domain name (domain name). "Domain" (domain) is the name space can be managed in a division.
Domain name only logical concept and does not represent the physical location of the computer is located. The domain can be divided into three categories:
(1) national top-level domain name : The ISO3166 requirements. Such as: cn behalf of China, us represent the United States, uk on behalf of the United Kingdom, and so on. National domain name and often referred to as ccTLD (country code top-level domains , cc represents the country code contry-code).
(2) generic top-level domains : the most common generic top-level domain has seven, namely: com (companies), net (network service), org (nonprofit organizations), int (international organizations), gov (the US government department), mil (the US military).
(3) Infrastructure domain(infrastructure domain): This is only one top-level domain, i.e. ARPA, a reverse domain name resolution, so called reverse domain
1.2 type domain name server
from the domain name server according to the action, the domain name server can be classified into the following types:
(1 ) root name server : the highest level of the domain name server, domain name server is the most important. All root name servers know that domain names and IP addresses of all the top-level domain servers. No matter what a local domain name server, to parse for any domain on the Internet, as long as they can not be resolved, it is first of all help the root name servers. So root name server is the most important domain name server.
(Now put the world's total of 13 root servers, root servers mainly used to manage the Internet's master directories, the world is only 13 units .1 main root server, placed in the United States. The remaining 12 were supplemented by the root servers, 9 placed in the United States, two in Europe, the UK and Sweden, 1 in Asia, in Japan)
(2) top-level domain servers : responsible for managing the two domain names registered in the top-level domain servers.
(3) the domain name server permissions : responsible for a "zone" domain name server.
(4) local domain name server : The local domain name server does not belong to the hierarchy of the domain name server, but it is very important domain name system. When a host sends a DNS query requests, query request message is sent to the local domain name server.
(5) DNS server cache : not responsible for resolving domain, but DNS cache results
(6) forwarding server : Any server can forward DNS resolution requests to other DNS servers are known as forward DNS server
which (1,2,3) collectively referred to as the authorization server
Here Insert Picture Description
Here Insert Picture Description

2 DNS name resolution process

To enter in a browser such as domain name, for example www.qq.com

  1. First check whether the local hosts file exists that URL mapping relationship, if there is successfully resolved
  2. If no mapping local hosts file, the query whether there is a mapping for the URL of the local dns resolver cache, if there is then parsed.
  3. If the above two steps are not mappings to find a local dns server, dns server that is preferred tcp / ip set, if the domain name to be queried included in the allocation of resources in the local area, it will be the corresponding ip address back to the host, complete analytical
  4. If the domain name to be queried, the local DNS server could not help resolve the region, but the server has cached the URL mappings call this IP address mapping, complete DNS, this does not have the authority to resolve.
  5. If the local DNS server to the local area cache file parsing fail, then (if the transponder is provided) according to the settings query the local DNS server, forwarding mode if unused, puts the request sent to the local DNS 13 root DNS, the root server DNS after receiving the request will judge this domain name (.com) who is authorized to manage, and will return to the local dns server IP that a charge of a top-level domain servers. After the local DNS server receives IP information will contact this server is responsible for .com domain. This is responsible for the .com domain server receives a request, if they can not be resolved, it will manage to find a qq.com DNS server address to the local DNS server. When the local DNS server receives this address, you will find qq.com domain server, repeat the above action, inquiries, until www. Qq .com hosts found.
    Here Insert Picture Description
    Query:
    Recursive: Specifies the client to the server query
    iterations: between query DNS servers

3, dns analytical methods:

3 DNS analytic way
forward resolution: The FQDN (domain name) -----> IP
reverse analysis: The IP -----> FQDN (domain name)

4, configuration:

1, the forward resolution: domain name -> ip

1) bind to install software

[root@kongd ~]# yum install -y bind      //提供bind dns服务的套件叫bind但是执行服务名称是named
[root@kongd ~]# systemctl stop firewalld    //临时将防火墙以及selinux设置为警告模式
[root@kongd ~]# setenforce 0
也可以不停止防火墙,但是要放行dns服务:
[root@kongd ~]# firewall-cmd --permanent --add-service=dns
[root@kongd named]# firewall-cmd --reload

2) View profile :( only introduce a few important configuration files)

[root@llh ~]# rpm -qc bind
/etc/logrotate.d/named
**/etc/named.conf**        //bind主配置文件 
/etc/named.iscdlv.key
**/etc/named.rfc1912.zones**     //定义zone区域的文件
/etc/named.root.key
/etc/rndc.conf
/etc/rndc.key
/etc/sysconfig/named    //启动服务时的相关文件
/var/named/named.ca    // 根解析库----/var/named是数据配置文件目录
/var/named/named.empty    
/var/named/named.localhost    //本地主机解析库
/var/named/named.loopback   

3) configure the primary configuration file
the end of every sentence has a semicolon Note Configuration

[root@llh ~]# vim /etc/named.conf
options {
        listen-on port 53 { 192.168.154.140; };   //对哪一个主机进行监听
//      listen-on-v6 port 53 { ::1; };       //不使用ipv6直接注释掉
        directory       "/var/named";       
        dump-file       "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
        allow-query     { 192.168.150/24; };   //允许谁访问查询(允许所有--any)
        :wq 保存退出
 [root@llh ~]# named-checkconf      //语法检查
        

4) Configuration zone file:

[root@llh ~]# vim /etc/named.rfc1912.zones 
zone "huhu.com" IN {                               //域名区域
        type master;                           //类型为主区域类型
         file "huhu.com.zone";            //区域文件--域名后面要带.zone
        allow-update { none; };           //允许谁更新
};

type Type:
Primary DNS server: modifying data (accept user request to return data) Master authority domain name server
secondary server dns: periodically requests data synchronization slave
cache server dns: dns data cache only hint ----- no parsing
Here Insert Picture Description
5) arranged above zone file file "huhu.com.zone"; data files:
Note: It is recommended to copy the template file to configure:

[root@llh ~]# cd /var/named
[root@llh named]# ll 
total 16    //只展示所需内容
-rw-r-----. 1 root  named  152 Jun 21  2007 named.localhost  //正向区域配置模板
-rw-r-----. 1 root  named  168 Dec 15  2009 named.loopback
[root@llh named]# cp -p named.localhost huhu.com.zone    //拷贝模板
[root@llh named]# vim huhu.com.zone
$TTL 1D
@       IN SOA  ns1.huhu.com. admin.huhu.com. (
                                        2020021201      ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      ns1
        MX 5    mail.huhu.com.
ns1     A       192.168.154.140
mail    A       192.168.154.140
www     A       192.168.154.11
web     CNAME   www
 :wq
 [root@llh named]# named-checkzone huhu.com /var/named/huhu.com.zone   //区域数据文件语法检测
zone huhu.com/IN: loaded serial 2020021201
OK       //表示没有语法错误

Note: @ indicates a region (domain huhu.com) starting at the specified authorization record, in which case the following parameters can be resource record huhu.com Com later add the domain must be omitted in order to complete the form shown, and back. iN front of the @ is omitted because SOA can be inherited in front of the above name
related knowledge added:
resource record is an entry in the DNS zone information is used to specify a particular name or object. A resource record contains five fields, organized according to the following format:
Owner class-name the TTL Data type
www.dyzx.edu the IN A 192.168.1.3 500
Here Insert Picture Description
the DNS resource records and varieties
①SOA recording - authorizing start (Start Of Authority) records, each region has a SOA record is used to specify the region responsible for resolving the DNS server which is in charge of the primary authorization server, and manage e-mail address and the main area, data synchronization between secondary authoritative DNS server control parameter
②NS record - a domain name server (Name server) records for the domain name is mapped to the authoritative DNS servers in the region. Each disclosed the main region / secondary DNS server has authorized a NS record.
③A record - also known as forward-resolution records, explain what a domain name for the corresponding IPv4 address Yes.
④AAAA record - for explaining an IPv6 address corresponding to the domain name, the domain name is mapped to the IPv6 address soon.
⑤CNAME Record - Alias (Canonical Name) record for the host to set another new domain name, the domain is a new record to the original domain mapping. Prior to the original domain name should be provided through the respective A or AAAA record record.
⑥PTR recording - also called reverse DNS record or record pointer, an inverse mapping for the IP address to the domain name.
⑦MX Record - Mail Exchange (Mail Exchange) record, belonging to a mail domain of the region (i.e., mail address string behind @) maps the domain name to the mail server.
⑧SRV record - used to find a specific host support "Windows domain" services
6): Start and test the service:
[root @ LLH named] # systemctl Start named // Note the name of the service
to install a local test software:
[root @ LLH named] # yum install bind-utils -y

  • Temporary test:
    1. nslookup
[root@llh named]# nslookup       -----**交互式**
> server 192.168.154.140#53
^C[root@llh named]# 
[root@llh named]# nslookup
> server 192.168.154.140      //临时指定主机
Default server: 192.168.154.140
Address: 192.168.154.140#53
> www.huhu.com           //测试域名  
Server:		192.168.154.140
Address:	192.168.154.140#53
Name:	www.huhu.com
Address: 192.168.154.11        //解析成功
> web.huhu.com              //测试别名
Server:		192.168.154.140
Address:	192.168.154.140#53
web.huhu.com	canonical name = www.huhu.com.
Name:	www.huhu.com         //解析成功
Address: 192.168.154.11         //域名对应ip地址
> set type=mx               //测试邮件服务器需要指定类型
> huhu.com
Server:		192.168.154.140
Address:	192.168.154.140#53
huhu.com	mail exchanger = 5 mail.huhu.com.              //解析成功
> exit      //退出
[root@llh named]# nslookup ns1.huhu.com 192.168.154.140       ----**-非交互式**
Server:		192.168.154.140
Address:	192.168.154.140#53
Name:	ns1.huhu.com
Address: 192.168.154.140
  1. host // and nslookup use similar, but you can specify the resource record type -t type
[root@llh named]# host ns1.huhu.com 192.168.154.140 
Using domain server:
Name: 192.168.154.140
Address: 192.168.154.140#53
Aliases: 
ns1.huhu.com has address 192.168.154.140   //解析成功
[root@llh named]# host -t MX huhu.com 192.168.154.140   //-t 指定邮件类型mx(不区分大小写)
Using domain server:
Name: 192.168.154.140
Address: 192.168.154.140#53
Aliases: 
huhu.com mail is handled by 5 mail.huhu.com.   //解析成共
  1. you
[root@llh named]# dig -t MX huhu.com @192.168.154.140 
  • Permanent test:
    modify the configuration file: /etc/resolv.conf
[root@llh named]# vim /etc/resolv.conf 
search huhu.com            //修改搜索域名
nameserver 192.168.154.140     //添加自己的dns服务器ip
nameserver 192.168.154.1
:wq

At this time the test:
[root @ LLH named] # Host -t MX huhu.com
huhu.com mail IS the Handled by 5 mail.huhu.com // do not specify the dns server ip can be successfully resolved.

2. reverse lookup: ip ---------> domain name

The following modifications based on the above part of the forward resolution:
1, profile modification area
[the root @ LLH the named] # Vim /etc/named.rfc1912.zones
Zone "154.168.192.in-addr.arpa" {// the IN "" written backwards within the network bit
type Master;
File "192.168.154.zone";
the allow-Update {none;};
};
the red box as a template, the reference template Acronym blue content Here Insert Picture Description
2 arranged above zone file file "192.168.154.zone"; data file:
still copy template:

[root@llh named]# pwd
/var/named
[root@llh named]# ll
total 20
-rw-r-----. 1 root  named  152 Jun 21  2007 named.localhost
-rw-r-----. 1 root  named  168 Dec 15  2009 named.loopback  //反向解析模板
[root@llh named]# cp -p named.loopback 192.168.154.zone   //复制模板
[root@llh named]# vim 192.168.154.zone    //注意:一定要对应正向解析的域名和ip写
$TTL 1D
@       IN SOA  ns1.huhu.com. admin.huhu.com. (
                                        2020031201      ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
           NS      ns1.huhu.com.     //反向解析此处一定要写完整
ns1      A       192.168.154.140
140     PTR     ns1.huhu.com.      //前面写上正想解析中对应的主机
           PTR     mail.huhu.com.     //前面没写代表继承上一个主机位
11       PTR     www.huhu.com.
11       PTR     web.huhu.com.      
:wq
检测语法是否有误:
[root@llh named]# named-checkconf    //检测主配置文件
[root@llh named]# named-checkzone huhu.com 192.168.154.zone    //检测zone
zone huhu.com/IN: loaded serial 2020031201
OK          //语法正确

3, restart the test:

[root@llh named]# systemctl restart named
由于正向解析中已经配置过永久解析,所以此处直接使用:
[root@llh named]# host -t ptr 192.168.154.140  
140.154.168.192.in-addr.arpa domain name pointer ns1.huhu.com.   
140.154.168.192.in-addr.arpa domain name pointer mail.huhu.com.  

[root@llh named]# host -t ptr 192.168.154.11    
11.154.168.192.in-addr.arpa domain name pointer www.huhu.com.
11.154.168.192.in-addr.arpa domain name pointer web.huhu.com.

[root@llh named]# nslookup 192.168.154.140
Server:		192.168.154.140
Address:	192.168.154.140#53
140.154.168.192.in-addr.arpa	name = ns1.huhu.com.
140.154.168.192.in-addr.arpa	name = mail.huhu.com.

dig -x 192.168.154.140    //可以查看更多解析出来的详细信息
Published 34 original articles · won praise 26 · views 1708

Guess you like

Origin blog.csdn.net/Alkaid__3/article/details/104785139
Recommended