加密算法原理&&DNS服务原理及配置

1).简述常见加密算法及常见加密算法原理,最好使用图例解说

加密算法类型:

对称加密、公钥加密、单向加密

各加密算法的特性:

(第一种).对称加密: 加密和解密使用同一个密钥

常用的一些加密种类
DES: Date Encryption Standard
3DES: Triple DES
AES: Advanced Encryption Standard,(128bits,192bits,256bits,384bits)
Blowfish
Twofish
IDEA
RC6
CAST5
存在的特性:

1、加密、解密使用同一个密钥;
2、将源氏数据分割成为固定大小的块,逐个进行加密

缺陷:

1、密钥过多;
2、密钥分发困难;

(第二种).公钥加密: 密钥分为公钥与私钥

6716920_1407061378m5RW.jpg
公钥: 从私钥中提取产生;公开给所有人; pubkey
私钥: 通过工具创建,使用者自己留存,必须保证其私密性;secret key
特点: 用公钥加密的数据只能使用与之配对的私钥解密,反之亦然
用途:

数字签名: 主要在于让接收方确认发送方的身份
密钥交换: 发送发用对方的公钥加密一个对称密钥,并发送给对方;
数据加密

算法: RSA,DSA,ELGamal

DSS: Digital Signature Standard
DSA: Digital Signature Algorithm

(第三种)单向加密: 即提出数据指纹;只能加密,不能解密

特征: 定长输出、雪崩效应;
功能: 完整性验证
算法: 
md5: Message Digest 5,128bits
sha1: Secure Hash Algorithm 1,160bits
sha224,sha256,sha384,sha512

2).搭建apache或者nginx并使用自签证书实现https访问,自签名证书的域名自拟.

第一步: 生成私钥:(路径必须与默认配置相同)

[root@cherry ~]#(umask 077; openssl genrsa -out /etc/pki/CA/private/cakey.pem 2048)

注意: 需要查看生成的私钥是否只是自己的权限(很重要!)

[root@cherry ~]#ls /etc/pki/CA/private -l
-rw------- 1 root root 3243 Oct  7 08:35 cakey.pem

第二步: 生成自签证书(自签需要加-x509,否则只是自请的功能, -new指新创建)

[root@cherry ~]#openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -out /etc/pki/CA/cacert.pem -days 3655

第三步: 为CA提供目录及文件 (三目录两文件)

[root@cherry ~]#mkdir -pv /etc/pki/CA/certs

[root@cherry ~]#mkdir -pv /etc/pki/CA/newcerts

[root@cherry ~]#mkdir -pv /etc/pki/CA/crl

[root@cherry ~]#touch /etc/pki/CA/serial
[root@cherry ~]#touch /etc/pki/CA/index.txt

[root@cherry ~]#ls /etc/pki/CA
cacert.pem  certs  crl  index.txt  newcerts  private  serial

最后一步: 为serial文件添加开始码"01"

[root@cherry ~]#echo "01" > /etc/pki/CA/serial

要用到证书进行安全通信的服务器,需要向CA请求签署证书

  • 步骤:(以httpd为例)
    • (1) 用到证书的主机生成证书签署请求;
      • ~]#mkdir /etc/httpd/ssl
      • ~]#cd /etc/httpd/ssl
      • ~]#(umask 077; openssl genrsa -out httpd.key 2048)
[root@localhost ~]# yum -y install httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.ustc.edu.cn
 * extras: mirrors.aliyun.com
 * updates: centos.ustc.edu.cn
Package httpd-2.4.6-67.el7.centos.6.x86_64 already installed and latest version
Nothing to do
[root@localhost ~]# mkdir  /etc/httpd/ssl
[root@localhost ~]# cd /etc/httpd/ssl/
[root@localhost ssl]# (umask 077; openssl genrsa -out httpd.key 2048)
Generating RSA private key, 2048 bit long modulus
[root@localhost ssl]# ls 
httpd.key
  • (2) 生成证书签署请求
    • ~]#openssl req -new -key /etc/httpd/ssl/httpd.key -out /etc/httpd/ssl/httpd.csr -days 365
