DNS: Master and slave
本文配置Linux中的DNS的主从架构。
主DNS:192.168.232.151
从DNS:192.168.232.152
一、主端
将/etc/rndc.key传到从端:
1 2 3 4 5 6 7 8 |
[root@ns ~]# scp /usr/local/named/etc/rndc.key 192.168.232.152:/software The authenticity of host '192.168.232.152 (192.168.232.152)' can't be established. RSA key fingerprint is cf:e0:2d:5b:42:af:4e:02:3b:e4:05:f7:46:c7:6c:a1. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.232.152' (RSA) to the list of known hosts. root@192.168.232.152's password: rndc.key 100% 77 0.1KB/s 00:00 [root@ns ~]# |
配置文件:特定zone的修改:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
[root@ns ~]# cat /usr/local/named/etc/named.conf key "rndc-key" { algorithm hmac-md5; secret "JY52sPoTdeBWiBBquOchqg=="; }; controls { inet 127.0.0.1 port 953 allow { any; } keys { "rndc-key"; }; }; options { directory "/usr/local/named/var"; pid-file "named.pid"; }; zone "." IN { type hint; file "named.root"; }; zone "localhost" IN { type master; file "localhost.zone"; allow-update { none; }; }; zone "0.0.127.in-addr.arpa" IN { type master; file "named.local"; allow-update { none; }; }; zone "d-prototype.com" IN { type master; file "dprototype.zone"; allow-update { none; }; notify yes; also-notify { 192.168.232.152; }; allow-transfer { 192.168.232.152; }; }; zone "232.168.192.in-addr.arpa" IN { type master; file "dprototype.local"; allow-update { none; }; notify yes; also-notify { 192.168.232.152; }; allow-transfer { 192.168.232.152; }; }; [root@ns ~]# |
如上,可以看到,正解与反解zone中都添加了:
notify yes;
also-notify { 192.168.232.152; };
allow-transfer { 192.168.232.152; };
以声明从端的位置。
这样主端就配置好了。
二、从端
配置文件:/etc/named.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
[root@oradb 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. // key "rndc-key" { algorithm hmac-md5; secret "JY52sPoTdeBWiBBquOchqg=="; }; controls { inet 127.0.0.1 port 953 allow { any; } keys { "rndc-key"; }; }; options { listen-on port 53 { 192.168.232.152; }; 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; }; recursion yes; dnssec-enable yes; dnssec-validation yes; /* Path to ISC DLV key */ bindkeys-file "/etc/named.iscdlv.key"; managed-keys-directory "/var/named/dynamic"; }; logging { channel default_debug { file "data/named.run"; severity dynamic; }; }; zone "." IN { type hint; file "named.ca"; }; zone "d-prototype.com" IN { type slave; file "slaves/dprototype.zone"; #allow-update { none; }; #notify yes; #also-notify { 192.168.232.152; }; #allow-transfer { 192.168.232.152; }; masters { 192.168.232.151; }; }; zone "232.168.192.in-addr.arpa" IN { type slave; file "slaves/dprototype.local"; #allow-update { none; }; #notify yes; #also-notify { 192.168.232.152; }; #allow-transfer { 192.168.232.152; }; masters { 192.168.232.151; }; }; include "/etc/named.rfc1912.zones"; include "/etc/named.root.key"; [root@oradb named]# |
可以看到,添加了zone的声明:
type slave;
file “slaves/dprototype.zone”;
masters { 192.168.232.151; };
指向到主端即可。
其中,file的定义,会在:/var/named/slaves,路径下,自动生成主端同步过来的DNS配置。
三、测验一下:
主库,保证DNS启动:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
[root@ns ~]# ps -ef | grep --color named root 61433 1 0 18:21 ? 00:00:00 /usr/local/named/sbin/named -c /usr/local/named/etc/named.conf root 61484 44604 0 18:28 pts/1 00:00:00 grep --color named [root@ns ~]# [root@ns ~]# /usr/local/named/sbin/rndc status version: BIND 9.10.4-P2 <id:7658a94> boot time: Sat, 30 Jul 2016 01:21:45 GMT last configured: Sat, 30 Jul 2016 01:21:45 GMT CPUs found: 1 worker threads: 1 UDP listeners per interface: 1 number of zones: 103 debug level: 0 xfers running: 0 xfers deferred: 0 soa queries in progress: 0 query logging is OFF recursive clients: 0/0/1000 tcp clients: 0/100 server is up and running [root@ns ~]# |
备库:
当前DNS服务是关闭的:
1 2 3 4 5 6 7 |
[root@oradb named]# service named status rndc: connect failed: 127.0.0.1#953: connection refused named is stopped [root@oradb named]# [root@oradb named]# rndc status rndc: connect failed: 127.0.0.1#953: connection refused [root@oradb named]# |
删掉从主端同步过来的数据:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
[root@oradb named]# pwd /var/named [root@oradb named]# [root@oradb named]# ls -ltr total 32 -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 Dec 15 2009 named.empty -rw-r----- 1 root named 3171 Jan 11 2016 named.ca drwxr-x--- 6 root named 4096 Jul 29 17:53 chroot drwxrwx--- 2 named named 4096 Jul 29 18:05 data drwxrwx--- 2 named named 4096 Jul 29 18:05 dynamic drwxrwx--- 2 named named 4096 Jul 29 18:12 slaves [root@oradb named]# [root@oradb named]# ls -ltr slaves/ total 8 -rw-r--r-- 1 named named 393 Jul 29 18:12 dprototype.local -rw-r--r-- 1 named named 354 Jul 29 18:12 dprototype.zone [root@oradb named]# [root@oradb named]# rm -rf slaves/* [root@oradb named]# [root@oradb named]# ls -ltr slaves/ total 0 [root@oradb named]# |
启动服务:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
[root@oradb named]# service named start Starting named: [ OK ] [root@oradb named]# [root@oradb named]# rndc status version: 9.8.2rc1-RedHat-9.8.2-0.47.rc1.el6 CPUs found: 1 worker threads: 1 number of zones: 21 debug level: 0 xfers running: 0 xfers deferred: 0 soa queries in progress: 0 query logging is OFF recursive clients: 0/0/1000 tcp clients: 0/100 server is up and running [root@oradb named]# [root@oradb named]# ps -ef | grep named named 9547 1 0 18:30 ? 00:00:00 /usr/sbin/named -u named -t /var/named/chroot root 9559 8286 0 18:30 pts/0 00:00:00 grep named [root@oradb named]# |
查看数据目录:
1 2 3 4 5 6 7 8 9 10 |
[root@oradb named]# pwd /var/named [root@oradb named]# ls chroot data dynamic named.ca named.empty named.localhost named.loopback slaves [root@oradb named]# [root@oradb named]# ls -ltr slaves/ total 8 -rw-r--r-- 1 named named 393 Jul 29 18:30 dprototype.local -rw-r--r-- 1 named named 354 Jul 29 18:30 dprototype.zone [root@oradb named]# |
从端,正解:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
[root@oradb named]# cat slaves/dprototype.zone $ORIGIN . $TTL 86400 ; 1 day d-prototype.com IN SOA localhost. root.localhost. ( 20160729 ; serial 28800 ; refresh (8 hours) 14400 ; retry (4 hours) 3600000 ; expire (5 weeks 6 days 16 hours) 86400 ; minimum (1 day) ) NS localhost. $ORIGIN d-prototype.com. master A 192.168.232.30 www A 192.168.232.12 [root@oradb named]# |
从端,反解:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
[root@oradb named]# cat slaves/dprototype.local $ORIGIN . $TTL 86400 ; 1 day 232.168.192.in-addr.arpa IN SOA ns.d-prototype.com. root.d-prototype.com. ( 20160729 ; serial 7200 ; refresh (2 hours) 3600 ; retry (1 hour) 43200 ; expire (12 hours) 86400 ; minimum (1 day) ) NS ns.d-prototype.com. $ORIGIN 232.168.192.in-addr.arpa. 12 PTR www.d-prototype.com. 30 PTR master.d-prototype.com. [root@oradb named]# |
nslookup测一下从端:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
[root@oradb named]# nslookup > > server 192.168.232.152 Default server: 192.168.232.152 Address: 192.168.232.152#53 > > 192.168.232.12 Server: 192.168.232.152 Address: 192.168.232.152#53 12.232.168.192.in-addr.arpa name = www.d-prototype.com. > > master.d-prototype.com Server: 192.168.232.152 Address: 192.168.232.152#53 Name: master.d-prototype.com Address: 192.168.232.30 > > exit [root@oradb named]# |
测试成功。
DNS的主从,搭建完成。
——————————————————
Done。