Linux
上
dns
服务是一个域名解析的服务
实际安装为:
1.
查看服务器上是否安装了
dns
服务
# rpm -qa | grep bind
bind-utils-9.3.6-16.P1.el5
bind-9.3.6-16.P1.el5
# rpm -qa | grep name
caching-nameserver-9.3.6-16.P1.el5
需要有这几个
rpm
。
2.
修改配置文件(其实细心的人会发现次文件为链接文件,具体看下文错误
2
)
# cat /etc/named.caching-nameserver.conf
//
// named.caching-nameserver.conf
//
// Provided by Red Hat caching-nameserver package to configure the
// ISC BIND named(8) DNS server as a caching only nameserver
// (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
// DO NOT EDIT THIS FILE - use system-config-bind or an editor
// to create named.conf - edits to this file will be lost on
// caching-nameserver package upgrade.
//
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";
// 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";
};
把以上的
localhost
和
127.0.0.1
都改成
any
,如果不改他只能让主机来访问。
3.
在
/etc/named.rfc1912.zones
文件中添加一些东西
# cat /etc/named.rfc1912.zones
// named.rfc1912.zones:
//
// Provided by Red Hat caching-nameserver package
//
// ISC BIND named zone configuration for zones recommended by
// RFC 1912 section 4.1 : localhost TLDs and address zones
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
zone "." IN {
type hint;
file "named.ca";
};
zone "localdomain" IN {
type master;
file "localdomain.zone";
allow-update { none; };
};
zone "localhost" IN {
type master;
file "localhost.zone";
allow-update { none; };
};
zone "0.0.127.in-addr.arpa" IN {
type master;
file "named.local";
allow-update { none; };
};
zone "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN {
type master;
file "named.ip6.local";
allow-update { none; };
};
zone "255.in-addr.arpa" IN {
type master;
file "named.broadcast";
allow-update { none; };
};
zone "0.in-addr.arpa" IN {
type master;
file "named.zero";
allow-update { none; };
};
zone "baidu.com" IN {
type master;
file "baidu.zheng";
};
红色部分为添加的,意图为正向解析
4.
上面添加的
baidu.zheng
文件应该在
/var/named
下面配置,进入目录执行命令
cp named.zero baidu.zheng
,其实这个目录下面应该是链接文件,真正的文件是放在
/var/named/chroot/var/named
下面,
copy
后
baidu.zheng
为正确的链接文件就对了,否则需要到
/var/named/chroot/var/named
目录下面创建,然后修改
baidu.zheng
文件
# cat /var/named/baidu.zheng
$TTL 86400
@ IN SOA localhost. root.localhost. (
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
IN NS dns.baidu.com.
dns IN A 10.10.247.119
www IN A 10.10.247.115
后面有注释,
A
即
Address
localhost.localdomain
为我的主机名,主机名可以在
/etc/sysconfig/network
下面修改,注销后生效
5.
重启
dns
使之生效,
service named restart
。
6.
测试:
# nslookup dns.baidu.com
;; Got recursion not available from 10.10.101.3, trying next server
Server: 10.10.101.8
Address: 10.10.101.8#53
Name: dns.baidu.com
Address: 202.108.22.220
# nslookup www.baidu.com
Server: 10.10.101.3
Address: 10.10.101.3#53
Non-authoritative answer:
www.baidu.com canonical name = www.a.shifen.com.
Name: www.a.shifen.com
Address: 61.135.169.105
Name: www.a.shifen.com
Address: 61.135.169.125
这里的错误原因是本机的
dns
没有更改还是用的局域网内的
dns
,更改
dns
再测试,下文的错误
3
,有具体解释。
修改后测试
# nslookup dns.baidu.com
Server: 10.10.247.119
Address: 10.10.247.119#53
Name: dns.baidu.com
Address: 10.10.247.119
# nslookup www.baidu.com
Server: 10.10.247.119
Address: 10.10.247.119#53
Name: www.baidu.com
Address: 10.10.247.115
7.
配置反向解析在
/etc/named.rfc1912.zones
文件下面添加以下行
zone "247.10.10.in-addr.arpa" IN {
type master;
file "baidu.fan";
};
我的
ip
是
10.10.247
网段的,所以黄色部分应该那样写,
ip
倒过来写
8.
拷贝文件
cp /var/named/baidu.zheng /var/named/baidu.fan
,如果拷贝后为链接文件就是对的,否则应该拷贝到
/var/named/chroot/var/named
,然后修改
baidu.fan
文件:
# cat baidu.fan
$TTL 86400
@ IN SOA localhost. root.localhost. (
1997022700 ; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ; Minimum
IN NS baidu.com.
119 IN PTR dns.baidu.com.
115 IN PTR www.baidu.com.
红色部分为修改文件,前面的
119 115
为
ip
最后一位
9.
重启
dns
使之生效
service named restart,
然后执行命令
nslookup 10.10.247.119
,
# nslookup 10.10.247.119
Server: 10.10.247.119
Address: 10.10.247.119#53
119.247.10.10.in-addr.arpa name = dns.baidu.com.
# nslookup 10.10.247.115
Server: 10.10.247.119
Address: 10.10.247.119#53
115.247.10.10.in-addr.arpa name = www.baidu.com.
报错
1.
# service named restart
停止
named
:
[
确定
]
启动
named
:
named
配置错误:
:
zone localdomain/IN: loaded serial 42
zone localhost/IN: loaded serial 42
zone 0.0.127.in-addr.arpa/IN: loaded serial 1997022700
zone 0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa/IN: loaded serial 1997022700
zone 255.in-addr.arpa/IN: loaded serial 42
zone 0.in-addr.arpa/IN: loaded serial 42
dns_rdata_fromtext: baidu.zheng:9: near '10.10.247.119.': bad dotted quad
dns_rdata_fromtext: baidu.zheng:10: near '10.10.247.115.': bad dotted quad
zone baidu.com/IN: loading master file baidu.zheng: bad dotted quad
localhost_resolver/baidu.com/IN: bad dotted quad
[
失败
]
配置正向解析的时候有这个报错,后来反复测试发现在
baidu.zheng
文件中应该注意
:
# cat baidu.zheng
$TTL 86400
@ IN SOA localhost. root.localhost. (
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
IN NS baidu.com.
dns IN A 10.10.247.119.
www IN A 10.10.247.115.
在
ip
后面的
.
应该去掉,做事情应该认真。
报错
2.
启动失败提示找不到文件
**
,一定要认准真正的目录在哪里,我这就犯了个这个问题,其实默认应该是在
/var/named/
下面创建向上文说的
baidu.zheng
、
baidu.fan
,但是细心的人会发现
ll
看一下
# ll
总计
52
drwxr-x--- 6 root named 4096 02-14 22:28 chroot
drwxrwx--- 2 named named 4096 2011-02-23 data
lrwxrwxrwx 1 root named 45 2011-11-20 localdomain.zone -> /var/named/chroot//var/named/localdomain.zone
lrwxrwxrwx 1 root named 43 2011-11-20 localhost.zone -> /var/named/chroot//var/named/localhost.zone
lrwxrwxrwx 1 root named 44 2011-11-20 named.broadcast -> /var/named/chroot//var/named/named.broadcast
lrwxrwxrwx 1 root named 37 2011-11-20 named.ca -> /var/named/chroot//var/named/named.ca
lrwxrwxrwx 1 root named 44 2011-11-20 named.ip6.local -> /var/named/chroot//var/named/named.ip6.local
lrwxrwxrwx 1 root named 40 2011-11-20 named.local -> /var/named/chroot//var/named/named.local
lrwxrwxrwx 1 root named 39 2011-11-20 named.zero -> /var/named/chroot//var/named/named.zero
drwxrwx--- 2 named named 4096 2011-02-23 slaves
文件都是链接文件,真正的文件在
/var/named/chroot/var/named
下面,在这个目录先买年创建文件,可以正常启动,不知道为什么都是链接文件,也许是我安装了
rpm
包然后卸载又重新安装的原因,或者他就是这样这样配置的,没有详细研究,根据个人配置而定。
报错
3.
解析不了,提示:
正向解析,反向解析都不行,随便举个例子:
# nslookup 10.10.247.119
;; Got recursion not available from 10.10.101.8, trying next server
Server: 10.10.101.3
Address: 10.10.101.3#53
** server can't find 119.247.10.10.in-addr.arpa.: NXDOMAIN
看一下本机的
dns
:
cat /etc/resolv.conf
; generated by /sbin/dhclient-script
search domain
nameserver 10.10.101.3
nameserver 10.10.101.8
我本地的
dns
服务器分别为
10.10.101.3
、
10.10.101.8
,所以他是跑去解析局域网内的
dns
服务器了,这是因为本机的
dns
默认是局域网内的,把
dns
修改成本地的即
10.10.247.119
即可。
报错
4.
有时候解析不了,错误提示:
# nslookup www.baidu.com
;; connection timed out; no servers could be reached
这个的原因是文件所属问题,
# ll baidu.zheng
-rw-r----- 1 root root 477 02-14 23:48 baidu.zheng
把这里的百度所属改成
named
的
chown :named baidu.zheng
重启,问题解决