作用:由域名解析出ip地址
第一步:编辑/etc/named.rfc1912.zones文件
zone "westos.com" IN { type master; file "westos.com.zone"; allow-update { none; }; };
第二步:编辑/var/named/westos.com.zone文件
这个时候我们会发现没有这个文件
cp -p named.localhost westos.com.zone
$TTL 1D @ IN SOA dns.westos.com. root.westos.com. ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum NS dns.westos.com. dns A 172.25.254.122 www A 172.25.254.100 music A 172.25.254.78 heloo A 172.25.254.34
注意:
TTL 1D ##数据可以被客户端缓存一天 @ ##所维护的域的域名,指定zone后的“”的内容 在这个文件中如果后头没有.就会自动补全@代表的
测试:重启服务,dig www.westos.com
第一步:编辑/var/named/westos.com.zone文件
$TTL 1D @ IN SOA dns.westos.com. student.westos.com. ( 0 ; serial ##刷新时间 1D ; refresh ##过段时间继续查看文的问题 1H ; retry 1W ; expire ##过期时间 3H ) ; minimum ##在最小数据访问时间 NS dns.westos.com. dns A 172.25.254.122 www CNAME music.a music.a A 172.25.254.8 music.a A 172.25.254.9 hello A 172.25.254.8 westos.com. MX 10 172.25.254.222.
测试:
dig -t mx 域名 ##检测要维护的域
作用:由ip地址解析出域名
第一步:编辑vim /etc/named.rfc1912.zones文件
zone "254.25.172.in-addr.arpa" IN { type master; file "172.25.254.ptr"; allow-update { none; }; };
第二步:cp -p named.loopback 172.25.254.ptr,编辑vim 172.25.254.ptr 文件
$TTL 1D @ IN SOA dns.westos.com. root.westos.com. ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum NS dns.westos.com. dns A 172.25.254.122 111 PTR hello.westos.com. 222 PTR balala.westos.com.
~
测试:
[[email protected] named]# dig -x 172.25.254.111 ; <<>> DiG 9.9.4-RedHat-9.9.4-14.el7 <<>> -x 172.25.254.111 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 24812 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;111.254.25.172.in-addr.arpa. IN PTR ;; ANSWER SECTION: 111.254.25.172.in-addr.arpa. 86400 IN PTR hello.westos.com. ;; AUTHORITY SECTION: 254.25.172.in-addr.arpa. 86400 IN NS dns.westos.com. ;; ADDITIONAL SECTION: dns.westos.com. 86400 IN A 172.25.254.122 ;; Query time: 0 msec ;; SERVER: 172.25.254.122#53(172.25.254.122) ;; WHEN: Mon Nov 19 03:00:05 EST 2018 ;; MSG SIZE rcvd: 120
如何让一台DNS服务器解析不通的IP网段的ip地址的域名???
1.首先,在虚拟机desktop下更改网络,给eth0添加另一个ip,作为內网ip 1.1.1.122
在server上配置网络1.1.1.222
2.将真机的/etc/resolv.conf 配置DNS服务器为172.25.254网段的可以访问westos.com.zone中的域名解析,1.1.1网段的可以访问westos.com.inter的域名解析
将desktop的DNS服务器设置为172.25.254.122;将server的配置为1.1.1.222,DNS服务器设置为1.1.1.122
第一步:编辑/etc/named.conf文件,使不同的网段指向不同的/etc/named.rfc1912.zones/inter的指向
/* zone "." IN { type hint; file "named.ca"; }; include "/etc/named.rfc1912.zones"; */ view localnet { match-clients { 1.1.1.0/24; }; zone "." IN { type hint; file "named.ca"; }; include "/etc/named.rfc1912.inter"; }; view internet { match-clients { 172.25.254.0/24; }; zone "." IN { type hint; file "named.ca"; }; include "/etc/named.rfc1912.zones"; };
注意:要注释掉下图中的内容
第二步:在/etc/named.rfc1912.zones文件中有westos.com这个域的解析域名的文件/var/named/westos.com.zone
zone "westos.com" IN { type master; file "westos.com.zone"; allow-update { none; }; };
在/etc/named.rfc1912.inter文件中有westos.com这个域的解析域名的文件/var/named/westos.com.inter
zone "westos.com" IN { type master; file "westos.com.inter"; allow-update { none; }; };
第三步:编辑westos.com.zone和westos.com.inter文件,设置不同的域名解析
$TTL 1D @ IN SOA dns.westos.com. student.westos.com. ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum NS dns.westos.com. dns A 172.25.254.122 www CNAME music.a music.a A 172.25.254.8 music.a A 172.25.254.9 hello A 172.25.254.8 westos.com. MX 10 172.25.254.222. ~
$TTL 1D @ IN SOA dns.westos.com. student.westos.com. ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum NS dns.westos.com. dns A 1.1.1.122 www CNAME music.a music.a A 1.1.1.8 music.a A 1.1.1.9 hello A 1.1.1.8 westos.com. MX 10 1.1.1.222.
4.分别在真机和server上进行测试dig www.westos.com
在真机测试:
用server测试:
解析出来不同的结果,哈哈哈,这就成功啦!!!!