参考网站:
搭建DNS服务的步骤比较简单,如果出现问题,最重要的就是查看日志,定位问题,祝你好运!
开启、关闭和查看DNS服务器日志如下:
# 初次为开启
rndc querylog
tail -f /var/log/message
# 再次为关闭(建议关闭,不然日志太多)
rndc querylog
简要流程日下:
1. 安装bind
sudo yum install bind bind-utils
2. 配置正向和方向DNS解析
vi /etc/named.conf
修改或添加如下行:
listen-on port 53 { any; };
allow-query { any; };
allow-transfer {172.16.0.12;};
forwarders { 114.114.114.114; 8.8.8.8; };
allow-transfer用于执向另外一台DNS服务器, 只有一台的情况下,可以不写。
添加正向解析配置:
zone "nyc3.example.com" {
type master;
file "/etc/named/zones/db.nyc3.example.com"; # zone file path
};
文件名可以任意位置,不过需要注意权限,要求为named组。
chrow root:named
添加方向解析配置
zone "128.10.in-addr.arpa" {
type master;
file "/etc/named/zones/db.10.128"; # 10.128.0.0/16 subnet
};
注意这里的IP是反者写的:10.128.0.0/16, 需要写成:128.10.in-addr.arpa
配置文件如下:
$TTL 604800
@ IN SOA ns1.nyc3.example.com. admin.nyc3.example.com. (
3 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
; name servers - NS records
IN NS ns1.nyc3.example.com.
IN NS ns2.nyc3.example.com.
; name servers - A records
ns1.nyc3.example.com. IN A 10.128.10.11
ns2.nyc3.example.com. IN A 10.128.20.12
; 10.128.0.0/16 - A records
host1.nyc3.example.com. IN A 10.128.100.101
host2.nyc3.example.com. IN A 10.128.200.102
$TTL 604800
@ IN SOA nyc3.example.com. admin.nyc3.example.com. (
3 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
; name servers
IN NS ns1.nyc3.example.com.
IN NS ns2.nyc3.example.com.
; PTR Records
11.10 IN PTR ns1.nyc3.example.com. ; 10.128.10.11
12.20 IN PTR ns2.nyc3.example.com. ; 10.128.20.12
101.100 IN PTR host1.nyc3.example.com. ; 10.128.100.101
102.200 IN PTR host2.nyc3.example.com. ; 10.128.200.102
3. 启动服务
systemctl start named.service
systemctl enable named.service
systemctl reload named.service