这是一篇实践性的文章,如果你还不知道DNS是个什么东西和bind的一些简单知识建议还是了解一下先
首先,确认系统是否装有bind
# rpm -qa|grep bind
我用的就是redhatas4u3自带的bind:bind-9.2.4-2这个版本(如果没有bind的话 就去下载一个源码包吧,具体怎么安装就不在说了 这样的文档google一下,一大把)
如果是系统自带的bind是安装在/var/named/chroot下的(chroot如果不知道的话 也去google一下吧)
下面是具体操作:
# cd /var/named/chroot/etc/ //进入chroot环境下的etc目录
(建议在编辑配置文件之前先备份一下已有的配置文件!!!)
# vi named.conf //编辑bind的主配置文件
//
// named.conf for Red Hat caching-nameserver
//
options {
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
/*
* 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;
};
//
// a caching only nameserver config
//
controls {
inet 127.0.0.1 allow { localhost; } keys { rndckey; };
};
acl "telecom" {
众多电信的DNS,我就不cp过来了,实在是太多了!我在写这个的时候已经是1K多条记录了
....
....
};
view "telecom" {
match-clients { TELECOM; };
zone "." {
type hint;
file "named.ca";
};
zone "0.0.127.IN-ADDR.ARPA" {
type master;
file "localhost.rev";
};
zone "test.com" {
type master;
file "master/telecom/test.com";
};
};
view "any" {
match-clients { any; };
zone "." {
type hint;
file "named.ca";
};
zone "0.0.127.IN-ADDR.ARPA" {
type master;
file "localhost.rev";
};
zone "test.com" {
type master;
file "master/cnc/test.com";
};
};
include "/etc/rndc.key";
//编辑完成后保存退出
# mkdir /var/named/chroot/var/named/master/
# mkdir /var/named/chroot/var/named/master/telecom
# mkdir /var/named/chroot/var/named/master/cnc
# vi /var/named/chroot/var/named/master/telecom/test.com
$TTL 86400
@ IN SOA ns.test.com. root.ns.test.com. (
2005062301 ; serial
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
IN NS ns.test.com.
IN MX 10 mail.test.com.
www IN A 电信IP
//保存退出
# vi /var/named/chroot/var/named/master/cnc/test.com
$TTL 86400
@ IN SOA ns.test.com. root.ns.test.com. (
2005062301 ; serial
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
IN NS ns.test.com.
IN MX 10 mail.test.com.
www IN A 网通IP
//保存退出
# service named start
别忘记修改/etc/resolv.conf这个文件!
# dig @IP