1:概念
DNS是是域名解析系统的缩写,简而言之就是计算机只能相识于ip,而DNS就是你告诉他一个www.baidu.com,他告诉你一个183.232.231.173,而域名解析系统也分为正向解析和反向解析,正向解析就是你告诉他网站,他告诉你ip,而反向解析就是你告诉他ip,他告诉你网址。
准备动作
1:ip配置
2:yum源配置
3:下载bind
[root@server11 Desktop]# vim /etc/yum.repos.d/rhel_dvd.repo
[root@server11 Desktop]# yum clean all
Loaded plugins: langpacks
Cleaning repos: rhel_dvd
Cleaning up everything
[root@server11 Desktop]# yum install bind
Loaded plugins: langpacks
rhel_dvd | 4.1 kB 00:00
(1/2): rhel_dvd/group_gz | 134 kB 00:00
(2/2): rhel_dvd/primary_db | 3.4 MB 00:00
Resolving Dependencies
--> Running transaction check
---> Package bind.x86_64 32:9.9.4-14.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
bind x86_64 32:9.9.4-14.el7 rhel_dvd 1.8 M
Transaction Summary
================================================================================
Install 1 Package
Total download size: 1.8 M
Installed size: 4.3 M
Is this ok [y/d/N]: y
Downloading packages:
bind-9.9.4-14.el7.x86_64.rpm | 1.8 MB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : 32:bind-9.9.4-14.el7.x86_64 1/1
Verifying : 32:bind-9.9.4-14.el7.x86_64 1/1
Installed:
bind.x86_64 32:9.9.4-14.el7
Complete!
4:做火墙策略
[root@localhost Desktop]# firewall-cmd --add-service=dns
success
[root@localhost Desktop]# firewall-cmd --list-all
public (default, active)
interfaces: eth0
sources:
services: dhcpv6-client dns ssh
ports:
masquerade: no
forward-ports:
icmp-blocks:
rich rules:
5:给主机重命名
[root@localhost Desktop]# hostnamectl set-hostname DNS-SERVER.example.com
[root@localhost Desktop]# hostname
dns-server.example.com
A:正向解析
[root@localhost Desktop]# vim /etc/resolv.conf
[root@localhost Desktop]# vim /etc/named.conf
[root@localhost Desktop]# systemctl restart named
[root@localhost Desktop]# dig www.baidu.com
; <<>> DiG 9.9.4-RedHat-9.9.4-14.el7 <<>> www.baidu.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 40803
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 13, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.baidu.com. IN A
;; ANSWER SECTION:
www.baidu.com. 685 IN CNAME www.a.shifen.com.
www.a.shifen.com. 205 IN A 220.181.112.244
www.a.shifen.com. 205 IN A 220.181.111.188
;; AUTHORITY SECTION:
. 513349 IN NS d.root-servers.net.
. 513349 IN NS b.root-servers.net.
. 513349 IN NS i.root-servers.net.
. 513349 IN NS c.root-servers.net.
. 513349 IN NS m.root-servers.net.
. 513349 IN NS g.root-servers.net.
. 513349 IN NS k.root-servers.net.
. 513349 IN NS e.root-servers.net.
. 513349 IN NS a.root-servers.net.
. 513349 IN NS h.root-servers.net.
. 513349 IN NS f.root-servers.net.
. 513349 IN NS l.root-servers.net.
. 513349 IN NS j.root-servers.net.
;; Query time: 62 msec
;; SERVER: 172.25.254.111#53(172.25.254.111)
;; WHEN: Tue Aug 08 22:09:28 EDT 2017
;; MSG SIZE rcvd: 312
[root@localhost Desktop]# dig www.baidu.com
; <<>> DiG 9.9.4-RedHat-9.9.4-14.el7 <<>> www.baidu.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 26510
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 13, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.baidu.com. IN A
;; ANSWER SECTION:
www.baidu.com. 662 IN CNAME www.a.shifen.com.
www.a.shifen.com. 182 IN A 220.181.112.244
www.a.shifen.com. 182 IN A 220.181.111.188
;; AUTHORITY SECTION:
. 513326 IN NS d.root-servers.net.
. 513326 IN NS b.root-servers.net.
. 513326 IN NS f.root-servers.net.
. 513326 IN NS e.root-servers.net.
. 513326 IN NS m.root-servers.net.
. 513326 IN NS h.root-servers.net.
. 513326 IN NS i.root-servers.net.
. 513326 IN NS k.root-servers.net.
. 513326 IN NS l.root-servers.net.
. 513326 IN NS g.root-servers.net.
. 513326 IN NS j.root-servers.net.
. 513326 IN NS a.root-servers.net.
. 513326 IN NS c.root-servers.net.
;; Query time: 0 msec
;; SERVER: 172.25.254.111#53(172.25.254.111)
;; WHEN: Tue Aug 08 22:09:51 EDT 2017
;; MSG SIZE rcvd: 312
forwarders 权威dns
在没配置好dns之前用作解析的ip
&&&查看named端口
[root@localhost named]# vim /etc/named.conf ##查看下一个指向文件
[root@localhost named]# vi /etc/named.rfc1912.zones ##编辑新的网站
[root@localhost named]# cp -p named.localhost westos.com.zone
[root@localhost named]# systemctl restart named
[root@localhost named]# vim westos.com.zone
开始解析 直接解析
[root@localhost named]# dig www.westos.com
; <<>> DiG 9.9.4-RedHat-9.9.4-14.el7 <<>> www.westos.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 8814
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.westos.com. IN A
;; ANSWER SECTION:
www.westos.com. 86400 IN A 172.25.254.111
;; AUTHORITY SECTION:
westos.com. 86400 IN NS dns.westos.com.
;; ADDITIONAL SECTION:
dns.westos.com. 86400 IN A 172.25.254.100
;; Query time: 0 msec
;; SERVER: 172.25.254.111#53(172.25.254.111)
;; WHEN: Tue Aug 08 22:48:31 EDT 2017
;; MSG SIZE rcvd: 93
###bbs解析
[root@localhost named]# dig bbs.westos.com
; <<>> DiG 9.9.4-RedHat-9.9.4-14.el7 <<>> bbs.westos.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56572
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 1, ADDITIONAL: 2
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;bbs.westos.com. IN A
;; ANSWER SECTION:
bbs.westos.com. 86400 IN CNAME news.westos.com.
news.westos.com. 86400 IN A 172.25.254.222
;; AUTHORITY SECTION:
westos.com. 86400 IN NS dns.westos.com.
;; ADDITIONAL SECTION:
dns.westos.com. 86400 IN A 172.25.254.100
;; Query time: 0 msec
;; SERVER: 172.25.254.111#53(172.25.254.111)
;; WHEN: Tue Aug 08 22:48:40 EDT 2017
;; MSG SIZE rcvd: 112
B:反向解析
[root@localhost named]# vim /etc/named.rfc1912.zones
[root@localhost named]# vim westos.com.ptr
[root@localhost named]# dig -x 172.25.254.111
; <<>> DiG 9.9.4-RedHat-9.9.4-14.el7 <<>> -x 172.25.254.111
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 61636
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;111.254.25.172.in-addr.arpa. IN PTR
;; ANSWER SECTION:
111.254.25.172.in-addr.arpa. 86400 IN PTR hello.westos.com.
;; AUTHORITY SECTION:
254.25.172.in-addr.arpa. 86400 IN NS dns.westos.com.
;; ADDITIONAL SECTION:
dns.westos.com. 86400 IN A 172.25.254.100
;; Query time: 0 msec
;; SERVER: 172.25.254.111#53(172.25.254.111)
;; WHEN: Tue Aug 08 23:31:54 EDT 2017
;; MSG SIZE rcvd: 120
[root@localhost named]# dig dns.westos.com
; <<>> DiG 9.9.4-RedHat-9.9.4-14.el7 <<>> dns.westos.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 51147
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;dns.westos.com. IN A
;; ANSWER SECTION:
dns.westos.com. 86400 IN A 172.25.254.100
;; AUTHORITY SECTION:
westos.com. 86400 IN NS dns.westos.com.
;; Query time: 0 msec
;; SERVER: 172.25.254.111#53(172.25.254.111)
;; WHEN: Tue Aug 08 23:32:30 EDT 2017
;; MSG SIZE rcvd: 73
C:分类解析
概念:顾名思义,就是对于不同的类群解析出来的 ip 不同,比如百度的内部人员使用的为了运行后台而设立的ip不同一样,为了解决这种问题,我们就提出并创建了分类解析,通过不同的人得到的ip不同而实现对网络更有效的管理。
[root@localhost named]# vim /etc/named.conf
[root@localhost named]# cp -p /etc/named.rfc1912.zones /etc/named.rfc1913.zones
[root@localhost named]# vim /etc/named.rfc1913.zones
[root@localhost named]# cp -p westos.com.zone westos.com.inter
[root@localhost named]# ls
data named.ca named.localhost slaves westos.com.ptr
dynamic named.empty named.loopback westos.com.inter westos.com.zone
[root@localhost named]# vim westos.com.inter
[root@localhost named]# systemctl restart named
[root@localhost named]# dig www.westos.com
; <<>> DiG 9.9.4-RedHat-9.9.4-14.el7 <<>> www.westos.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 52983
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.westos.com. IN A
;; ANSWER SECTION:
www.westos.com. 86400 IN A 112.112.112.112
;; AUTHORITY SECTION:
westos.com. 86400 IN NS dns.westos.com.
;; ADDITIONAL SECTION:
dns.westos.com. 86400 IN A 112.112.112.112
;; Query time: 20 msec
;; SERVER: 172.25.254.111#53(172.25.254.111)
;; WHEN: Wed Aug 09 01:27:59 EDT 2017
;; MSG SIZE rcvd: 93
[root@foundation11 ~]# vim /etc/resolv.conf
[root@foundation11 ~]# dig www.westos.com
; <<>> DiG 9.9.4-RedHat-9.9.4-29.el7 <<>> www.westos.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 65105
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.westos.com. IN A
;; ANSWER SECTION:
www.westos.com. 86400 IN A 172.25.254.111
;; AUTHORITY SECTION:
westos.com. 86400 IN NS dns.westos.com.
;; ADDITIONAL SECTION:
dns.westos.com. 86400 IN A 172.25.254.100
;; Query time: 1 msec
;; SERVER: 172.25.254.111#53(172.25.254.111)
;; WHEN: Wed Aug 09 13:29:53 CST 2017
;; MSG SIZE rcvd: 93
对比发现,两个解析出来ip不同,实验成功
D:解析释压
概念
什么是解析施压,顾名思义,就是当你配置的dns解析满足不了大量客户的需求时,此刻的他就需要另一个人站出来替他分担这种压力,我把这叫做解析的释压。而另外一个帮助解析的叫副dns,同样的,在运用副dns也要进行ip设置,yum源配置,bind下载,火墙策略的一系列步骤。完成以上配置后还需要作下面几个改变。
[root@desktop11 slaves]# vim /etc/resolv.conf
[root@desktop11 slaves]# vim /etc/named.conf
[root@desktop11 slaves]# vim /etc/named.rfc1912.zones
[root@desktop11 named]# ll
total 16
drwxrwx--- 2 named named 6 Jan 29 2014 data
drwxrwx--- 2 named named 6 Jan 29 2014 dynamic
-rw-r----- 1 root named 2076 Jan 28 2013 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
drwxrwx--- 2 named named 6 Jan 29 2014 slaves
[root@desktop11 slaves]# systemctl restart named
[root@desktop11 slaves]# ls
westos.com.zone
E:解析的同步
[root@server11 named]# vim /etc/named.rfc1913.zones
[root@server11 named]# vim westos.com.inter
[root@server11 named]# systemctl restart named
[root@server11 named]#
测试
[root@desktop11 slaves]# dig www.westos.com
; <<>> DiG 9.9.4-RedHat-9.9.4-14.el7 <<>> www.westos.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 48725
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.westos.com. IN A
;; ANSWER SECTION:
www.westos.com. 86400 IN A 111.111.222.244
;; AUTHORITY SECTION:
westos.com. 86400 IN NS dns.westos.com.
;; ADDITIONAL SECTION:
dns.westos.com. 86400 IN A 112.112.112.112
;; Query time: 0 msec
;; SERVER: 172.25.254.211#53(172.25.254.211)
;; WHEN: Wed Aug 09 03:36:50 EDT 2017
;; MSG SIZE rcvd: 93
同步成功