底层:两台linux主机
[root@cilent ~]# mount /dev/sr0 /mnt #挂载
[root@cilent ~]# yum install bind -y #下载dns服务
[root@cilent ~]# systemctl stop firewalld #关闭防火墙
[root@cilent ~]# senforce 0 #关闭selinux
[root@cilent ~]# vim /etc/named.conf #编辑主配置文件(删掉了一部分不必要的内容)
options {
listen-on port 53 { 192.168.231.131; };
directory "/var/named";
allow-query { any; };
};
zone "qq.com" IN {
type master;
file "named.qq.com";
};
[root@cilent named]# cp named.localhost named.qq.com #复制并起名一个为qq.com的配置文件
[root@cilent named]# vim /var/named/named.qq.com #编译子配置文件
$TTL 1D
@ IN SOA @ rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.qq.com.
www IN A 192.168.231.100
dns IN A 192.168.231.131
[root@cilent named]# systemctl restart named #重启服务
[root@cilent named]# systemctl status named #查看服务状态
[root@cilent named]# nslookup #测试
> server 192.168.231.131
Default server: 192.168.231.131
Address: 192.168.231.131#53
> www.qq.com
Server: 192.168.231.131
Address: 192.168.231.131#53
Name: www.qq.com
Address: 192.168.231.100
[root@cilent named]# vim /etc/named.conf #编译两条dns互联规则(小心编译规范)
options {
listen-on port 53 { 192.168.231.131; };
directory "/var/named";
allow-query { any; };
};
acl "china" { 192.168.231.131 ;};
acl "america" { 192.168.231.133 ;};
view "china"
{ match-clients { "china"; };
zone "qq.com" IN {
type master;
file "named.qq.com";
notify yes;
};
};
view "america"
{ match-clients { "america"; };
zone "qq.com" IN {
type master;
file "named.qq1.com";
notify yes;
};
};
[root@cilent named]# cd /var/named
[root@cilent named]# ls
data named.ca named.localhost slaves
dynamic named.conf named.loopback
named.baidu.com named.empty named.qq.com
[root@cilent named]# cp named.qq.com named.qq1.com #复制并起名为qq1.com的配置文件
[root@cilent named]# vim named.qq1.com #将其主机ip修改为192.168.231.50(便于区分)
[root@cilent named]# systemctl restart named #重启服务
[root@cilent named]# nslookup #测试
> server 192.168.231.131
Default server: 192.168.231.131
Address: 192.168.231.131#53
> www.qq.com
Server: 192.168.231.131
Address: 192.168.231.131#53
Name: www.qq.com
Address: 192.168.231.100
另一台主机:
[root@server ~]# nslookup #测试
> server 192.168.231.131
Default server: 192.168.231.131
Address: 192.168.231.131#53
> www.qq.com
Server: 192.168.231.131
Address: 192.168.231.131#53
Name: www.qq.com
Address: 192.168.231.50
>
实验完毕!