Fedora 服务器之 DNS 配置

网络中为了区别各个主机,必须为每台主机分配一个惟一的地址,这个地址即称为“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 定义预先配置到服务器中,并且信任的DNSSEC密钥
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 /mnt/cdrom/Packages/    先将光驱挂载到/mnt/cdrom
[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.i38 6
[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
error: Failed dependencies:
perl(DBI) is needed by mysql-5.0.45-4.fc8.i386
[root@localhost Packages]#
rpm -ivh perl-DBI-1.58-2.fc8.i386.rpm
warning: perl-DBI-1.58-2.fc8.i386.rpm: Header V3 DSA signature: NOKEY, key ID 4f2a6fd2
Preparing... ########################################### [100%]
1:perl-DBI ########################################### [100%]

[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.11.255
IPADDR=192.168.11.126
NETMASK=255.255.255.0
NETWORK=192.168.11.0
GATEWAY=192.168.11.254

ONBOOT=yes

四、 修改/etc/resolv.conf、/etc/hosts、/etc/host.conf
/etc/hosts :记录hostname对应的ip地址
/etc/resolv.conf :设置DNS服务器的ip地址
/etc/host.conf :指定域名解析的顺序(是从本地的hosts文件解析还是从DNS解析)
修改本机域名服务器IP地址(/etc/resolv.conf):

domain uhome.com
nameserver 192.168.11.126

修改下hosts(/etc/hosts):,不然开机时会经常有提示找不到主机名对应的网络地址
127.0.0.1 localhost.localdomain localhost
192.168.11.126 uhome.com uhome

演示文档/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 "uhome.com" IN {
type master;
file "uhome.com.zone";
allow-update { none; };
};
zone "11.168.192.in-addr.arpa" IN {
type master;
file "11.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 uhome.com.zone
[root@localhost named]# cp named.loopback 11.168.192.arpa
uhome.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
uhome.com.zone修改后的文件内容
$TTL 1D
uhome.com. IN SOA uhome.com. root.uhome.com.(
2010030101 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
uhome.com. IN NS dns.uhome.com.
dns IN A 192.168.11.126
www IN A 192.168.11.126
bbs IN A 192.168.11.126
blog IN A 192.168.11.126
mail IN A 192.168.11.126
uhome.com. IN MX 10 mail.uhome.com.
aaa.uhome.com IN CNAME www.uhome.com.
11.168.192.arpa原文件内容
$TTL 1D
@ IN SOA @ rname.invalid. (
0; serial添加修改时相应的序列号
1D; refresh是SOA信息的刷新时间间隔
1H; retry是与授权服务器联系的频率
1W; expire是从服务器保存有关区域信息,

而不更新它的时间间隔
3H ); minimum是区域中记录存活的时间
NS @
PTR localhost. 注:指针记录,执行逆向域名访问,映射IP地址到主机名
11.168.192.arpa修改后的文件内容
$TTL 1D
11.168.192.in-addr.arpa IN SOA uhome.com. root.uhome.com (
2010030101 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
11.168.192.in-addr.arpa IN NS uhome.com.
126 IN PTR dns.uhome.com.
126 IN PTR www.uhome.com.
126 IN PTR bbs.uhome.com.
126 IN PTR blog.uhome.com.
126 IN PTR mail.uhome.com.

七、 修改文件所属组:
[root@localhost named]# chgrp named uhome.com.zone
[root@localhost named]# chgrp named 11.168.192.arpa
[root@localhost ~]# /etc/rc.d/init.d/named start
启动 named: [确定]

八、 开启防火墙
[root@localhost ~]# iptables -I INPUT -p udp --dport 53 -j ACCEPT

九、 测试
[root@localhost ~]# nslookup
> localhost
Server: 192.168.11.6
Address: 192.168.11.6#53
Name: localhost
Address: 127.0.0.1
> 127.0.0.1
Server: 192.168.11.126
Address: 192.168.11.126#53
1.0.0.127.in-addr.arpa name = localhost.
> www.uhome.com 注:测试主机地址A资源记录
Server: 192.168.11.126
Address: 192.168.11.126#53
Name: www.uhome.com
Address: 192.168.11.126
> dns.uhome.com
Server: 192.168.11.126
Address: 192.168.11.126#53
Name: dns.uhome.com
Address: 192.168.11.126
> 192.168.11.126 注:测试反向解析指针PTR资源记录
Server: 192.168.11.126
Address: 192.168.11.126#53
126.11.168.192.in-addr.arpa name = www.uhome.com.
126.11.168.192.in-addr.arpa name = bbs.uhome.com.
126.11.168.192.in-addr.arpa name = blog.uhome.com.
126.11.168.192.in-addr.arpa name = dns.uhome.com.
> set type=ns 注:测试名称服务器NS资源记录
> uhome.com
Server: 192.168.11.126
Address: 192.168.11.126#53
uhome.com nameserver = dns.uhome.com.
> set type=mx 注:测试邮件交换器MX资源记录
> uhome.com
Server: 192.168.11.126
Address: 192.168.11.126#53
uhome.com mail exchanger = 10 mail.uhome.com.
> set type=soa 注:测试起始授权机构SOA资源记录
> uhome.com
Server: 192.168.11.126
Address: 192.168.11.126#53
uhome.com
origin = dns.uhome.com
mail addr = admin.uhome.com
serial = 2008041201
refresh = 86400
retry = 3600
expire = 604800
minimum = 10800
> set type=cname 注:测试别名CNAME资源记录
> aaa.uhome.com
Server: 192.168.11.126
Address: 192.168.11.126#53
aaa.uhome.com canonical name = www.uhome.com.
> exit

九、 关闭服务
[root@localhost ~]# /etc/rc.d/init.d/named stop
停止 named: [确定]


你可能感兴趣的:(fedora)