您的位置:首页 > 理论基础 > 计算机网络

初学linux网络服务之DNS服务实验

2014-06-17 22:12 771 查看
实验拓扑:
DNSSlave
-----DNSMaster(vmnet1)----------(vmnet1)
Win7Client
实验一:搭建主DNS服务器
tarena.com
www.tarena.com 192.168.10.253
bbs.tarena.com 192.168.10.100
blog是bbs别名
1、安装软件包
[root@localhost~]# rpm -q bind bind-chroot caching-nameserver //查询软件包是否安装
packagebind is not installed
packagebind-chroot is not installed
packagecaching-nameserver is not installed
[root@localhost~]# yum -y install bind bind-chroot caching- nameserver //yum库安装软件包
2、修改主配置文件
[root@localhost~]# cd /var/named/chroot/etc/ //切换到主配置文件所在目录
[root@localhostetc]# cp -p named.caching-nameserver.conf named.conf //复制配置文件并改名
[root@localhostetc]# vim named.conf //编辑主配置文件
...
15 listen-on port 53 { 192.168.10.253; }; //设置监听端口,IP
16 # listen-on-v6 port 53 { ::1; }; //注释掉监听IPV6
...
27 allow-query { any; }; //允许客户机查询
28 allow-query-cache { any; }; //允许客户机查询缓存
...
37 match-clients { any; };
38 match-destinations { any; };
[root@localhostetc]# vim named.rfc1912.zones //编辑配置文件
...
51 zone "tarena.com" IN { //声明正向区域
52 type master; //类型 master
53 file "tarena.com.zone"; //库文件存放位置
54 };
55
56 zone "10.168.192.in-addr.arpa" IN{ //声明反向作用域
57 type master; //指定类型
58 file "tarena.com.arpa"; //库文件位置
59 };
[root@localhostetc]# named-checkconf named.conf //检查语法,无输出说明正确

3、修改数据库文件
[root@localhostetc]# cd /var/named/chroot/var/named/ //切换到库文件存放目录
[root@localhostnamed]# cp -p named.local tarena.com.zone //复制并改名库文件
[root@localhostnamed]# cp -p named.local tarena.com.arpa
[root@localhostnamed]# vim tarena.com.zone //编辑库文件
$TTL 86400
@ IN SOA localhost.root.localhost. (
2014061701 ; Serial //指定序列号
28800 ; Refresh //刷新时间
14400 ; Retry //重试间隔
3600000 ; Expire //失效时间
86400) ; Minimum //无效记录生存周期
IN NS dns01.tarena.com. //域名服务器
dns01 IN A 192.168.10.253 //解析条目
www IN A 192.168.10.253
bbs IN A 192.168.10.100
blog IN CNAME bbs //为bbs设置别名 blog
[root@localhostnamed]# cat tarena.com.arpa //编辑、查看反向解析库文件
$TTL 86400
@ IN SOA localhost.root.localhost. (
2014061701; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400) ; Minimum
IN NS dns01.tarena.com. //域名服务器
253 IN PTR dns01.tarena.com. //解析条目
253 IN PTR www.tarena.com.
100 IN PTR bbs.tarena.com.
100 IN PTR blog.tarena.com.
[root@localhostnamed]# named-checkzone tarena.com tarena.com.zone 检查语法
zonetarena.com/IN: loaded serial 2014061701
OK
[root@localhostnamed]# named-checkzone tarena.com tarena.com.arpa
zonetarena.com/IN: loaded serial 2014061701
OK
4、启动服务
[root@localhostnamed]# service named restart
[root@localhostnamed]# chkconfig named on
5、测试
取消之前hosts文件定义(C:\Windows\System32\drivers\etc)
把DNS指向服务器
win7客户运行—cmd –回车—在命令提示符nslookup 输入网址查看解析结果

实验二:DNS高级应用
实现DNS负载均衡,当用户访问www.tarena.com的时候,2/3用户访

问10.253,1/3用户访问10.100
确保用户访问tarena.com的时候仍然可以访问www.tarena.com 的网


实现用户在访问的时候只要域名正确就可以访问www.tarena.com的

网站

