Linux下DNS服务器配置
目的:通过在Linux真机上配置DNS服务器,并用本机查询域名,同时在虚拟机中配置从DNS指向真机。
步骤:
1.准备工作
服务器配置需要的软件包如下:
bind
bind-utils
bind-chroot
本机IP配置:192.168.1.116
2.配置named.conf文件
安装了bind-chroot后,dns的主目录就变成了/var/named/chroot下
其中etc下包含named.conf配置文件,而var/named下则包含数据文件
vim named.conf (主配置--简单化)
option{
directory /var/named;
};
zone "example.com" {
type master;
file "example.com.zone";
};
zone "1.168.192.in-addr.arpa" {
type master;
file "1.168.192.arpa";
};
在这里可以实现复杂的访问控制,配置参数远不止如上所述
3.配置区块文件
根据named.conf中描述的zone,在var/named下创建区块文件
a.example.com.zone
$ttl 36000
example.com. IN SOA dns.example.com.admin.example.com.(
2005090504
10800
3600
604800
36000)
example.com. IN NS dns.example.com.
dns IN A 192.168.1.116
www.example.com IN A 192.168.1.9
mail0 IN A 192.168.1.116
mail1 IN A 192.168.1.178
mail2 IN A 192.168.1.179
mail3 IN A 192.168.1.180
rhel4 IN CNAME dns
bbs IN CNAME www
samba IN CNAME www
example.com. IN MX 8 dns.example.com.
example.com. IN MX 9 mail0.example.com.
example.com. IN MX 10 mail1.example.com.
example.com. IN MX 11 mail2.example.com.
example.com. IN MX 12 mail3.example.com.
ftp IN A 192.168.1.11
ftp IN A 192.168.1.12
ftp IN A 192.168.1.13
*.example.com. IN A 192.168.1.88
b.192.168.1.arpa
$ttl 36000
@ IN SOA dns.example.com. admin.example.com. (
2005090504
10800
3600
604800
36000 )
IN NS dns.example.com.
116 IN PTR dns.example.com.
116 IN PTR mail0.example.com.
9 IN PTR www.example.com.
178 IN PTR mail1.example.com.
179 IN PTR mail2.example.com.
180 IN PTR mail3.example.com.
11 IN PTR ftp.example.com.
12 IN PTR ftp.example.com.
13 IN PTR ftp.example.com.
测试配置文件是否正确:
service named configtest
如果测试通过,则将本机dns配置中的nameserver配置为本机:127.0.0.1
此时可以利用host来获取DNS信息了
host -t mx example.com
4.从DNS配置
基于真机已经配置了DNS服务,在虚拟机中配置从DNS,虚拟机IP为:192.168.1.20
其配置文件named.conf为:
option {
directory "/var/named";
};
zone "example.com"{
type slave;
masters {192.168.1.116;};
file "slaves/example.com.zone";
};
zone "1.168.192.in-addr.arpa"{
type slave;
masters {192.168.1.116;};
file "slaves/1.168.192.arpa";
};
此时重启DNS服务即可看到var/named/slaves下存在下载的区块数据