一、實驗環境:
操作系統:CentOS6.5
二、拓撲結構:
角色 主機名 IP地址 LDNS DC01 192.168.2.2/24 DNS ns1 192.168.2.41/24 www VIP 192.168.2.18/24 mail EX2013A 192.168.2.31/24
三、配置腳本
1)安裝DNS服務:
1 2 3 4 5 6 7 8 9 [root@ns1 ~]# yum list bind* [root@ns1 ~]# yum install bind [root@ns1 ~]# ls /etc/|grep named # 安裝完成之後配置文件自動生成 named named.conf named.iscdlv.key named.rfc1912.zones named.root.key [root@ns1 ~]# mv /etc/named.conf /etc/named.conf.ori # 此處我們不使用默認文件,手工配置服務參數2)配置/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 options { directory "/var/named"; //DNS數據庫位置 }; zone "." IN { type hint; file "named.ca"; // 指定全球13台根節點服務器所在位置 }; zone "localhost" IN { // 正向解析本機IP地址 type master; file "localhost.zone"; }; zone "0.0.127.in-addr.arpa" IN { // 反向解析本機域名 type master; file "named.local"; }; zone "stephenzhou.net" IN { // 添加域記錄 type master; file "stephenzhou.net.zone"; };並且需要修改配置文件屬組:
1 2 3 4 5 [root@ns1 etc]# ll /etc/named.conf -rw-r--r--. 1 root root 220 Jul 10 23:24 /etc/named.conf [root@ns1 etc]# chown :named /etc/named.conf [root@ns1 etc]# ll /etc/named.conf -rw-r--r--. 1 root named 220 Jul 10 23:24 /etc/named.conf3)配置named.ca:
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 [root@ns1 etc]# cd /var/named/ [root@ns1 named]# ls data dynamic named.ca named.empty named.localhost named.loopback slaves [root@ns1 named]# dig -t NS . # 13台根域名服務器記錄 ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> -t NS . ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 51882 ;; flags: qr rd ra; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 0 ;; QUESTION SECTION: ;. IN NS ;; ANSWER SECTION: . 59687 IN NS k.root-servers.net. . 59687 IN NS j.root-servers.net. . 59687 IN NS f.root-servers.net. . 59687 IN NS m.root-servers.net. . 59687 IN NS e.root-servers.net. . 59687 IN NS d.root-servers.net. . 59687 IN NS c.root-servers.net. . 59687 IN NS l.root-servers.net. . 59687 IN NS b.root-servers.net. . 59687 IN NS g.root-servers.net. . 59687 IN NS i.root-servers.net. . 59687 IN NS h.root-servers.net. . 59687 IN NS a.root-servers.net. ;; Query time: 6 msec ;; SERVER: 116.228.111.118#53(116.228.111.118) ;; WHEN: Thu Jul 10 23:26:32 2014 ;; MSG SIZE rcvd: 228 [root@ns1 named]# mv named.ca named.ca.ori [root@ns1 named]# dig -t NS . > named.ca [root@ns1 named]# chown :named named.ca # 修改屬組
4)配置localhost.zone正向解析文件:
1 2 3 4 5 6 7 8 9 10 11 $TTL 600 @ IN SOA localhost. admin.localhost. ( 2014071001 1H 10M 1W 1D ) IN NS localhost. localhost. IN A 127.0.0.15)配置named.local反向解析文件:
1 2 3 4 5 6 7 8 9 10 $TTL 600 @ IN SOA localhost. admin.localhost. ( 2014071101 1H 10M 1W 1D ) IN NS localhost. 1 IN PTR localhost.6)配置stephenzhou.net.zone正向解析文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 $TTL 600 $ORIGIN stephenzhou.net. @ IN SOA ns1.stephenzhou.net. administrator.stephenzhou.net. ( 2014071101 1H 10M 1W 1D ) IN NS ns1 IN MX 1 mail ns1 IN A 192.168.2.41 mail IN A 192.168.2.31 www IN A 192.168.2.18 autodiscover IN A 192.168.2.31修改屬組:
1 [root@ns1 named]# chown :named localhost.zone named.local stephenzhou.net.zone7)測試DNS服務:
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 [root@ns1 named]# service named configtest zone localhost/IN: loaded serial 2014071001 zone 0.0.127.in-addr.arpa/IN: loaded serial 2014071101 [root@ns1 named]# rndc-confgen -r /dev/urandom -a # CentOS6.x必須單獨寫rndc.key文件 wrote key file "/etc/rndc.key" [root@ns1 named]# service named start Starting named: [ OK ] [root@ns1 named]# netstat -tunlp|grep :53 # 查看端口使用情況 tcp 0 0 192.168.3.41:53 0.0.0.0:* LISTEN 2204/named tcp 0 0 192.168.2.41:53 0.0.0.0:* LISTEN 2204/named tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 2204/named udp 0 0 192.168.3.41:53 0.0.0.0:* 2204/named udp 0 0 192.168.2.41:53 0.0.0.0:* 2204/named udp 0 0 127.0.0.1:53 0.0.0.0:* 2204/named [root@ns1 named]# dig -t NS localhost # 查看本機正向解析 ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> -t NS localhost ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 63358 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0 ;; QUESTION SECTION: ;localhost. IN NS ;; ANSWER SECTION: localhost. 10800 IN NS localhost. ;; Query time: 7 msec ;; SERVER: 116.228.111.118#53(116.228.111.118) ;; WHEN: Fri Jul 11 00:13:43 2014 ;; MSG SIZE rcvd: 41 [root@ns1 named]# dig -x 127.0.0.1 # 查看本機反向解析 ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> -x 127.0.0.1 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 39683 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0 ;; QUESTION SECTION: ;1.0.0.127.in-addr.arpa. IN PTR ;; ANSWER SECTION: 1.0.0.127.in-addr.arpa. 9945 IN PTR localhost. ;; Query time: 3 msec ;; SERVER: 116.228.111.118#53(116.228.111.118) ;; WHEN: Fri Jul 11 00:15:02 2014 ;; MSG SIZE rcvd: 63
8)修改LDNS:
1 2 3 4 [root@ns1 ~]# cat /etc/resolv.conf nameserver 192.168.2.2 nameserver 192.168.1.19)修改防火牆(分別添加tcp/udp的53號端口):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 [root@ns1 named]# cat /etc/sysconfig/iptables # Firewall configuration written by system-config-firewall # Manual customization of this file is not recommended. *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -p tcp --dport 53 -j ACCEPT -A INPUT -p udp --dport 53 -j ACCEPT -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT -A INPUT -j REJECT --reject-with icmp-host-prohibited -A FORWARD -j REJECT --reject-with icmp-host-prohibited COMMIT10)測試結果:
本機:
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 80 81 [root@ns1 named]# dig -t NS stephenzhou.net ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> -t NS stephenzhou.net ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 21983 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ;; QUESTION SECTION: ;stephenzhou.net. IN NS ;; ANSWER SECTION: stephenzhou.net. 600 IN NS ns1.stephenzhou.net. ;; ADDITIONAL SECTION: ns1.stephenzhou.net. 600 IN A 192.168.2.41 ;; Query time: 0 msec ;; SERVER: 192.168.2.41#53(192.168.2.41) ;; WHEN: Fri Jul 11 02:36:02 2014 ;; MSG SIZE rcvd: 67 [root@ns1 named]# dig mail.stephenzhou.net ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> mail.stephenzhou.net ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 9155 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1 ;; QUESTION SECTION: ;mail.stephenzhou.net. IN A ;; ANSWER SECTION: mail.stephenzhou.net. 600 IN A 192.168.2.31 ;; AUTHORITY SECTION: stephenzhou.net. 600 IN NS ns1.stephenzhou.net. ;; ADDITIONAL SECTION: ns1.stephenzhou.net. 600 IN A 192.168.2.41 ;; Query time: 0 msec ;; SERVER: 192.168.2.41#53(192.168.2.41) ;; WHEN: Fri Jul 11 02:32:34 2014 ;; MSG SIZE rcvd: 88 [root@ns1 named]# ll stephenzhou.net.zone -rw-r--r--. 1 root named 256 Jul 11 02:27 stephenzhou.net.zone [root@ns1 named]# dig -t A www.stephenzhou.net ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> -t A www.stephenzhou.net ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 40607 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1 ;; QUESTION SECTION: ;www.stephenzhou.net. IN A ;; ANSWER SECTION: www.stephenzhou.net. 600 IN A 192.168.2.18 ;; AUTHORITY SECTION: stephenzhou.net. 600 IN NS ns1.stephenzhou.net. ;; ADDITIONAL SECTION: ns1.stephenzhou.net. 600 IN A 192.168.2.41 ;; Query time: 0 msec ;; SERVER: 192.168.2.41#53(192.168.2.41) ;; WHEN: Fri Jul 11 02:33:53 2014 ;; MSG SIZE rcvd: 87 [root@ns1 named]# host -t A www.stephenzhou.net www.stephenzhou.net has address 192.168.2.18 [root@ns1 named]# host -t A mail.stephenzhou.net mail.stephenzhou.net has address 192.168.2.31 [root@ns1 named]# host -t NS stephenzhou.net stephenzhou.net name server ns1.stephenzhou.net. [root@ns1 named]# host -t MX stephenzhou.net stephenzhou.net mail is handled by 1 mail.stephenzhou.net.
遠端:
本文出自 “小鬼的地盤” 博客,請務必保留此出處http://zhoufwind.blog.51cto.com/1029821/1437079