[root@localhost~]# cd /var/named/chroot/var/named/ //切换到数据文件目录
[root@localhostnamed]# vim tarena.com.zone //编辑库文件
...
www IN A 192.168.10.253
www IN A 192.168.10.253
www IN A 192.168.10.100
tarena.com. IN A 192.168.10.253 //添加tarena.com.解析条目
$GENERATE20-50 station$ IN A 192.168.10.$ // 自动匹配主机头函数
* IN A 192.168.10.253 //解析所有主机头条目

客户机测试
在win7浏览器上输入tarena.com可正常访问网页,在win7上输入123456.tarena.com也可以正常访问网页
在linux客户机上 ping www.tarena.com多次会发现每次IP不一样

实验三:搭建从DNS服务器
给上面的主DNS搭建一个辅助DNS
1、安装软件包
[root@localhost~]# rpm -q bind bind-chroot caching-nameserver
packagebind is not installed
packagebind-chroot is not installed
packagecaching-nameserver is not installed
[root@localhost~]# yum -y install bind bind-chroot caching- nameserver
2、修改从DNS的主配置文件
[root@localhost~]# cd /var/named/chroot/etc/ //切换到主配置文件目录
[root@localhostetc]# cp -p named.caching-nameserver.conf named.conf
[root@localhostetc]# vim named.conf //编辑主配置文件
...
15 listen-on port 53 { 192.168.10.100; };
...
27 allow-query { any; };
28 allow-query-cache { any; };
...
37 match-clients { any; };
38 match-destinations { any; };
[root@ser2etc]# vim named.rfc1912.zones
...
51 zone "tarena.com" IN { //指定正向区域
52 type slave; //指定类型slave
53 file "slaves/tarena.com.zone"; //数据文件位置
54 masters { 192.168.10.253; }; //主DNS服务器地址
55 };
56
57 zone "10.168.192.in-addr.arpa" IN{ //指定反向区域
58 type slave;
59 file "slaves/tarena.com.arpa";
60 masters { 192.168.10.253; };
61 };
[root@ser2etc]# named-checkconf named.conf //检查语法,无输出说明正确
3、修改主DNS服务器的主配置文件,添加授权信息
[root@localhost~]# cd /var/named/chroot/etc/ //进入主配置文件目录
[root@localhostetc]# vim named.conf //编辑主配置文件
...
21 allow-transfer { 192.168.10.100; }; //在21行添加内容
...
[root@localhostetc]# cd /var/named/chroot/var/named/
[root@localhostnamed]# vim tarena.com.zone //查看编辑数据文件
$TTL 86400
@ IN SOA tarena.com.root.tarena.com. (
2014041802 ; Serial //序列号

加1
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400) ; Minimum
IN NS dns01.tarena.com.
IN NS dns02.tarena.com. //添加从DNS服务器
IN A 192.168.10.253
dns01 IN A 192.168.10.253
dns02 IN A 192.168.10.100 //为从DNS正向解析
www IN A 192.168.10.253
www IN A 192.168.10.253
www IN A 192.168.10.100
bbs IN A 192.168.10.100
blog IN CNAME bbs
$GENERATE20-50 station$ IN A 192.168.10.$
* IN A 192.168.10.101
[root@localhostnamed]# cat tarena.com.arpa //编辑反向数据文件
$TTL 86400
@ IN SOA tarena.com. root.tarena.com. (
2014041802 ; Serial //序

列号加1
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400) ; Minimum
IN NS dns01.tarena.com.
IN NS dns02.tarena.com. //添加从DNS服务


253 IN PTR dns01.tarena.com.
100 IN PTR dns02.tarena.com. //为从DNS反向解析
253 IN PTR www.tarena.com.
100 IN PTR bbs.tarena.com.
[root@localhostetc]# service named restart
4、启动从DNS服务器并验证
[root@localhostetc]# service named restart //重启服务
[root@localhostetc]# chkconfig named on //设置开机自动启动
[root@localhostetc]# ls /var/named/chroot/var/named/slaves/ //查看数据文件目录下是否出现目录文件,出现说明设置成功
tarena.com.zonetarena.com.arpa
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: