centos 安装配置 bind

ZephyrXT 发布于 阅读:28

http://www.isc.org/downloads/current(官网地址)


rpm -qa | grep bind   看看本机装了没有

yum install bind*       把有关于bind的全装上,
yum install   caching-nameserver   这个也是必要的

cd /etc/
编辑配置文件:named.caching-nameserver.conf

vi named.caching-nameserver.conf

修改后:
options {
 listen-on port 53 { any; };
 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";
        forwarders     { 8.8.8.8;};
 // Those options should be used carefully because they disable port
 // randomization
 // query-source    port 53; 
 // query-source-v6 port 53;

 allow-query     { any; };
 allow-query-cache { any; };
};
logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};
view localhost_resolver {
 match-clients     { any; };
 match-destinations { any; };
 recursion yes;
 include "/etc/named.rfc1912.zones";
};

注:转发配置 转发的作用在于,如果找不到某个解析,转发到公开的DNS服务器来处理。
forwarders {
        8.8.8.8;
};

编辑域名文件:named.rfc1912.zones
cd /etc
vi  named.rfc1912.zones

//定义一个正向域 zephyrtest.com ,定义正向解析文件名 zephyrtest.com.zone
//定义反向域 ,定义反向解析文件名 1.2.3.zone
[root@testserver etc]# vi named.rfc1912.zones
//test

zone "zephyrtest.com" IN {
type master;
  file "zephyrtest.com.zone";
allow-update { none; };
};

zone "3.2.1.in-addr.arpa" IN {
type master;
file "1.2.3.zone";
allow-update { none; };
};

编辑正向解析文件 zephyrtest.com.zone
cd /var/named
cp -p localdomain.zone zephyrtest.com.zone
vi zephyrtest.com.zone

$TTL 86400
@  IN SOA localhost root (
     42  ; serial (d. adams)
     3H  ; refresh
     15M  ; retry
     1W  ; expiry
     1D )  ; minimum
         IN NS  localhost
localhost IN A  127.0.0.1
         IN NS  zephyrtest.com
www      IN A  1.2.3.4
@               IN A            1.2.3.4
bbs             IN A            5.6.7.8

编辑反向解析文件 
cd /var/named
cp -p named.local 1.2.3.zone
vi 1.2.3.zone

$TTL 86400
@       IN      SOA     localhost. root.localhost.  (
                                      1997022700 ; Serial
                                      28800      ; Refresh
                                      14400      ; Retry
                                      3600000    ; Expire
                                      86400 )    ; Minimum
        IN      NS      zephyrtest.com.
4       IN      PTR     zephyrtest.com.

4是指的是IP:1.2.3.4 的最后一个数

启动named
# service named start
# /etc/init.d/named start

netstat -ntl //查看DNS服务器53端口是否打开

测试
把本机的DNS改为我们用来测试的机器,如192.168.1.2
打开终端(WINDOWS下从开始->运行输入cmd),运行nslookup zephyrtest.com,如果看到如下输出,表示设置成功。

Name: zephyrtest.com
Address: 1.2.3.4

或是直接用ping zephyrtest.com来看效果,注意WINDOWS会缓存DNS结果,需要每次PING后用”ipconfig /flushdns”来清空DNS缓存。

命令格式: nslookup -qa=ptr xxx.xxx.xxx.xxx

-qa=ptr说明查询类型是PTR也就是反向查询 后面请跟上你要做反向解析的IP地址 (反向解析是从IP查主机名的解析,所以不用与域名的解析混淆)

如下正确PTR解析的输出结果
4.3.2.1.in-addr.arpa    name = zephyrtest.com

配置selinux
[root@testserver etc]# setup
弹出一个对话框。我们要进行的是防火墙配置,步骤如下:
选择“Firewall Configuration”---按 “Tab”键切换到“Run Tool”—回车—“Security Level”选项要在“Enabled”前面按一下“Tab”键---“SelLinux”选项要选“Disabled”—按一下“Tab”键---选中“Customize”---弹出新对话框---在“Other Port”栏目里输入“53:tcp 53:udp”—“OK”—返回上一个对话框—“OK”—对话框自动关闭。配置完成。

启动named
# service named start
# /etc/init.d/named start

修改配置后记得重启
# service named restart
# /etc/init.d/named restart

把bind设为开机自启动
chkconfig named  on 345

 

参考:

DNS配置-BIND安装配置全过程
https://bbs.zephyrxt.com/thread-6151-1-1.html

centos 5.4安装配置bind-9.7.3
https://bbs.zephyrxt.com/thread-6150-1-1.html
CentOS安装Bind
https://bbs.zephyrxt.com/thread-6149-1-1.html
CentOS 5安装BIND DNS服务器
https://bbs.zephyrxt.com/thread-6148-1-1.html
Bind服务的安装与配置全过程-DNS配置
https://bbs.zephyrxt.com/thread-6146-1-1.html
Godaddy注册DNS服务器相关方法
https://bbs.zephyrxt.com/thread-6131-1-1.html