[root@localhost ssl]# openssl  req  -new  -key  /etc/httpd/ssl/httpd.key  -out /etc/httpd/ssl/httpd.csr  -days  365
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:BJ
State or Province Name (full name) []:beijing
Locality Name (eg, city) [Default City]:beijing
Organization Name (eg, company) [Default Company Ltd]:magedu
Organizational Unit Name (eg, section) []:ops
Common Name (eg, your name or your server's hostname) []:www.magedu.com
Email Address []:admin@magedu.com
[root@localhost ssl]# ls 
httpd.csr  httpd.key
  • (3) 将请求通过可靠方式发送给CA主机
    • SCP 源文件 root@ip
[root@localhost ssl]# scp httpd.csr root@192.168.60.44:/tmp/
The authenticity of host '192.168.60.44 (192.168.60.44)' can't be established.
ECDSA key fingerprint is SHA256:Yrud4cR2ciZ9YozYfnmrDIF7Gw2Z5QQYdvijKEd6ol4.
ECDSA key fingerprint is MD5:f0:c1:27:00:b9:89:9e:67:1f:65:79:7a:d4:91:cd:63.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.60.44' (ECDSA) to the list of known hosts.
root@192.168.60.44's password:    #输入root密码
httpd.csr
  • (4) 在CA主机上签署证书;
    • ~]#openssl ca -in /tmp/httpd.csr -out /etc/pki/CA/certs/httpd.crt -days 365
[root@localhost ~]# openssl ca -in /tmp/httpd.csr -out /etc/pki/CA/certs/httpd.crt -days 365
Using configuration from /etc/pki/tls/openssl.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
        Serial Number: 1 (0x1)
        Validity
            Not Before: Apr  6 14:34:561 2018 GMT
            Not After : Apr  6 14:34:56 2019 GMT
        Subject:
            countryName               = CN
            stateOrProvinceName       = beijing
            organizationName          = magedu
            organizationalUnitName    = ops
            commonName                = www.magedu.com
            emailAddress              = admin@magedu.com
        X509v3 extensions:
            X509v3 Basic Constraints: 
                CA:FALSE
            Netscape Comment: 
                OpenSSL Generated Certificate
            X509v3 Subject Key Identifier: 
                D9:36:D6:04:3A:7F:C6:F5:EC:CD:1D:C7:79:84:D3:BF:0D:D4:9F:6F
            X509v3 Authority Key Identifier: 
                keyid:9E:8B:94:0E:BA:C9:37:DC:3F:65:3D:49:B6:BE:68:88:22:8E:4E:78

Certificate is to be certified until Apr  6 14:34:56 2019 GMT (365 days)
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

[root@localhost ~]# cat /etc/pki/CA/index.txt
V   190406110831Z       01  unknown /C=CN/ST=guangxi/O=maedu/OU=ops/CN=www.maedu.com/emailAddress=adc@maedu.com


3).简述DNS服务器原理,并搭建主-辅服务器.

DNS域名基础知识

1.什么是DNS:

DNS: (Domain Name System, 域名系统)


2.DNS服务器的类型:

  • 主DNS服务器
    - 维护所负责解析的域的数据库的那台服务器; 读写操作均可进行;
  • 从DNS服务器
    - 从主DNS服务器那里或其他的从DNS服务器那里"复制"一份解析库;但只能进行读操作;
  • 缓存服务器
    - 通过其他域名服务器查询获得的域名与IP地址对应关系,并将经常查询的域名信息保存到服务器本地,用于提高查询效率.

实战配置

(一).服务器搭建环境

项目明细 配置信息
主服务器地址 ip: 192.168.60.42
从服务器地址 ip: 192.168.60.44
系统版本 CentOS Linux release 7.5.1804
bind版本 bind-9.9.4-61.el7_5.1.x86_64

(二).搭建DNS主服务器

