用RHEL5默认安装了DNS服务,当使用service named start时发现缺少named.conf。从网上查了很多资料,结果还是没弄明白到底怎么写。(最痛恨那些网上半瓶子咣当的人了,写得文章是让你似懂非懂来回抄袭,误人子弟不说,浪费别人时间,现把自己配置的过程写出来,供大家参考)
RHEL5确实是没有named.conf,需要我们手动填写。我的机器IP是192.168.10.113,hostname是test.com。
准备将192.168.10.113 和 mail.test.com/www.test.com做解析。
在RHEL5里named.conf需要放到/var/named/chroot/etc目录下,于是vi named.conf 形成以下的文档:
----------------------------------------named.conf-------------------------------------
options
{
directory "/var/named";
};
zone "."
{
type hint;
file "named.ca";
};
{
directory "/var/named";
};
zone "."
{
type hint;
file "named.ca";
};
--------------------------------------------------------------------------------------------
options 是用来说明全局属性的,其中设置了directory,指定服务器的工作目录
增加一个zone "."指向一个根域的分析文件named.ca
要产生一个named.ca文件可以先配置一个可用的DNS
echo "nameserver xxx.xxx.xxx.xxx" > /etc/resolv.conf
然后利用指令创建named.ca
dig -t NS . >/var/named/chroot/var/named/named.ca
启动域名服务
service named start
监视日志/var/log/messages
然后在启动成功后,将机器的DNS更换,测试一下named.conf文件是否正确
echo "nameserver 127.0.0.1" > /etc/resolv.conf
然后host以下163.com看看是否可以解析
host
www.163.com
完成之后就可以配置我们的域了,在named.conf里边增加相应的正向解析和反向解析,修改成下边的样子:
----------------------------------named.conf---------------------------
options
{
directory "/var/named";
};
zone "."
{
type hint;
file "named.ca";
};
zone "test.com"
{
type master;
file "test.com.zone";
};
zone "10.168.192.in-addr.arpa"
{
type master;
file "192.168.10.rev";
};
{
directory "/var/named";
};
zone "."
{
type hint;
file "named.ca";
};
zone "test.com"
{
type master;
file "test.com.zone";
};
zone "10.168.192.in-addr.arpa"
{
type master;
file "192.168.10.rev";
};
------------------------------------------------------------------------
增加了正反向之后,就要添加相应的解析文件/var/named/chroot/var/named/test.com.zone和/var/named/chroot/var/named/192.168.10.rev
添加内容如下
--------------------------------test.com.zone----------------------------
@ IN SOA test.com. root (
20060801
1H
15M
1W
1D)
IN NS ns
IN MX 10 mail
ns IN A 192.168.10.113
www IN A 192.168.10.113
mail IN A 192.168.10.113
20060801
1H
15M
1W
1D)
IN NS ns
IN MX 10 mail
ns IN A 192.168.10.113
www IN A 192.168.10.113
mail IN A 192.168.10.113
----------------------------------------------------------------
注意到格式了么,一定要用Tab对齐!
---------------------------------------192.168.10.rev------------
@ IN SOA test.com. root (
20060801
1H
15M
1W
1D)
IN NS ns.test.com.
113 IN PTR ns.test.com.
113 IN PTR www.test.com.
113 IN PTR mail.test.com.
20060801
1H
15M
1W
1D)
IN NS ns.test.com.
113 IN PTR ns.test.com.
113 IN PTR www.test.com.
113 IN PTR mail.test.com.
---------------------------------------------------------------------
然后service named restart
就可以解析访问了:)