zone "baidu.com" { type master; file "baidu.com.zone"; };
创建文件/var/named/baidu.com.zone,内容如下:
1 2 3 4 5
$TTL 7200 baidu.com. IN SOA baidu.com. consoles.baidu.com. (222 1H 15M 1W 1D) baidu.com. IN NS dns1.baidu.com. dns1.baidu.com. IN A 192.168.1.128 www.baidu.com. IN A 2.2.2.2
baidu.com.zone可以简写如下:
1 2 3 4 5
$TTL 7200 @ IN SOA baidu.com. consoles.baidu.com. (222 1H 15M 1W 1D) baidu.com. IN NS dns1.baidu.com. dns1 IN A 192.168.1.128 www IN A 14.215.177.38
小提示:如果服务启动失败,可以使用tail -f /var/log/messages查看日志。
第一行的consoles.baidu.com.其实是管理员邮箱consoles@baidu.com.(@是DNS的保留字,表示当前域名,即baidu.com.二级域名)。配置完成后service named restart。
zone "baidu.com" { type master; file "baidu.com.zone"; }; zone "admin.com" { type master; file "admin.com.zone"; };
/var/named/admin.com.zone
1 2 3 4 5
$TTL 7200 admin.com. IN SOA admin.com. admin.gmail.com. (4012100 1H 15M 1W 1D) admin.com. IN NS dns1.admin.com. dns1.admin.com. IN A 192.168.1.128 baidu.admin.com. IN CNAME www.baidu.com.
$TTL 7200 @ IN SOA baidu.com. consoles.baidu.com. (222 1H 15M 1W 1D) baidu.com. IN NS dns1.baidu.com. dns1 IN A 192.168.1.128 www IN A 14.215.177.38 @ IN MX 10 mail mail IN A 192.168.1.165
$ dig @127.0.0.1 mail.baidu.com ; <<>> DiG 9.9.4-RedHat-9.9.4-38.el7_3 <<>> @127.0.0.1 mail.baidu.com ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 15666 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;mail.baidu.com. IN A ;; ANSWER SECTION: mail.baidu.com. 7200 IN A 192.168.1.165 ;; AUTHORITY SECTION: baidu.com. 7200 IN NS dns1.baidu.com. ;; ADDITIONAL SECTION: dns1.baidu.com. 7200 IN A 192.168.1.128
配置反向解析的域,/etc/named.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
options { directory "/var/named"; };
zone "baidu.com" { type master; file "baidu.com.zone"; }; zone "admin.com" { type master; file "admin.com.zone"; }; zone "1.168.192.in-addr.arpa" { type master; file "192.168.1.zone"; };
注意上面配置的时候使用ip倒置。
192.168.1.zone配置:
1 2 3 4 5
$TTL 3600 @ IN SOA 1.168.192.in-addr.arpa. consoles.gmail.com. (2014012200 1H 15M 1W 1D) @ IN NS dns1.baidu.com. 128 IN PTR dns1.baidu.com. 165 IN PTR mail.baidu.com.