DNS在Linux服务器上的服务名是named,而named服务依赖软件bind。 环境: 系统版本:VBOX虚拟机centos6.0。 本机内网IP 192.168.2.198。 一、安装软件bind。 1.显示bind相关的软件包。 [root@localhost ~]# yum list bind* bind.i686 bind-chroot.i686 bind-devel.i686 bind-dyndb-ldap.i686 bind-libs.i686 bind-sdb.i686 bind-utils.i686 2.安装必要包。主要安装三个软件包,其他的目前没有必要安装。bind安装成功后服务器是named。 [root@service ~]# yum install bind bind-libs bind-utils -y 3.查看bind安装产生的文件。主要用到两个文件。如下: [root@localhost ~]# rpm -ql bind | less /etc/NetworkManager/dispatcher.d/13-named /etc/logrotate.d/named /etc/named /etc/named.conf----------------主配置文件 /etc/named.iscdlv.key /etc/named.rfc1912.zones-------zone配置文件,include到主配置文件 /etc/named.root.key /etc/portreserve/named /etc/rc.d/init.d/named /etc/rndc.conf /etc/rndc.key /etc/sysconfig/named ....很多行.... 二、配置DNS缓存服务器 1.打开/etc/named.conf文件配置修改options配置块内以下选项: listen-on port 53 { 127.0.0.1; }; 改为 listen-on port 53 { 127.0.0.1; 192.168.2.198;}; //192.168.2.198是我的内网IP,根据自己情况修改。 #listen-on-v6 port 53 { ::1; }; //注释掉,如果不用的话。 allow-query { localhost; }; 改为 allow-query { any; }; 保存退出; 2.打开配置/etc/named.rfc1912.zones, 即主配置文件named.conf底部include进来的zone文件。 注释掉bind自动生成的除以下zone块,也就是除了以下两块意外的都注释掉: zone "localhost" IN { //正向解析配置 type master; file "named.localhost"; //文件相对于/var/named/目录 allow-update { none; }; }; zone "1.0.0.127.in-addr.arpa" IN { //反向解析配置 type master; file "named.loopback"; //文件相对于/var/named/目录 allow-update { none; }; }; 3.配置正向解析文件 [root@localhost named]# vim /var/named/named.localhost 填写以下内容: $TTL 1D @ IN SOA localhost. root.localhost. ( 201406251006 ; serial //序列号,随便写我一般写成单签日期时间 1D ; refresh //命令slave多久进行一次主动更新。 1H ; retry //如果到了refresh的时间,但是slave却无法连接master时,那么多久之后,slave会再次的主动尝试与主机连线。 1W ; expire //如果slave一直无法与master连接上,那么经过多久的时间后,则命令slave不要在连接master了。 3H ) ; minimum //没有指定生存期的数据,可以保存在数据库中的时间,及TTL IN NS localhost. IN A 127.0.0.1 4.配置反向解析文件,实际上就是把正向解析的配置文件复制一份,然后把里面的A记录反过来写“A”写成“PTR” [root@localhost named]# vim /var/named/named.loopback 填写如下内容: $TTL 1D @ IN SOA localhost. root.localhost. ( 201406251006 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum IN NS localhost. IN PTR localhost. 5.修改named的相关文件属组为named [root@localhost named]# chown :named /var/named/named* 6.检查配置文件,相关命令named-checkconf、named-checkzone [root@localhost named]# named-checkconf [/etc/named.conf] //检查主配置文件,如果没有输出错误信息表示正常。 [root@localhost named]# named-checkzone "localhost" /var/named/named.localhost //检查正向解析配置 zone localhost/IN: loaded serial 20140625 OK [root@localhost named]# named-checkzone "1.0.0.127.in-addr.arpa" /var/named/named.loopback //检查反向解析配置 zone 1.0.0.127.in-addr.arpa/IN: loaded serial 20140625 OK 7.启动named服务 [root@localhost named]# service named start //或者用/etc/init.d/named start启动 启动 named: [确定] [root@localhost named]# service named status //查看服务运行状态 version: 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 CPUs found: 1 worker threads: 1 number of zones: 18 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 named (pid 2144) 正在运行... 8.测试NDS a.使用命令dig测试 [root@localhost named]# dig -t A localhost @127.0.0.1 //后面@127.0.0.1表示用本机解析,如果不想每次都写修改/etc/resolv.conf文件,添加nameserver 127.0.0.1 ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> -t A localhost @127.0.0.1 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 58945 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 0 ;; QUESTION SECTION: ;localhost. IN A ;; ANSWER SECTION: localhost. 86400 IN A 127.0.0.1 ;; AUTHORITY SECTION: localhost. 86400 IN NS localhost. ;; Query time: 3 msec ;; SERVER: 127.0.0.1#53(127.0.0.1) ;; WHEN: Wed Jun 25 10:25:28 2014 ;; MSG SIZE rcvd: 57 [root@localhost named]# dig -t NS localhost @127.0.0.1 ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> -t NS localhost @127.0.0.1 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 36123 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ;; QUESTION SECTION: ;localhost. IN NS ;; ANSWER SECTION: localhost. 86400 IN NS localhost. ;; ADDITIONAL SECTION: localhost. 86400 IN A 127.0.0.1 ;; Query time: 2 msec ;; SERVER: 127.0.0.1#53(127.0.0.1) ;; WHEN: Wed Jun 25 10:29:55 2014 ;; MSG SIZE rcvd: 57 b.使用nslookup命令测试 [root@localhost named]# nslookup > server 127.0.0.1 Default server: 127.0.0.1 Address: 127.0.0.1#53 > set q=A > localhost Server: 127.0.0.1 Address: 127.0.0.1#53 Name: localhost Address: 127.0.0.1 > set q=NS > localhost Server: 127.0.0.1 Address: 127.0.0.1#53 localhost nameserver = localhost. >exit (责任编辑:IT) |