Client -->hosts文件 --> Client DNS Service Local Cache --> DNS Server (recursion递 归) --> DNS Server Cache -->DNS iteration(迭代) --> 根--> 顶级域名DNS-->二级域名DNS…
dig www.baidu.com
$TTL 86400
@ IN SOA ns1 admin.magedu.org (
1 ;
2H ;
10M ;
1W ;
1D ;
)
企业内部DNS解析-实现DNS主从服务器、反向解析
环境要求
前提准备
vi /etc/selinux/config
SELINUX=disabled
或者
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
systemctl disable --now firewalld
[root@centos7 ~]
[root@centos7 ~]
server ntp.aliyun.com iburst
server time1.cloud.tencent.com iburst
server slb.time.edu.cn iburst
allow 10.0.0.0/24
local stratum 10
:wq
[root@centos7 ~]
[root@centos7 ~]
[root@centos7 ~]
210 Number of sources = 2
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* 203.107.6.88 2 6 177 33 -4617us[+1547us] +/- 31ms
^+ 139.199.215.251 2 6 17 39 +5274us[ +11ms] +/- 30ms
[root@centos6 ~]
[root@centos6 ~]
server 10.0.0.170 iburst
:wq
[root@centos6 ~]
Stopping chronyd: [FAILED]
Starting chronyd: [ OK ]
[root@centos6 ~]
210 Number of sources = 1
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* 10.0.0.8 3 6 17 18 +15ns[ -880us] +/- 79ms
[root@centos8 ~]
[root@centos8 ~]
server 10.0.0.170 iburst
:wq
[root@centos8 ~]
[root@centos8 ~]
210 Number of sources = 1
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* 10.0.0.170 3 6 17 12 -2512ns[ -21us] +/- 33ms
root@ubuntu1804:~
root@ubuntu1804:~
pool 10.0.0.170 iburst maxsources 1
:wq
root@ubuntu1804:~
root@ubuntu1804:~
210 Number of sources = 1
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* 10.0.0.170 3 6 177 21 -21us[ +34us] +/- 29ms
搭建DNS主服务器
[root@centos7 ~]
[root@centos8 ~]
// listen-on port 53 { 127.0.0.1; };
// allow-query { localhost; };
:wq
[root@centos7 ~]
zone "shichong.org" IN {
type master;
file "shichong.org.zone";
};
[root@centos7 named]
[root@centos7 named]
total 20
drwxrwx--- 2 named named 6 Apr 29 22:05 data
drwxrwx--- 2 named named 6 Apr 29 22:05 dynamic
-rw-r----- 1 root named 2253 Apr 5 2018 named.ca
-rw-r----- 1 root named 152 Dec 15 2009 named.empty
-rw-r----- 1 root named 152 Jun 21 2007 named.localhost
-rw-r----- 1 root named 168 Dec 15 2009 named.loopback
-rw-r----- 1 root named 152 Jun 21 2007 shichong.org.zone
drwxrwx--- 2 named named 6 Apr 29 22:05 slaves
[root@centos7 named]
$TTL 1D
@ IN SOA ns1.shichong.org. admin.shichong.org. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS ns1.shichong.org.
ns1 A 10.0.0.170
www A 10.0.0.190
:wq
[root@centos7 ~]
[root@centos7 ~]
zone shichong.org/IN: loaded serial 0
OK
[root@centos7 ~]
Created symlink from /etc/systemd/system/multi-user.target.wants/named.service to /usr/lib/systemd/system/named.service.
root@ubuntu1804:~
root@ubuntu1804:~
www.shichong.org
[root@centos610 ~]
[root@centos610 ~]
alias vie0="'"vim /etc/sysconfig/network-scripts/ifcfg-eth0"'"
[root@centos610 ~]
DNS1=10.0.0.170
:wq
[root@centos610 ~]
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: Determining if ip address 10.0.0.160 is already in use for device eth0...
[ OK ]
[root@centos610 ~]
; generated by /sbin/dhclient-script
nameserver 10.0.0.170
search baidu.com
[root@centos610 ~]
www.shichong.org
[root@centos610 ~]
-bash: dig: command not found
[root@centos610 ~]
[root@centos610 ~]
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.68.rc1.el6 <<>> www.shichong.org
;; global options: +cmd
;; Got answer:
;; ->>HEADER"<<-" opcode: QUERY, status: NOERROR, id: 29107
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
;; QUESTION SECTION:
;www.shichong.org. IN A
;; ANSWER SECTION:
www.shichong.org. 86400 IN A 10.0.0.190
;; AUTHORITY SECTION:
shichong.org. 86400 IN NS ns1.shichong.org.
;; ADDITIONAL SECTION:
ns1.shichong.org. 86400 IN A 10.0.0.170
;; Query time: 0 msec
;; SERVER: 10.0.0.170
;; WHEN: Sun Aug 29 18:57:29 2021
;; MSG SIZE rcvd: 84
反向解析
[root@centos7 ~]
// listen-on port 53 { 127.0.0.1; };
// allow-query { localhost; };
[root@centos7 ~]
zone "0.0.10.in-addr.arpa" IN {
type master;
file "10.0.0.zone";
};
[root@centos7 ~]
[root@centos7 ~]
total 24
-rw-r----- 1 root named 168 Dec 15 2009 10.0.0.zone
drwxrwx--- 2 named named 23 Aug 29 18:34 data
drwxrwx--- 2 named named 60 Aug 29 19:03 dynamic
-rw-r----- 1 root named 2253 Apr 5 2018 named.ca
-rw-r----- 1 root named 152 Dec 15 2009 named.empty
-rw-r----- 1 root named 152 Jun 21 2007 named.localhost
-rw-r----- 1 root named 168 Dec 15 2009 named.loopback
-rw-r----- 1 root named 194 Aug 29 19:02 shichong.org.zone
drwxrwx--- 2 named named 6 Apr 29 22:05 slaves
[root@centos7 ~]
$TTL 1D
@ IN SOA rev1 admin.shichong.org. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS rev1.shichong.org.
190 PTR www.shichong.org.
[root@centos610 ~]
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.68.rc1.el6 <<>> -t ptr 190.0.0.10.in-addr.arpa @10.0.0.170
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<"-" opcode: QUERY, status: NOERROR, id: 38273
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 0
;; QUESTION SECTION:
;190.0.0.10.in-addr.arpa. IN PTR
;; ANSWER SECTION:
190.0.0.10.in-addr.arpa. 86400 IN PTR www.shichong.org.
;; AUTHORITY SECTION:
0.0.10.in-addr.arpa. 86400 IN NS rev1.shichong.org.
;; Query time: 1 msec
;; SERVER: 10.0.0.170
;; WHEN: Sun Aug 29 20:10:46 2021
;; MSG SIZE rcvd: 90
[root@centos610 ~]
190.0.0.10.in-addr.arpa domain name pointer www.shichong.org.
[root@centos610 ~]
Server: 10.0.0.170
Address: 10.0.0.170
190.0.0.10.in-addr.arpa name = www.shichong.org.
DNS从服务器
[root@centos7 ~]
allow-transfer {10.0.0.180;};
:wq
[root@centos7 ~]
$TTL 1D
@ IN SOA ns1.shichong.org. admin.shichong.org. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS ns1.shichong.org.
NS ns2.shichong.org.
ns1 A 10.0.0.170
ns2 A 10.0.0.180
www A 10.0.0.190
:wq
[root@centos7 ~]
server reload successful
[root@centos8 ~]
[root@centos8 ~]
allow-transfer {none;};
:wq
[root@centos8 ~]
[root@centos8 ~]
[root@centos8 ~]
-rw-r--r-- 1 named named 324 Aug 29 20:29 /var/named/slaves/shichong.org.zone
[root@centos610 ~]
DNS1=10.0.0.170
DNS2=10.0.0.180
:wq
[root@centos610 ~]
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: Determining if ip address 10.0.0.160 is already in use for device eth0...
[ OK ]
[root@centos610 ~]
; generated by /sbin/dhclient-script
nameserver 10.0.0.170
nameserver 10.0.0.180
search baidu.com
[root@centos7 ~]
[root@centos610 ~]
www.shichong.org
[root@centos610 ~]
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.68.rc1.el6 <<>> www.shichong.org
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<"-" opcode: QUERY, status: NOERROR, id: 8281
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 2
;; QUESTION SECTION:
;www.shichong.org. IN A
;; ANSWER SECTION:
www.shichong.org. 86400 IN A 10.0.0.190
;; AUTHORITY SECTION:
shichong.org. 86400 IN NS ns2.shichong.org.
shichong.org. 86400 IN NS ns1.shichong.org.
;; ADDITIONAL SECTION:
ns1.shichong.org. 86400 IN A 10.0.0.170
ns2.shichong.org. 86400 IN A 10.0.0.180
;; Query time: 1 msec
;; SERVER: 10.0.0.180
;; WHEN: Sun Aug 29 20:41:26 2021
;; MSG SIZE rcvd: 118