#!/bin/bash yum -y install openssl-devel perl-devel cd /opt wget http://ftp.isc.org/isc/bind9/9.7.2-P3/bind-9.7.2-P3.tar.gz tar -zxvf bind-9.7.2-P3.tar.gz cd bind-9.7.2-P3 ./configure --enable-largefile --enable-threads --prefix=/usr/local/named make make install cd /usr/local/named/etc /usr/local/named/sbin/rndc-confgen > /usr/local/named/etc/rndc.conf tail -n 10 rndc.conf |head -n9 |sed -e s/#\//g > named.conf mkdir -p /usr/local/named/data cd /usr/local/named/ wget ftp://ftp.rs.internic.net/domain/named.root exit 1 执行sh脚本; 第二步、修改配置文件 named.conf、rndc.conf这两个配置文件位置为:/usr/local/named/etc 域名相关的配置文件位置为:/usr/local/named 2-1、修改named.conf 修改后内容如下: options { directory "/usr/local/named"; pid-file "named.pid"; listen-on port 53 {any;}; allow-query {any;}; dump-file "/usr/local/named/data/cache_dump.db"; statistics-file "/usr/local/named/data/named_stats.txt"; forward only; //增加转发功能 forwarders { 202.106.0.20; //北京网通DNS服务器地址 139.175.10.20; }; }; key "rndc-key" { algorithm hmac-md5; secret "jhdbq+u4cE6KJdrJ6m6yAA=="; //注意“”号中的内容需要和rndc.conf中生成的key值一样; }; controls { inet 127.0.0.1 port 953 allow { 127.0.0.1; } keys { "rndc-key"; }; }; 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 "localhost.rev"; allow-update { none; }; }; zone "qiu.com" IN { type master; file "qiu.com.zone"; allow-update { none; }; }; zone "1.168.192.in-addr.arpa" IN { type master; file "192.168.1.zone"; allow-update { none; }; }; 2-2、生成域名的配置文件 cd /usr/local/named 修改localhost.zone文件: vi localhost.zone 内容如下: $TTL 3600 @ IN SOA @ root ( 20100923 ;serial (d. adams) 3H ;refresh 15M ;retry 1W ;expiry 3600) ;minimum IN NS @ IN A 127.0.0.1 修改localhost.rev文件: vi localhost.rev 内容如下: $TTL 3600 @ IN SOA localhost. root.localhost. ( 20100923 ; serial 3600 ; refresh every hour 900 ; retry every 15 minutes 3600000 ; expire 1000 hours 3600) ; minimun 1 hour IN NS localhost. 1 IN PTR localhost. 修改qiu.com.zone域名解析文件: vi qiu.com.zone 内容如下: $TTL 86400 @ IN SOA dns.qiu.com. root.qiu.com. ( 420000 ; serial (d. adams) 3H ; refresh 15M ; retry 1W ; expiry 1D ) ; minimum IN NS dns.qiu.com. dns IN A 192.168.1.107 www IN A 192.168.1.107 qiu.com. IN MX 5 mail.qiu.com. bbs IN CNAME www mail IN A 192.168.1.6 修改反向解析文件192.168.1.zone vi 192.168.1.zone 内容如下: $TTL 86400 @ IN SOA dns.qiu.com. root.qiu.com. ( 1997022700 ; serial (d. adams) 28800 ; refresh 14400 ; retry 3600000 ; expiry 86400) ; minimum IN NS dns.qiu.com. 107 IN PTR dns.qiu.com. 107 IN PTR www.qiu.com. 6 IN PTR mail.qiu.com. 第三步 测试 启动bind /usr/local/named/sbin/named -gc /usr/local/named/etc/named.conf & nslookup方式测试 正向查询 #nslookup >www.qiu.com Server: 192.168.1.107 Address: 192.168.1.107#53 Name: www.qiu.com Address: 192.168.64.128 反向查询 >192.168.1.107 Server: 192.168.1.107 Address: 192.168.1.107#53 107.1.168.192.in-addr.arpa name = www.qiu.com. 别名查询 > set type=CNAME >bbs.qiu.com Server: 192.168.1.107 Address: 192.168.1.107#53 bbs.qiu.com canonical name = www.qiu.com. 查询SOA >set type=SOA >qiu.com Server: 192.168.1.107 Address: 192.168.1.107#53 qiu.com origin = dns.qiu.com mail addr = root.qiu.com serial = 420000 r efresh = 10800 retry = 900 expire = 604800 minimum = 86400 查询NS >set type=NS >qiu.com Server: 192.168.1.107 Address: 192.168.1.107#53 qiu.com mail exchanger = 5 mail.qiu.com. > set type=NS > qiu.com Server: 192.168.1.107 Address: 192.168.1.107#53 qiu.com nameserver = dns.qiu.com. 查询MX >set type=MX >qiu.com Server: 192.168.1.107 Address: 192.168.1.107#53 qiu.com nameserver = dns.qiu.com. > set type=MX > qiu.com Server: 192.168.1.107 Address: 192.168.1.107#53 qiu.com mail exchanger = 5 mail.qiu.com.