教你搭建自己专有的DNS服务器
2012-06-03 14:19:08 来源:熊熊看世界 评论:0 点击:
DNS服务(Domain Name Service)是互联网上至关重要的服务之一。基本上所有的互联网应用首先都要基于正确、快速的DNS域名解析。前段时间5.19暴风影音事件,也是由于DNS服务受到影响而造成大面积INTERNET服务受影响;其实很多互联网服务不正常的时候,也常与DNS服务有关,所以排查故障时,DNS是必须首先考虑的部分。搭建一个安全、快速、独有的DNS服务器也显得尤为重要。
目前使用最为广泛的DNS服务器软件是BIND。BIND是一款开放源码的DNS服务器软件,由美国加州大学Berkeley分校开发和维护的,全名为Berkeley Internet Name Domain,支持各种unix平台和windows平台,官方网站:http://www.isc.org/ 。下面就谈谈如何在UNIX下搭建一个安全而有效的DNS服务器。
1、下载最新版的BIND ,现在最新稳定版为bind-9.6.0-P1.tar.gz。UNIX下下载方法如下:
#mkdir -p /usr/local/src
#cd /usr/local/src
#wget http://ftp.isc.org/isc/bind9/9.6.0-P1/bind-9.6.0-P1.tar.gz
这样就将BIND软件包下载到了/usr/local/src目录下。
2、安装BIND:
#cd /usr/local/src
#tar xzcf bind-9.6.0-P1.tar.gz
#cd bind-9.6.0-P1
#./configure
#make
#make install
如无意外,这样会将BIND默认安装于/usr/local/sbin下(主程序名named),而nslookup等工具会安装于/usr/local/bin下,其配认的配置文件是:/etc/named.conf。若你不希望与/usr/local目录混用,你可以在configure的时候指定目录,如:./configure --prefix=/usr/local/dns9
3、配置BIND9:DNS服务的配置包括2类,一类是BIND启动配置文件(即/etc/named.conf与rndc.conf),另一类是提供各域的域名解析服务配置数据文件(即我们俗称的zone文件。包括但不限于:named.root;db.localhost,db.yourdomainname)。这里我们将示例介绍这几个配置文件:named.conf,rndc.conf,named.root,db.shopgz.com,db.127.0.0,db.61.145.113等。
(1)自动生成配置文件/etc/rndc.conf
#/usr/local/sbin/rndc-confgen > /etc/rndc.conf
上述命令将自动生成rndc.conf,内容大致如下:
# Start of rndc.conf
key "rndc-key" {
algorithm hmac-md5;
secret "******";
};
options {
default-key "rndc-key";
default-server 127.0.0.1;
default-port 953;
};
# End of rndc.conf
# Use with the following in named.conf, adjusting the allow list as needed:
# key "rndc-key" {
# algorithm hmac-md5;
# secret "******";
# };
#
# controls {
# inet 127.0.0.1 port 953
# allow { 127.0.0.1; } keys { "rndc-key"; };
# };
# End of named.conf
(2)生成配置文件/etc/named.conf(需使用vi /etc/named.conf手工生成),主要内容大致如下:
/*
* log option
* 此部分是日志的设置,其中最主要的是file "/var/log/named.log" 这一句指定了日志文件的位置
* 要正常启动named,必须要保证这一文件是存在的,并且named 进程对它有读写权限
*/
logging {
channel default_syslog { syslog local2; severity error; };
channel audit_log { file "/var/log/named.log"; severity error; print-time yes; };
category default { default_syslog; };
category general { default_syslog; };
category security { audit_log; default_syslog; };
category config { default_syslog; };
category resolver { audit_log; };
category xfer-in { audit_log; };
category xfer-out { audit_log; };
category notify { audit_log; };
category client { audit_log; };
category network { audit_log; };
category update { audit_log; };
category queries { audit_log; };
category lame-servers { audit_log; };
};
/*
* 此部分是一些基本的配置项
* directory "/etc/namedb"; 指定域名解析等文件的存放目录(须手动建立);
* listen-on-v6 { any; }; 支持ipv6的请求;
* forwarders {
* your.upper.DNS.address;
* }; 指定前向DNS,当本机无法解析的域名,就会被转发至前向DNS进行解析。
* dump-file "/etc/named_dump.db"; 指定named_dump.db文件的位置。
*/
options {
directory "/etc/namedb";
// listen-on-v6 { any; };
// If you've got a DNS server around at your upstream provider, enter
// its IP address here, and enable the line below. This will make you
// benefit from its cache, thus reduce overall DNS traffic in the Internet.
forwarders {
202.96.128.86;
202.96.128.166;
};
/*
* If there is a firewall between you and nameservers you want
* to talk to, you might need to uncomment the query-source
* directive below. Previous versions of BIND always asked
* questions using port 53, but BIND 8.1 uses an unprivileged
* port by default.
*/
// query-source address * port 53;
/*
* If running in a sandbox, you may have to specify a different
* location for the dumpfile.
*/
dump-file "/etc/named_dump.db";
};
// 接下来的部分就是定义服务域的配置(即zone文件指定与定义)
// Setting up secondaries is way easier and the rough picture for this
// is explained below.
//
// If you enable a local name server, don't forget to enter 127.0.0.1
// into your /etc/resolv.conf so this server will be queried first.
// Also, make sure to enable it in /etc/rc.conf.
zone "." {
type hint;
file "named.root";
};
zone "0.0.127.IN-ADDR.ARPA" {
type master;
file "db.127.0.0";
};
zone "shopgz.com" {
type master;
file "db.shopgz.com";
};
zone "113.145.61.in-addr.arpa" {
type master;
file "db.61.145.113";
};
# Use with the following in named.conf, adjusting the allow list as needed:
key "rndc-key" {
algorithm hmac-md5;
secret "********";
};
controls {
inet 127.0.0.1 port 953
allow { 127.0.0.1; } keys { "rndc-key"; };
};
# End of named.conf
(3)生成各域解析服务的数据配置文件(即生成zone文件)。这些文件按要求都要放在/etc/namedb下面,因为在named.conf中定义了directory。
(3.1)取named.root(这是DNS服务的根域服务器,一般这个文件是不能改的)
#cd /etc/namedb
#wget ftp://ftp.internic.org/domain/named.root
(3.2)手工建立db.127.0.0文件:
vi db.127.0.0
$TTL 3h
0.0.127.in-addr.arpa. IN SOA ns.shopgz.com. dns.shopgz.com. (
2009053001;
3h;
1h;
1w;
1h);
0.0.127.in-addr.arpa. IN NS ns.shopgz.com.
1.0.0.127.in-addr.arpa. IN PTR localhost.
(3.3)手工建立db.shopgz.com(shopgz.com 这里仅做示例,你可以看样你需要的任何域名)
vi db.shopgz.com
$TTL 3h
shopgz.com. IN SOA ns.shopgz.com. dns.shopgz.com. (
2009053001;
3h;
1h;
1w;
1h);
;name server
;
domain.cn. IN NS ns.shopgz.com.
;
;address
;
localhost.shopgz.com. IN A 127.0.0.1
ns.shopgz.com. IN A 61.145.113.1
www.shopgz.com. IN A 61.145.113.2
bbs.shopgz.com IN A 61.145.113.3
(3.4)手工建立db.61.145.113(域名反解,可以不用做,这里仅做示例)
vi db.61.145.113
$TTL 3h
113.145.61.in-addr.arpa. IN SOA ns.shopgz.com. dns.shopgz.com. (
2009053001;
3h;
1h;
1w;
1h);
113.145.61.in-addr.arpa. IN NS ns.shopgz.com.
1.113.145.61.in-addr.arpa. IN PTR ns.shopgz.com.
2.113.145.61.in-addr.arpa. IN PTR www.shopgz.com.
3.113.145.61.in-addr.arpa. IN PTR bbs.shopgz.com.
4、配置最后的检查与确
相关热词搜索:dns
评论排行
- ·Windows(Win7)下用Xming...(92)
- ·使用jmx client监控activemq(20)
- ·Hive查询OOM分析(14)
- ·复杂网络架构导致的诡异...(8)
- ·使用 OpenStack 实现云...(7)
- ·影响Java EE性能的十大问题(6)
- ·云计算平台管理的三大利...(6)
- ·Mysql数据库复制延时分析(5)
- ·OpenStack Nova开发与测...(4)
- ·LTPP一键安装包1.2 发布(4)
- ·Linux下系统或服务排障的...(4)
- ·PHP发布5.4.4 和 5.3.1...(4)
- ·RSYSLOG搭建集中日志管理服务(4)
- ·转换程序源码的编码格式[...(3)
- ·Linux 的木马程式 Wirenet 出现(3)
- ·Nginx 发布1.2.1稳定版...(3)
- ·zend framework文件读取漏洞分析(3)
- ·Percona Playback 0.3 development release(3)
- ·运维业务与CMDB集成关系一例(3)
- ·应该知道的Linux技巧(3)