1.安装bind服务程序
[root@CentOS7 ~]#rpm -qa bind
/etc/logrotate.d/named
/etc/named
/etc/named.conf                          ##主配置文件
/etc/named.iscdlv.key
/etc/named.rfc1912.zones         ##域配置文件
/etc/named.root.key
/etc/rndc.conf
....
[root@CentOS7 ~]#yum install bind -y
2.编辑主配置文件
[root@CentOS7 ~]#vim /etc/named.conf
options {
        listen-on port 53 { any; };                    ***对应做更改
        listen-on-v6 port 53 { ::1; };
        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     { localhost; };                        ***对应做更改

        /* 
         - If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.
         - If you are building a RECURSIVE (caching) DNS server, you need to enable 
           recursion. 
         - If your recursive DNS server has a public IP address, you MUST enable access 
           control to limit queries to your legitimate users. Failing to do so will
           cause your server to become part of large scale DNS amplification 
           attacks. Implementing BCP38 within your network would greatly
           reduce such attack surface 
        */
        recursion yes;

        dnssec-enable no;                          ***对应做更改
        dnssec-validation no;                     ***对应做更改
3.检查主配置文件语法并启动bind服务程序
[root@CentOS7 ~]#named-checkconf
[root@CentOS7 ~]#systemctl start named.service
[root@CentOS7 ~]#systemctl status named.service
● named.service - Berkeley Internet Name Domain (DNS)
   Loaded: loaded (/usr/lib/systemd/system/named.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2018-10-09 12:21:37 CST; 8s ago
  Process: 2839 ExecStart=/usr/sbin/named -u named -c ${NAMEDCONF} $OPTIONS (code=exited, status=0/SUCCESS)
4.配置域文件
[root@CentOS7 ~]#vim /etc/named.rfc1912.zones

//并在里面添加如下解析域内容:

zone "magedu.com" IN {                                     **正向解析
        type master;
        file "magedu.com.zone";
        allow-update { none; };
};

zone "60.168.192.in-addr.arpa" IN {                         **反向解析
        type master;
        file "192.168.60.in-addr.zone";
};

5.创建对应的zone文件
[root@CentOS7 ~]#cd /var/named
[root@CentOS7 named]#cp -a named.localhost magedu.com.zone
[root@CentOS7 named]#cp -a named.loopback 192.168.60.in-addr.zone
[root@CentOS7 named]#ll
total 24
-rw-r----- 1 root  named  168 Dec 15  2009 192.168.60.in-addr.zone                   **注意权限问题
drwxrwx--- 2 named named   23 Oct  9 12:21 data
drwxrwx--- 2 named named   60 Oct  9 12:22 dynamic
-rw-r----- 1 root  named  365 Oct  9 12:32 magedu.com.zone                              **注意权限问题
-rw-r----- 1 root  named 2281 May 22  2017 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 Aug 27 23:40 slaves
6.编辑域名数据配置文件
[root@CentOS7 named]#vim magedu.com.zone 
$TTL 1D
@       IN      SOA     magedu.com.     admin.magedu.com. (
                                2018101001      ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        IN      NS      ns.magedu.com.
        IN      MX 10   mail1.mageedu.com.
        IN      MX 20   mail2.mageedu.com.
ns      IN      A       192.168.60.42
mail1   IN      A       192.168.60.42
mail2   IN      A       192.168.60.50
www     IN      A       192.168.60.42
bbs     IN      CNAME   www
ftp     IN      A       192.168.60.50
[root@CentOS7 named]#vim 192.168.60.in-addr.zone 
$TTL 1D
@       IN      SOA     magedu.com.      rname.invalid. (
                                2018101001      ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        IN      NS      ns.magedu.com.
42      IN      PTR     ns.magedu.com.
42      IN      PTR     mail1.magedu.com.
50      IN      PTR     mail2.magedu.com.
42      IN      PTR     www.magedu.com.
50      IN      PTR     ftp.magedu.com.

7.再次检查语法错误并重载服务
[root@CentOS7 named]#named-checkconf
[root@CentOS7 named]#named-checkzone magedu.com /var/named/magedu.com.zone 
[root@CentOS7 named]#named-checkzone 60.168.192.in-addr.arpa /var/named/192.168.60.in-addr.zone 
zone 60.168.192.in-addr.arpa/IN: loaded serial 2018101001
OK
[root@CentOS7 named]#rndc reload
server reload successful
[root@CentOS7 named]#systemctl status named.service
● named.service - Berkeley Internet Name Domain (DNS)
   Loaded: loaded (/usr/lib/systemd/system/named.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2018-10-09 12:21:37 CST; 18min ago
  Process: 2839 ExecStart=/usr/sbin/named -u named -c ${NAMEDCONF} $OPTIONS (code=exited, status=0/SUCCESS)
8.更改本地DNS服务器并测试正向和反向解析
[root@CentOS7 named]#vim /etc/resolv.conf 
# Generated by NetworkManager
nameserver 192.168.60.42
[root@CentOS7 named]#dig -t axfr magedu.com
; <<>> DiG 9.9.4-RedHat-9.9.4-61.el7_5.1 <<>> -t axfr magedu.com
;; global options: +cmd
magedu.com.     86400   IN  SOA magedu.com. admin.magedu.com. 2018101001 86400 3600 604800 10800
magedu.com.     86400   IN  NS  ns.magedu.com.
magedu.com.     86400   IN  MX  10 mail1.mageedu.com.
magedu.com.     86400   IN  MX  20 mail2.mageedu.com.
bbs.magedu.com.     86400   IN  CNAME   www.magedu.com.
ftp.magedu.com.     86400   IN  A   192.168.60.50
mail1.magedu.com.   86400   IN  A   192.168.60.42
mail2.magedu.com.   86400   IN  A   192.168.60.50
ns.magedu.com.      86400   IN  A   192.168.60.42
www.magedu.com.     86400   IN  A   192.168.60.42
magedu.com.     86400   IN  SOA magedu.com. admin.magedu.com. 2018101001 86400 3600 604800 10800
;; Query time: 2 msec
;; SERVER: 192.168.60.42#53(192.168.60.42)
;; WHEN: Tue Oct 09 12:45:25 CST 2018
;; XFR size: 11 records (messages 1, bytes 293)
[root@CentOS7 named]#dig -t A www.magedu.com

; <<>> DiG 9.9.4-RedHat-9.9.4-61.el7_5.1 <<>> -t A www.magedu.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 33893
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.magedu.com.            IN  A

;; ANSWER SECTION:
www.magedu.com.     86400   IN  A   192.168.60.42

;; AUTHORITY SECTION:
magedu.com.     86400   IN  NS  ns.magedu.com.

;; ADDITIONAL SECTION:
ns.magedu.com.      86400   IN  A   192.168.60.42

;; Query time: 0 msec
;; SERVER: 192.168.60.42#53(192.168.60.42)
;; WHEN: Tue Oct 09 12:40:55 CST 2018
;; MSG SIZE  rcvd: 92
[root@CentOS7 named]#dig -x 192.168.60.42

; <<>> DiG 9.9.4-RedHat-9.9.4-61.el7_5.1 <<>> -x 192.168.60.42
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 36597
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 1, ADDITIONAL: 2

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;42.60.168.192.in-addr.arpa.    IN  PTR

;; ANSWER SECTION:
42.60.168.192.in-addr.arpa. 86400 IN    PTR ns.magedu.com.
42.60.168.192.in-addr.arpa. 86400 IN    PTR mail1.magedu.com.
42.60.168.192.in-addr.arpa. 86400 IN    PTR www.magedu.com.

;; AUTHORITY SECTION:
60.168.192.in-addr.arpa. 86400  IN  NS  ns.magedu.com.

;; ADDITIONAL SECTION:
ns.magedu.com.      86400   IN  A   192.168.60.42

;; Query time: 0 msec
;; SERVER: 192.168.60.42#53(192.168.60.42)
;; WHEN: Tue Oct 09 13:02:34 CST 2018
;; MSG SIZE  rcvd: 150

(三).搭建DNS从服务器

1.安装bind服务程序并配置相关的设置,参考上述主服务器搭建
[root@localhost ~]#yum install bind -y

[root@localhost ~]#vim /etc/named.conf 
options {
        listen-on port 53 { 127.0.0.1;192.168.60.44; };
        listen-on-v6 port 53 { ::1; };
        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     { localhost; };

        /* 
         - If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.
         - If you are building a RECURSIVE (caching) DNS server, you need to enable 
▽          recursion. 
         - If your recursive DNS server has a public IP address, you MUST enable access 
           control to limit queries to your legitimate users. Failing to do so will
           cause your server to become part of large scale DNS amplification 
           attacks. Implementing BCP38 within your network would greatly
           reduce such attack surface 
        */
        recursion yes;

        dnssec-enable no;
        dnssec-validation no;

2.启动bind程序并且配置从服务器上对应的域配置文件
[root@localhost ~]#systemctl start named.service
[root@localhost ~]#vim /etc/named.rfc1912.zones
zone "magedu.com" IN {
        type slave;
        file "slaves/magedu.com.zone";
        masters { 192.168.60.42; };                            ***需要添加主服务器的IP
};

zone "60.168.192.in-addr.arpa" IN {
        type slave;
        file "slaves/192.168.60.in-addr.zone";
        masters { 192.168.60.42; };                            ***需要添加主服务器的IP
};

[root@localhost ~]#named-checkconf
3.切回到主DNS服务器,在主服务器域配置文件中添加从服务器的IP信息
[root@CentOS7 named]#vim /etc/named.rfc1912.zones

zone "magedu.com" IN {
        type master;
        file "magedu.com.zone";
        allow-update { 192.168.60.44; };                        ***从服务器的IP
};

zone "60.168.192.in-addr.arpa" IN {
        type master;
        file "192.168.60.in-addr.zone";
        allow-update { 192.168.60.44; };                          ***从服务器的IP
}; 

4.切回到主DNS服务器,在主服务器数据配置文件中添加从服务器IP与域的一一对应关系
[root@CentOS7 named]#vim /var/named/magedu.com.zone
$TTL 1D
@       IN      SOA     magedu.com.     admin.magedu.com. (
                                2018101001      ; serial
▽                                       1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        IN      NS      ns.magedu.com.
        IN      NS      ns1.magedu.com.
        IN      MX 10   mail1.mageedu.com.
        IN      MX 20   mail2.mageedu.com.
ns      IN      A       192.168.60.42
ns1     IN      A       192.168.60.44
mail1   IN      A       192.168.60.42
mail2   IN      A       192.168.60.50
www     IN      A       192.168.60.42
bbs     IN      CNAME   www
ftp     IN      A       192.168.60.50
[root@CentOS7 named]#vim /var/named/192.168.60.in-addr.zone 
$TTL 1D
@       IN      SOA     magedu.com.      rname.invalid. (
                                2018101002      ; serial
▽                                       1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        IN      NS      ns.magedu.com.
42      IN      PTR     ns.magedu.com.
44      IN      PTR     ns1.magedu.com.
42      IN      PTR     mail1.magedu.com.
50      IN      PTR     mail2.magedu.com.
42      IN      PTR     www.magedu.com.
50      IN      PTR     ftp.magedu.com.

[root@CentOS7 named]#named-checkconf
[root@CentOS7 named]#named-checkzone magedu.com /var/named/magedu.com.zone
[root@CentOS7 named]#named-checkzone 60.168.192.in-addr.arpa /var/named/192.168.60.in-addr.zone
5.先重载主服务器端bind程序,然后切回从服务器重载等待更新同步完成
[root@CentOS7 named]#rndc reload                **顺序要主服务器优先重载,然后才是从服务器
6.测试从服务器正向反向解析
[root@localhost ~]#dig -t axfr magedu.com

; <<>> DiG 9.9.4-RedHat-9.9.4-61.el7_5.1 <<>> -t axfr magedu.com
;; global options: +cmd
magedu.com.     86400   IN  SOA magedu.com. admin.magedu.com. 2018101001 86400 3600 604800 10800
magedu.com.     86400   IN  MX  10 mail1.mageedu.com.
magedu.com.     86400   IN  MX  20 mail2.mageedu.com.
magedu.com.     86400   IN  NS  ns.magedu.com.
bbs.magedu.com.     86400   IN  CNAME   www.magedu.com.
ftp.magedu.com.     86400   IN  A   192.168.60.50
mail1.magedu.com.   86400   IN  A   192.168.60.42
mail2.magedu.com.   86400   IN  A   192.168.60.50
ns.magedu.com.      86400   IN  A   192.168.60.42
www.magedu.com.     86400   IN  A   192.168.60.42
magedu.com.     86400   IN  SOA magedu.com. admin.magedu.com. 2018101001 86400 3600 604800 10800
;; Query time: 1 msec
;; SERVER: 192.168.60.44#53(192.168.60.44)
;; WHEN: Tue Oct 09 13:26:48 CST 2018
;; XFR size: 11 records (messages 1, bytes 293)
[root@localhost ~]#dig -t A www.magedu.com

; <<>> DiG 9.9.4-RedHat-9.9.4-61.el7_5.1 <<>> -t A www.magedu.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 19535
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.magedu.com.            IN  A

;; ANSWER SECTION:
www.magedu.com.     86400   IN  A   192.168.60.42

;; AUTHORITY SECTION:
magedu.com.     86400   IN  NS  ns.magedu.com.

;; ADDITIONAL SECTION:
ns.magedu.com.      86400   IN  A   192.168.60.42

;; Query time: 0 msec
;; SERVER: 192.168.60.44#53(192.168.60.44)
;; WHEN: Tue Oct 09 13:26:24 CST 2018
;; MSG SIZE  rcvd: 92
[root@localhost ~]#dig -x 192.168.60.42

; <<>> DiG 9.9.4-RedHat-9.9.4-61.el7_5.1 <<>> -x 192.168.60.42
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56987
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 1, ADDITIONAL: 2

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;42.60.168.192.in-addr.arpa.    IN  PTR

;; ANSWER SECTION:
42.60.168.192.in-addr.arpa. 86400 IN    PTR mail1.magedu.com.
42.60.168.192.in-addr.arpa. 86400 IN    PTR ns.magedu.com.
42.60.168.192.in-addr.arpa. 86400 IN    PTR www.magedu.com.

;; AUTHORITY SECTION:
60.168.192.in-addr.arpa. 86400  IN  NS  ns.magedu.com.

;; ADDITIONAL SECTION:
ns.magedu.com.      86400   IN  A   192.168.60.42

;; Query time: 0 msec
;; SERVER: 192.168.60.44#53(192.168.60.44)
;; WHEN: Tue Oct 09 13:27:42 CST 2018
;; MSG SIZE  rcvd: 150

4).搭建并实现智能DNS

项目明细 配置信息
北京DNS服务器地址 ip: 192.168.60.42
上海DNS服务器地址 ip: 192.168.6.128
系统版本 CentOS Linux release 7.5.1804
bind版本 bind-9.9.4-61.el7_5.1.x86_64
1.安装bind服务
[root@localhost ~]#yum install bind -y
2.配置修改主文件
[root@localhost named]#cat /etc/named.conf 
//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
// See the BIND Administrator's Reference Manual (ARM) for details about the
// configuration located in /usr/share/doc/bind-{version}/Bv9ARM.html
acl "beijing" { 192.168.60.0/24; };                ***控制访问范围
acl "shanghai" { 192.168.6.0/24; };              ***控制访问范围


options {
    listen-on port 53 { any; };     ***需要做修改
    listen-on-v6 port 53 { ::1; };
    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     { any; };      ***需要做修改

    /* 
     - If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.
     - If you are building a RECURSIVE (caching) DNS server, you need to enable 
       recursion. 
     - If your recursive DNS server has a public IP address, you MUST enable access 
       control to limit queries to your legitimate users. Failing to do so will
       cause your server to become part of large scale DNS amplification 
       attacks. Implementing BCP38 within your network would greatly
       reduce such attack surface 
    */
    recursion yes;

    dnssec-enable no;                ***需要做修改
    dnssec-validation no;            ***需要做修改

    /* Path to ISC DLV key */
    bindkeys-file "/etc/named.iscdlv.key";

    managed-keys-directory "/var/named/dynamic";

    pid-file "/run/named/named.pid";
    session-keyfile "/run/named/session.key";
};

logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};

view bj {
    match-clients { beijing; };
    zone "." IN {
        type hint;
        file "named.ca";
    };
    zone "magedu.com" IN {
        type master;
        file "magedu.com.zone.bj";
    };
    include "/etc/named.rfc1912.zones";
    include "/etc/named.root.key";
};

view sh {
        match-clients { shanghai; };
        zone "." IN {
                type hint;
                file "named.ca";
        };
        zone "magedu.com" IN {
                type master;
                file "magedu.com.zone.sh";
        };
        include "/etc/named.rfc1912.zones";
        include "/etc/named.root.key";
};

view default {
        match-clients { any; };
        zone "." IN {
                type hint;
                file "named.ca";
        };
        include "/etc/named.rfc1912.zones";
        include "/etc/named.root.key";
};




//zone "." IN {
//  type hint;
//  file "named.ca";
//};

2.创建对应zone空间文件
[root@localhost ~]#cd /var/named
[root@localhost named]#cp -a named.localhost magedu.com.zone.bj
[root@localhost named]#cp -a named.localhost magedu.com.zone.sh
[root@localhost named]#ll
total 28
drwxrwx--- 2 named named   23 Oct  9 16:18 data
drwxrwx--- 2 named named 4096 Oct  9 16:19 dynamic
-rw-r----- 1 root  named  213 Oct  9 16:14 magedu.com.zone.bj
-rw-r----- 1 root  named  214 Oct  9 16:16 magedu.com.zone.sh
-rw-r----- 1 root  named 2281 May 22  2017 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 Aug 27 23:40 slaves

3.对数据文件做配置修改
[root@localhost named]#vim /var/named/magedu.com.zone.bj
$TTL 1D
@   IN   SOA    magedu.com. admin.magedu.com. (
                2018101001  ; serial
                    1D  ; refresh
                    1H  ; retry
                    1W  ; expire
                    3H )    ; minimum
    IN  NS  ns.magedu.com.
ns  IN  A   192.168.60.42
www IN  A   192.168.60.100
[root@localhost named]#vim /var/named/magedu.com.zone.sh
$TTL 1D
@   IN   SOA    magedu.com.     admin.magedu.com. (
                2018101001  ; serial
                    1D  ; refresh
                    1H  ; retry
                    1W  ; expire
                    3H )    ; minimum
    IN  NS  ns.magedu.com.
ns  IN  A   192.168.6.128   
www IN  A   192.168.6.100
4.对配置文件做语法检查并重载操作
[root@localhost named]#named-checkconf
[root@localhost named]#named-checkzone magedu.com /var/named/magedu.com.zone.bj
zone magedu.com/IN: loaded serial 2018101001
OK
[root@localhost named]#named-checkzone magedu.com /var/named/magedu.com.zone.sh
zone magedu.com/IN: loaded serial 2018101001
OK
[root@localhost named]#rndc reload
5.测试不同区域的解析
[root@localhost named]#nslookup
> server 192.168.60.42
Default server: 192.168.60.42
Address: 192.168.60.42#53
> set q=A
> www.magedu.com
Server:     192.168.60.42
Address:    192.168.60.42#53

Name:   www.magedu.com
Address: 192.168.60.100
> exit

[root@localhost named]#nslookup
> server 192.168.6.128
Default server: 192.168.6.128
Address: 192.168.6.128#53
> www.magedu.com
Server:     192.168.6.128
Address:    192.168.6.128#53

Name:   www.magedu.com
Address: 192.168.6.100

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 206,214评论 6 481
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 88,307评论 2 382
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 152,543评论 0 341
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 55,221评论 1 279
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 64,224评论 5 371
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,007评论 1 284
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,313评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,956评论 0 259
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,441评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,925评论 2 323
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,018评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,685评论 4 322
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,234评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,240评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,464评论 1 261
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,467评论 2 352
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,762评论 2 345

推荐阅读更多精彩内容