首页 > 代码库 > DNS---域名解析实验

DNS---域名解析实验

实验:
正向解析
1.[root@localhost etc]# vim /var/named/chroot/etc/named.conf
options {
listen-on port 53 {
172.17.0.142; }; -----修改
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
allow-query { any; };
forwarders {8.8.8.8;}; ------转发到指定的dns服务器
recursion yes;
# dnssec-enable yes;
# dnssec-validation yes;
#dnssec-lookaside auto;
2.[root@localhost etc]# vim /var/named/chroot/etc/named.rfc1912.zones
zone "zdj.com" IN { -------添加
type master;
file "zdj.com";
};
3.[root@localhost named]# pwd
/var/named/chroot/var/named
[root@localhost named]# cp named.localhost zdj.com -p
[root@localhost named]# vim zdj.com
$TTL 1D
@ IN SOA
dns.zdj.com. root.zdj.com.(
         0 ; serial ----更新序列号
        1D ; refresh ----刷新时间
        1H ; retry ----重试时间
        1W ; expire ----失效时间
        3H ) ; minimum ----地址解析记录的最小缓存时间
@ NS dns.zdj.com.
@ MX 6 mail.zdj.com
dns A 172.17.0.142
www A 172.17.0.88
ftp A 172.17.0.123
mail A 172.17.0.145
4.[root@localhost named]# service named restart
5.[root@localhost named]# nslookup www.zdj.com -----测试
Server: 172.17.0.142
Address: 172.17.0.142#53
Name: www.zdj.com
Address: 172.17.0.88

-------测试之前要将dns指向本机ip-------

[root@localhost named]# vim /etc/resolv.conf
nameserver  172.17.0.142

反向解析----两个地方不一样
[root@localhost etc]# vim /var/named/chroot/etc/named.rfc1912.zones
zone "0.17.172.in-addr.arpa" IN { ----添加网段
type master;
file "172.17.0.zone";
};

[root@localhost named]# vim 172.17.0.zone
$TTL 1D
@ IN SOA
dns.zdj.com. root.zdj.com.(
        0 ; serial
       1D ; refresh
       1H ; retry
       1W ; expire
       3H ) ; minimum
@ NS dns.zdj.com.
142 PTR dns.zdj.com.
123 PTR ftp.zdj.com.

DNS排错办法:1.看日志 tail -f /var/log/messages
2.检查文件有没有错
[root@localhost etc]# named-checkconf -t /var/named/chroot/
/etc/named.rfc1912.zones:27: missing ‘;‘ before ‘file‘
[root@localhost named]# named-checkzone feng.com feng.com.zone
dns_rdata_fromtext: feng.com.zone:15: near ‘mail2.feng.com.‘: not a valid number
feng.com.zone:19: unknown RR type ‘CNAMEabc‘
zone feng.com/IN: loading from master file feng.com.zone failed: not a valid number
zone feng.com/IN: not loaded due to errors.
[root@localhost named]# named-checkzone feng.com feng.com.zone
zone feng.com/IN: loaded serial 0
OK

DNS---域名解析实验