实验环境:
CentOS release 6.6(Final) 两台
IP地址:
172.16.31.3 DNS1
172.16.31.4 DNS2
我们要架设一个本地dns缓存服务器一般需要下面三个软件:
bind-libs.x86_64 #提供库文件
bind-utils.x86_64 #提供工具包
bind.x86_64 #提供主程序包
确认安装:
[root@dns1 ~]# rpm -qa bind-libs bind-libs-9.8.2-0.30.rc1.el6.x86_64 [root@dns1 ~]# rpm -qa bind-utlis [root@dns1 ~]# rpm -qa bind-utils bind-utils-9.8.2-0.30.rc1.el6.x86_64
设置正向反向解析库文件
解析库文件目录在:/var/named/
反向解析库文件创建:
#vim 127.0.0.zone $TTL 600 @ IN SOA localhost. root.localhost. ( 2014121001 1D 5M 7D 1D) IN NS localhost. 3 IN PTR localhost.
正向解析库文件创建:
#vim localhost.zone $TTL 600 @ IN SOA localhsot. root.localhost. ( 2014121001 1D 5M 7D 1D) IN NS localhost. localhost. IN A 127.0.0.1
根文件,这里面的是全球的13个根(当缓存中没有相应相应的ip对应的域名时,本DNS服务器回去找根DNS服务器}
[root@dns1 named]# cat named.ca ; <<>> DiG9.9.4-P2-RedHat-9.9.4-12.P2 <<>> +norec NS . @a.root-servers.net ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY,status: NOERROR, id: 26229 ;; flags: qr aa; QUERY: 1, ANSWER: 13,AUTHORITY: 0, ADDITIONAL: 24 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 1472 ;; QUESTION SECTION: ;. IN NS ;; ANSWER SECTION: . 518400 IN NS a.root-servers.net. . 518400 IN NS b.root-servers.net. . 518400 IN NS c.root-servers.net. . 518400 IN NS d.root-servers.net. . 518400 IN NS e.root-servers.net. . 518400 IN NS f.root-servers.net. . 518400 IN NS g.root-servers.net. . 518400 IN NS h.root-servers.net. . 518400 IN NS i.root-servers.net. . 518400 IN NS j.root-servers.net. . 518400 IN NS k.root-servers.net. . 518400 IN NS l.root-servers.net. . 518400 IN NS m.root-servers.net. ;; ADDITIONAL SECTION: a.root-servers.net. 518400 IN A 198.41.0.4 b.root-servers.net. 518400 IN A 192.228.79.201 c.root-servers.net. 518400 IN A 192.33.4.12 d.root-servers.net. 518400 IN A 199.7.91.13 e.root-servers.net. 518400 IN A 192.203.230.10 f.root-servers.net. 518400 IN A 192.5.5.241 g.root-servers.net. 518400 IN A 192.112.36.4 h.root-servers.net. 518400 IN A 128.63.2.53 i.root-servers.net. 518400 IN A 192.36.148.17 j.root-servers.net. 518400 IN A 192.58.128.30 k.root-servers.net. 518400 IN A 193.0.14.129 l.root-servers.net. 518400 IN A 199.7.83.42 m.root-servers.net. 518400 IN A 202.12.27.33 a.root-servers.net. 518400 IN AAAA 2001:503:ba3e::2:30 c.root-servers.net. 518400 IN AAAA 2001:500:2::c d.root-servers.net. 518400 IN AAAA 2001:500:2d::d f.root-servers.net. 518400 IN AAAA 2001:500:2f::f h.root-servers.net. 518400 IN AAAA 2001:500:1::803f:235 i.root-servers.net. 518400 IN AAAA 2001:7fe::53 j.root-servers.net. 518400 IN AAAA 2001:503:c27::2:30 k.root-servers.net. 518400 IN AAAA 2001:7fd::1 l.root-servers.net. 518400 IN AAAA 2001:500:3::42 m.root-servers.net. 518400 IN AAAA 2001:dc3::35 ;; Query time: 58 msec ;; SERVER: 198.41.0.4#53(198.41.0.4) ;; WHEN: Wed Apr 23 14:52:37 CEST 2014 ;; MSG SIZE rcvd: 727
2.文件权限设置及更改属组
[root@dns1 named]# chown :named localhost.zone [root@dns1 named]# chown :named 127.0.0.zone [root@dns1 named]# ll total 36 -rw-r--r-- 1 root named 124 Dec 10 04:45 127.0.0.zone drwxrwx--- 2 named named 4096 Oct 15 21:28data drwxrwx--- 2 named named 4096 Oct 15 21:28dynamic -rw-r--r-- 1 root named 130 Dec 10 05:21 localhost.zone -rw-r----- 1 root named 2075 Apr 23 2014 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 4096 Oct 15 21:28slaves
好了到此为止一个本地的缓存DNS服务器就配好了
3.启动你的DNS服务器:
如果你的Linux能上网,把DNS改为你的IP即可
[root@dns1 named]# service named start Generating /etc/rndc.key: [ OK ] Starting named: [ OK ] [root@dns1 named]# vi/etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE="eth0" BOOTPROTO="static" NM_CONTROLLED="yes" HWADDR=08:00:27:98:d8:88 ONBOOT="yes" TYPE="Ethernet" IPADDR=172.16.31.3 NETMASK=255.255.0.0 GATEWAY=172.16.0.1 DNS=172.16.31.3
[root@dns1 named]# service network restart Shutting down interface eth0: [ OK ] Shutting down loopback interface: [ OK ] Bringing up loopback interface: [ OK ] Bringing up interface eth0: Determining if ip address 172.16.31.3 isalready in use for device eth0... [ OK ]
4.进行测试:
本地缓存服务器成功测试:
[root@dns1 named]# dig -t NS localhost ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.30.rc1.el6<<>> -t NS localhost ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY,status: NOERROR, id: 8865 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1,AUTHORITY: 0, ADDITIONAL: 2 ;; QUESTION SECTION: ;localhost. IN NS ;; ANSWER SECTION: localhost. 86400 IN NS localhost. ;; ADDITIONAL SECTION: localhost. 86400 IN A 127.0.0.1 localhost. 86400 IN AAAA ::1 ;; Query time: 6 msec ;; SERVER: 172.16.0.1#53(172.16.0.1) ;; WHEN: Wed Dec 10 05:28:22 2014 ;; MSG SIZE rcvd: 85
网络连通性测试:
[root@dns1 named]# dig -t NS baidu.com ; <<>> DiG9.8.2rc1-RedHat-9.8.2-0.30.rc1.el6 <<>> -t NS baidu.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY,status: NOERROR, id: 8767 ;; flags: qr rd ra; QUERY: 1, ANSWER: 5,AUTHORITY: 0, ADDITIONAL: 5 ;; QUESTION SECTION: ;baidu.com. IN NS ;; ANSWER SECTION: baidu.com. 86400 IN NS ns2.baidu.com. baidu.com. 86400 IN NS ns4.baidu.com. baidu.com. 86400 IN NS ns3.baidu.com. baidu.com. 86400 IN NS dns.baidu.com. baidu.com. 86400 IN NS ns7.baidu.com. ;; ADDITIONAL SECTION: ns4.baidu.com. 75356 IN A 220.181.38.10 ns2.baidu.com. 75355 IN A 61.135.165.235 ns3.baidu.com. 75356 IN A 220.181.37.10 ns7.baidu.com. 75356 IN A 119.75.219.82 dns.baidu.com. 75355 IN A 202.108.22.220 ;; Query time: 36 msec ;; SERVER: 172.16.0.1#53(172.16.0.1) ;; WHEN: Wed Dec 10 05:27:48 2014 ;; MSG SIZE rcvd: 197
下一篇将介绍本地DNS服务器的搭建及实现正向反向解析
本文出自 “龙之守护” 博客,请务必保留此出处http://sohudrgon.blog.51cto.com/3088108/1588269
原文地址:http://sohudrgon.blog.51cto.com/3088108/1588269