DNS设定

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DNS设定相关的知识,希望对你有一定的参考价值。

####辅助dns####
###dns集群####
(1)辅助dns
设定slave
选定一台机子作辅助dns机
在辅助机上的操作
1. yum install bind -y
2.vim /etc/named.conf
 listen-on port 53 { any; };
 allow-query     { any; };
 dnssec-validation no;
3.vim /etc/named.rfc1912.zones
zone "westos.com" IN {
        type slave;
        masters {172.25.254.109; };
        file "slaves/westos.com.zone";
        allow-update { none; };
};
4.vim /etc/resolv.conf
namesever 172.25.254.209
5.systemctl restart named
6.systemctl stop firewalld
主dns设置
vim /etc/named.rfc1912.zones
zone "westos.com" IN {
        type master;
        file "westos.com.zone";
        allow-update {none; };
        allow-transfer {172.25.254.209; };    ##允许209同步数据
};
$TTL 1D
@       IN SOA  dns.westos.com. root.westos.com. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      dns.westos.com.
dns     A       172.25.254.109
www     A       172.25.254.140
www     A       172.25.254.240
systemctl restart named           ##重启服务
进行以上操作后将在辅助dns机的slaves/有 westos.com.zone文件
可以在辅助dns机中 dig www.westos.com
[[email protected] 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: 29609
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, 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.240
www.westos.com.  86400 IN A 172.25.254.140

;; AUTHORITY SECTION:
westos.com.  86400 IN NS dns.westos.com.

;; ADDITIONAL SECTION:
dns.westos.com.  86400 IN A 172.25.254.109

;; Query time: 0 msec
;; SERVER: 172.25.254.109#53(172.25.254.109)
;; WHEN: Wed Nov 30 08:19:21 EST 2016
;; MSG SIZE  rcvd: 109
(2)辅助dns自动获取主dns数据
主dns设置
vim /etc/named.rfc1912.zones
zone "westos.com" IN {
        type master;
        file "westos.com.zone";
        allow-update { 172.25.254.209; };
        allow-transfer {172.25.254.209; };
        also-notify {172.25.254.209; };    ##主dns发生变化时,将同步到辅助dns
};
 vim /var/named/westos.com.zone
$TTL 1D
@       IN SOA  dns.westos.com. root.westos.com. (
                                2016112901      ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      dns.westos.com.
dns     A       172.25.254.109
www     A       172.25.254.140
www     A       172.25.254.152
systemctl restart named
(以上的操作是改变www.westos.com的ip地址,并且要辅助dns机与之同步,常规操作则必须删除辅助机中slave/westos.com.zone文件,而每次进行这样的操作过于麻烦,而上面的操作则是选择在主dns机中修改/var/named/westos.com.zone文件中的serial值(上限10位数)以达到在以后的操作中自动同步主dns)
在辅助dns上测试
[[email protected] 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: 18144
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, 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.152
www.westos.com.  86400 IN A 172.25.254.140

;; AUTHORITY SECTION:
westos.com.  86400 IN NS dns.westos.com.

;; ADDITIONAL SECTION:
dns.westos.com.  86400 IN A 172.25.254.109

;; Query time: 0 msec
;; SERVER: 172.25.254.109#53(172.25.254.109)
;; WHEN: Wed Nov 30 09:29:09 EST 2016
;; MSG SIZE  rcvd: 109
(3)远程主机对dns的A记录修改
主dns设置
cp -p /var/named/westos.com.zone /mnt      ##备份到/mnt以便于恢复
vim /etc/named.rfc1912.zones
zone "westos.com" IN {
        type master;
        file "westos.com.zone";
        allow-update { 172.25.254.209; };   ##允许209 更新
        allow-transfer {172.25.254.209; };
        also-notify {172.25.254.209; };
};
chmod 770 /var/named/                      ##对/var/named组执行权限
systemctl restart named                    ##重启服务
辅助dns设置
[1]删除www.westos.com
[[email protected] slaves]# nsupdate
> server 172.25.254.109
> update delete www.westos.com
> send
> quit
测试结果
[[email protected] 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: NXDOMAIN, id: 32405
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1

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

;; AUTHORITY SECTION:
westos.com.  10800 IN SOA dns.westos.com. root.westos.com. 2016112902 86400 3600 604800 10800

;; Query time: 1 msec
;; SERVER: 172.25.254.109#53(172.25.254.109)
;; WHEN: Wed Nov 30 10:17:23 EST 2016
;; MSG SIZE  rcvd: 88
[2]添加www.westos.com
[[email protected] slaves]# nsupdate
> server 172.25.254.109
> update add www.westos.com 86400 A 172.25.254.160
> send
> quit
测试结果
[[email protected] 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: 38963
;; 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.160

;; AUTHORITY SECTION:
westos.com.  86400 IN NS dns.westos.com.

;; ADDITIONAL SECTION:
dns.westos.com.  86400 IN A 172.25.254.109

;; Query time: 0 msec
;; SERVER: 172.25.254.109#53(172.25.254.109)
;; WHEN: Wed Nov 30 10:19:31 EST 2016
;; MSG SIZE  rcvd: 93
恢复
主dns设置
[[email protected] named]# rm -fr westos.com.zone.jnl westos.com.zone
[[email protected] named]# cp /mnt/westos.com.zone /var/named/
(4)主机更新上锁
一般机子对主dns不可以修改A记录但对于有key的机子开放
[[email protected] named]# cp -p /etc/rndc.key /etc/westos.key
[[email protected] named]# cd /mnt
[[email protected] mnt]# dnssec-keygen -a HMAC-MD5 -b 128 -n HOST westos
Kwestos.+157+28134                      ##生成钥匙 -a是加密方式 -b是密码大小 -n是加密用户
[[email protected] mnt]# scp /mnt/Kwestos.+157+28134.private 172.25.254.209:/mnt
[email protected]‘s password:
Kwestos.+157+28134.private                                                   100%  165     0.2KB/s   00:00   
[[email protected] mnt]# scp /mnt/Kwestos.+157+28134.key 172.25.254.209:/mnt
[email protected]‘s password:
Kwestos.+157+28134.key                                                       100%   50     0.1KB/s   00:00  

[[email protected] mnt]# vim /etc/westos.key
key "westos" {
        algorithm hmac-md5;
        secret "Lz3B1zirL3Otb1gIk6917g==";
};

[[email protected] mnt]# vim /etc/named.conf
include "/etc/westos.key";
[[email protected] mnt]# vim /etc/named.rfc1912.zones
zone "westos.com" IN {
        type master;
        file "westos.com.zone";
        allow-update { key westos; };   ##允许key westos 更新
};:
[[email protected] mnt]# systemctl restart named
辅助dns操作
[[email protected] mnt]# nsupdate -k /mnt/Kwestos.+157+28134.private
> server 172.25.254.109       
> update delete www.westos.com
> send
> quit
可以在主dns上测试
(5)ddns
ddns=dhcp+dns
动态dns需要dhcp与dns的协同工作
这里dns所需要的bind6以上的版本,以及dhcp需要3.0以上版本。在操作以前要把原来的westos.com.zone恢复,以免影响后续操作。
主dns设置
yum install dhcp -y
systemctl start dhcpd
systemctl stop firewalld
 setenforce 0
cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcp.conf
vim /etc/dhcp/dhcp.conf
option domain-name "westos.com";
##删除27,28行
subnet 172.25.254.109 netmask 255.255.255.0 {
  range 172.25.254.110 172.25.254.120;
  option routers 172.25.254.109;
}
key westos {
        algorithm hmac-md5;
        secret Lz3B1zirL3Otb1gIk6917g==;
};
zone westos.com. {
primary 127.0.0.1;
key westos
}
systemctl restart dhcpd
systemctl restart named
辅助dns上的设置
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
TYPE=Ethernet
USERCTL=yes
PEERDNS=yes
IPV6INIT=no
PERSISTENT_DHCLIENT=1
systemctl restart network
配置完成后可以在机子上进行测试。


以上是关于DNS设定的主要内容,如果未能解决你的问题,请参考以下文章

DNS设定

ubuntu 设定永久dns

虚拟机即做dns又能上网需要如何设定?

linux学习笔记——IP网关DNS的认识与设定网络端口监测

Linux--IP基础知识 网关设定 dns服务

协议 - DNS