安装
ubuntu: apt install bind9 -y
centos: yum install bind -y
配置
/etc/bind/named.conf.options
options {
directory "/var/cache/bind";
auth-nxdomain no; # conform to RFC1035
listen-on-v6 { any; };
listen-on port 53 { 192.168.199.130; };
allow-query { any; };
forwarders { 192.168.199.1; };
dnssec-enable no;
dnssec-validation no;
recursion yes;
};
192.168.199.130是本机。192.168.199.1是网关。
注意格式严格按照示例,不能省略空格。
/etc/bind/named.conf.local
zone "host.com" IN {
type master;
file "host.com.zone";
allow-update { 192.168.199.130; };
};
这样就添加了一个zone,zone的文件在/var/cache/bind(named.conf.options中配置)目录下。
/var/cache/bind/host.com.zone
$ORIGIN host.com.
$TTL 600;
@ IN SOA dns.host.com. dnsadmin.host.cm. (
20211019;
10800;
900;
60480;
86400;
)
NS dns.host.com.
$TTL 60;
dns A 192.168.199.130
www A 192.168.199.130
配置了host.com这个zone中的两台服务器,dns和www。
校验
named-checkconf --验证配置正确
named-checkzone host.com /var/cache/bind/host.com.zone --验证区域配置文件正确
重启服务
service bind9 restart
验证
dig -t A dns.host.com @192.168.199.130 +short
排错
默认,日志文件在/var/log/syslog中