DNS有很多值得学习的地方,这里我们主要介绍DNS服务器,包括介绍DNS服务器启动等方面。Fedora Core Linux计划整合成新的Fedora Project。网络中为了区别各个主机,必须为每台主机分配一个惟一的地址,这个地址即称为“IP地址”。但这些数字难以记忆,所以就采用“域名”的方式来取代这些数字了。当某台主机要与其他主机通信时,就可以利用主机名称向DNS服务器查询该主机的IP地址。
整个DNS域名系统由以下4个部分组成
1.DNS服务器域名空间
2.资源记录
3.DNS服务器
4.DNS服务器客户端
Linux下架设DNS服务器通常是使用Bind程序来实现的。Bind是Berkeley Internet Name Domain Service的简写,它是一款实现DNS服务器的开放源码软件。Bind原本是美国DARPA资助伯克里大学(Berkeley)开设的一个研究生课题,后来经过多年的变化发展,已经成为世界上使用最为广泛的DNS服务器软件,目前Internet上绝大多数的DNS服务器有都是用Bind来架设的
DNS服务器种类:
1.Master Server 主服务器
2.Slave Server 辅助服务器/从服务器
3.Caching only Server 缓存服务器
4.Forwarder Server 转发服务器
5.Stealth Server 秘密服务器
DNS BIND区域类型:
类型 描述
master 主DNS服务器区域
slave 从DNS服务器区域,由主DNS服务器区域控制
stub与从区域类似,但只保存DNS服务器的名字
forward 将任何询问请求转发给其他服务器
hint根DNSInternet服务器集
常见的BIND配置语句和选项:
语句 描述
C语言风格的BIND注释
//注释 C++语法风格的BIND注释
#注释Unix shell和Perl系统风格的BIND注释
Acl 定义IP地址匹配列表
Include 包含一个文件
Key 指明用于识别和授权的密钥信息
Logging 指名服务器日志记录的内容和日志信息的来源
Options 全局服务器的配置选项和其他语句的默认值
Control 声明ndc软件工具使用的控制通道
Server 设置某个服务器的配置参数
trusted-keys 定义预先配置到服务器中,并且信任的DNS SEC密钥
zone 定义一个区域
type 指明一个区域类型
file 指明一个区域文件
directory 指明区域文件目录
forwarders 列出主机请求将要被转发的DNS服务器
masters 列出做为从服务器使用的DNS服务器主机
allow-transfer 指明允许那台主机接受区域传送的请求
allow-query 指明允许那台主机提出询问
motify 当主区域数据允许改变和更新时,允许主服务器通知从服务器
资源记录类型:
类型 描述
A 主机地址,映射主机名字到IP
NS 本域授权名字服务器
CNAME 规范的名字,用来注释主机的别名
SOA 授权开始,在域文件中开始DNS服务器条目,为域和其他特征(像点和序号)指定名字服务器
WKS 已知的服务描述
PTR 指针记录,执行逆向域名访问,映射IP地址到主机名
RP 文本字符串,包含有关主机的接点信息
HINFO 主机信息
MINFO 电子信箱或邮件列表信息
MX 邮件交换器,传送到域邮件服务器的远程站点
TXT 文本字符串,通常是主机信息
安装
[root@localhost ~]# rpm -q bind
[root@localhost /]# cd /media/Fedora\ 8\ i386\ DVD/Packages/
[root@localhost Packages]# find . -name "bind*"
bind-9.5.0-16.a6.fc8.i386.rpm
bind-chroot-9.5.0-16.a6.fc8.i386.rpm
bind-libs-9.5.0-16.a6.fc8.i386.rpm
bind-utils-9.5.0-16.a6.fc8.i386.rpm
BIND程序的虚拟目录是/var/named/chroot/
如:/etc/named.conf其实就是 /var/named/chroot/etc/named.conf
如:/var/named/其真正的路径是/var/named/chroot/ var/named/
[root@localhost Packages]# rpm -ivh bind-libs-9.5.0-16.a6.fc8.i386.rpm
warning: bind-libs-9.5.0-16.a6.fc8.i386.rpm: Header V3 DSA signature: NOKEY, key ID 4f2a6fd2
Preparing... [100%]
package bind-libs-9.5.0-16.a6.fc8 is already installed
[root@localhost Packages]# rpm -ivh util-linux-ng-2.13-3.fc8.i386.rpm
warning: util-linux-ng-2.13-3.fc8.i386.rpm: Header V3 DSA signature: NOKEY, key ID 4f2a6fd2
Preparing... [100%]
package util-linux-ng-2.13-3.fc8 is already installed
[root@localhost Packages]# rpm -ivh bind-9.5.0-16.a6.fc8.i386.rpm
warning: bind-9.5.0-16.a6.fc8.i386.rpm: Header V3 DSA signature: NOKEY, key ID 4f2a6fd2
error: Failed dependencies:
libmysqlclient.so.15 is needed by bind-9.5.0-16.a6.fc8.i386
libmysqlclient.so.15(libmysqlclient_15) is needed by bind-9.5.0-16.a6.fc8.i386
libodbc.so.1 is needed by bind-9.5.0-16.a6.fc8.i386
libpq.so.5 is needed by bind-9.5.0-16.a6.fc8.i386
mysql is needed by bind-9.5.0-16.a6.fc8.i386
postgresql is needed by bind-9.5.0-16.a6.fc8.i386
unixODBC is needed by bind-9.5.0-16.a6.fc8.i386
[root@localhost Packages]# rpm -ivh mysql-libs-5.0.45-4.fc8.i386.rpm
warning: mysql-libs-5.0.45-4.fc8.i386.rpm: Header V3 DSA signature: NOKEY, key ID 4f2a6fd2
Preparing... [100%]
1:mysql-libs [100%]
[root@localhost Packages]# rpm -ivh bind-9.5.0-16.a6.fc8.i386.rpm
warning: bind-9.5.0-16.a6.fc8.i386.rpm: Header V3 DSA signature: NOKEY, key ID 4f2a6fd2
error: Failed dependencies:
libodbc.so.1 is needed by bind-9.5.0-16.a6.fc8.i386
libpq.so.5 is needed by bind-9.5.0-16.a6.fc8.i386
mysql is needed by bind-9.5.0-16.a6.fc8.i386
postgresql is needed by bind-9.5.0-16.a6.fc8.i386
unixODBC is needed by bind-9.5.0-16.a6.fc8.i386
[root@localhost Tuxtools]# rpm -ivh unixODBC-2.2.12-5.fc8.i386.rpm
warning: unixODBC-2.2.12-5.fc8.i386.rpm: Header V3 DSA signature: NOKEY, key ID 4f2a6fd2
Preparing... [100%]
1:unixODBC [100%]
[root@localhost Packages]# rpm -ivh bind-9.5.0-16.a6.fc8.i386.rpm
warning: bind-9.5.0-16.a6.fc8.i386.rpm: Header V3 DSA signature: NOKEY, key ID 4f2a6fd2
error: Failed dependencies:
libpq.so.5 is needed by bind-9.5.0-16.a6.fc8.i386
mysql is needed by bind-9.5.0-16.a6.fc8.i386
postgresql is needed by bind-9.5.0-16.a6.fc8.i386
[root@localhost Tuxtools]# rpm -ivh postgresql-libs-8.2.7-1.fc8.i386.rpm
warning: postgresql-libs-8.2.7-1.fc8.i386.rpm: Header V3 DSA signature: NOKEY, key ID 4f2a6fd2
Preparing... [100%]
1:postgresql-libs [100%]
[root@localhost Packages]# rpm -ivh bind-9.5.0-16.a6.fc8.i386.rpm
warning: bind-9.5.0-16.a6.fc8.i386.rpm: Header V3 DSA signature: NOKEY, key ID 4f2a6fd2
error: Failed dependencies:
mysql is needed by bind-9.5.0-16.a6.fc8.i386
postgresql is needed by bind-9.5.0-16.a6.fc8.i386
[root@localhost Tuxtools]# rpm -ivh postgresql-8.2.7-1.fc8.i386.rpm
warning: postgresql-8.2.7-1.fc8.i386.rpm: Header V3 DSA signature: NOKEY, key ID 4f2a6fd2
Preparing... [100%]
1:postgresql [100%]
[root@localhost Packages]# rpm -ivh bind-9.5.0-16.a6.fc8.i386.rpm
warning: bind-9.5.0-16.a6.fc8.i386.rpm: Header V3 DSA signature: NOKEY, key ID 4f2a6fd2
error: Failed dependencies:
mysql is needed by bind-9.5.0-16.a6.fc8.i386
[root@localhost Packages]# rpm -ivh mysql-5.0.45-4.fc8.i386.rpm
warning: mysql-5.0.45-4.fc8.i386.rpm: Header V3 DSA signature: NOKEY, key ID 4f2a6fd2
Preparing... [100%]
1:mysql [100%]
[root@localhost Packages]# rpm -ivh bind-9.5.0-16.a6.fc8.i386.rpm
warning: bind-9.5.0-16.a6.fc8.i386.rpm: Header V3 DSA signature: NOKEY, key ID 4f2a6fd2
Preparing... [100%]
1:bind [100%]
[root@localhost ~]# rpm -q bind
bind-9.5.0-16.a6.fc8
安装完毕后启动DNS服务器并测试回环
[root@localhost etc]# /etc/rc.d/init.d/named start
启动 named: [确定]
[root@localhost etc]# nslookup
> localhost
Server: 127.0.0.1
Address:127.0.0.1#53
Name: localhost
Address: 127.0.0.1
> 127.0.0.1
Server: 127.0.0.1
Address:127.0.0.1#53
1.0.0.127.in-addr.arpa name = localhost.
> exit
[root@localhost etc]# /etc/rc.d/init.d/named stop
停止 named: [确定]
修改网络配置脚本文件(/etc/sysconfig/network-scripts/ifcfg-eth0):
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
修改后
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE=eth0
BOOTPROTO=static
HWADDR=00:0C:29:65:21:05
BROADCAST=192.168.1.255
IPADDR=192.168.1.6
NETMASK=255.255.255.0
NETWORK=192.168.1.1
ONBOOT=yes
修改本机域名服务器IP地址(/etc/resolv.conf):
domain jw.com
nameserver 192.168.1.6
演示文档/usr/share/doc/bind-9.5.0/sample
[root@localhost etc]# cp named.conf named.conf.old
修改named.conf文件(/etc/named.conf):
listen-on port 53 { 127.0.0.1; };
listen-on-v6 port 53 { ::1; };
Fedora 8中,默认仅仅在回环地址127.0.0.1和::1(IPV6的回环地址)上打开53端口,如果希望在所有地址上都打开53端口,则应该修改成:
listen-on port 53 { any; };
listen-on-v6 port 53 { any; };
allow-query { localhost; };
Fedora 8中的DNS服务器默认只允许127.0.0.1这个客户端(即本机)发起查询,一般我们需要允许所有人查询,则因该修改成:
allow-query { any; };
设置主区域(/etc/named.conf):
为了配置的方便和减少出错我们从系统(127.0.0.1)回环/etc/named.rfc1912.zones文件复制到named.conf文件并修改,将以下从named.rfc1912.zones文件复制
zone "localhost" IN {
type master; 注:type和file是两个必选项,type项用于指明区域类型(master,slave,stub,forward,hint)
file "named.localhost"; 注:用于指明区域文件的名字
allow-update { none; }; 注:不允许区域复制,
zone "1.0.0.127.in-addr.arpa" IN
type master;
file "named.loopback";
allow-update { none; };
};
修改成
zone "jw.com" IN {
type master;
file "jw.com.zone";
allow-update { none; };
};
zone "1.168.192.in-addr.arpa" IN {
type master;
file "1.168.192.arpa";
allow-update { none; };
};
建立区域文件在(/var/named):
[root@localhost ~]# cd /var/named/
为了配置方便和减少出错我们复制系统(127.0.0.1)回环文件(正向区域文件/var/named/named.localhost拟向区域文件/var/named/named.loopback)
[root@localhost named]# cp named.localhost jw.com.zone
[root@localhost named]# cp named.loopback 1.168.192.arpa
jw.com.zone原文件内容
$TTL 1D
@IN SOA @ rname.invalid. ( 注:授权开始,指定名字服务器
0 ; serial添加修改时相应的序列号
1D ; refresh是SOA信息的刷新时间间隔
1H ; retry是与授权服务器联系的频率
1W ; expire是从服务器保存有关区域信息,而不更新它的时间间隔
3H ) ; minimum是区域中记录存活的时间
NS @ 注:本域授权名字服务器
A 127.0.0.1 注:主机地址,映射主机名字到IP地址
AAAA ::1
jw.com.zone修改后的文件内容
$TTL 1D
jw.com. IN SOA dns.jw.com. admin.jw.com. (
2008041201 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
jw.com. IN NS dns.jw.com.
dns.jw.com. IN A 192.168.1.6
www.jw.com. IN A 192.168.1.6
bbs.jw.com. IN A 192.168.1.6
blog.jw.com. IN A 192.168.1.6
mail.jw.com. IN A 192.168.1.6
jw.com. IN MX 10 mail.jw.com.
aaa.jw.com IN CNAME www.jw.com.
1.168.192.arpa原文件内容
$TTL 1D
@IN SOA @ rname.invalid. (
0; serial添加修改时相应的序列号
1D; refresh是SOA信息的刷新时间间隔
1H; retry是与授权服务器联系的频率
1W; expire是从服务器保存有关区域信息,而不更新它的时间间隔
3H ); minimum是区域中记录存活的时间
NS @
PTR localhost. 注:指针记录,执行逆向域名访问,映射IP地址到主机名
1.168.192.arpa修改后的文件内容
$TTL 1D
1.168.192.in-addr.arpa. IN SOA dns.jw.com. admin.jw.com. (
2008041201 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
1.168.192.in-addr.arpa. IN NS dns.jw.com.
6 IN PTR dns.jw.com.
6 IN PTR www.jw.com.
6 IN PTR bbs.jw.com.
6 IN PTR blog.jw.com.
6 IN PTR mail.jw.com.
修改文件所属组:
[root@localhost named]# chgrp named jw.com.zone
[root@localhost named]# chgrp named 1.168.192.arpa
[root@localhost ~]# /etc/rc.d/init.d/named start
启动 named: [确定]
测试
[root@localhost ~]# nslookup
> localhost
Server: 192.168.1.6
Address:192.168.1.6#53
Name: localhost
Address: 127.0.0.1
> 127.0.0.1
Server: 192.168.1.6
Address:192.168.1.6#53
1.0.0.127.in-addr.arpa name = localhost.
> www.jw.com 注:测试主机地址A资源记录
Server: 192.168.1.6
Address:192.168.1.6#53
Name: www.jw.com
Address: 192.168.1.6
> dns.jw.com
Server: 192.168.1.6
Address:192.168.1.6#53
Name: dns.jw.com
Address: 192.168.1.6
> 192.168.1.6 注:测试反向解析指针PTR资源记录
Server: 192.168.1.6
Address:192.168.1.6#53
6.1.168.192.in-addr.arpaname = www.jw.com.
6.1.168.192.in-addr.arpaname = bbs.jw.com.
6.1.168.192.in-addr.arpaname = blog.jw.com.
6.1.168.192.in-addr.arpaname = dns.jw.com.
> set type=ns 注:测试名称服务器NS资源记录
> jw.com
Server: 192.168.1.6
Address:192.168.1.6#53
jw.com nameserver = dns.jw.com.
> set type=mx 注:测试邮件交换器MX资源记录
> jw.com
Server: 192.168.1.6
Address:192.168.1.6#53
jw.com mail exchanger = 10 mail.jw.com.
> set type=soa 注:测试起始授权机构SOA资源记录
> jw.com
Server: 192.168.1.6
Address:192.168.1.6#53
jw.com
origin = dns.jw.com
mail addr = admin.jw.com
serial = 2008041201
refresh = 86400
retry = 3600
expire = 604800
minimum = 10800
> set type=cname 注:测试别名CNAME资源记录
> aaa.jw.com
Server: 192.168.1.6
Address:192.168.1.6#53
aaa.jw.com.jw.com canonical name = www.jw.com.
> exit
关闭DNS服务器服务
[root@localhost ~]# /etc/rc.d/init.d/named stop 停止 named:
【编辑推荐】