- 安装 dns 软件 bind
yum install bind
- 配置文件
- 主配置文件 /etc/named.conf
- zone 配置文件目录 /var/named/
- 修改主配置文件
vim /etc/named.conf
options{
listen-on port 53 { any; };
...
allow-query { localhost; 172.25.250.0/24; };
}
- 添加zone 区域文件,添加正向解析
vim /var/named/lab.example.com.zone
$TTL 1D
@ IN SOA servera.lab.example.com. rname.invalid. (
0 1D 1H 1W 3H )
IN NS servera
servera IN A 172.25.250.10
serverb IN A 172.25.250.11
- 添加 zone 区域文件,添加反向解析
vim /var/named/25.172.loopback.zone
$TTL 1D
@ IN SOA servera.lab.example.com. rname.invalid. (
0 1D 1H 1W 3H )
NS servera.lab.example.com.
10.250 PTR servera.example.com.
11.250 PTR serverb.example.com.
- 使用 named-checkzone 检查配置文件
named-checkzone example.com /var/named/lab.example.com.zone
named-checkzone 172.25.250.11 /var/named/25.172.loopback.zone
- 将 zone 区域关联到主配置文件,写在后面
zone "lab.example.com" IN {
type master;
file "lab.example.com.zone";
};
zone "25.172.in-addr.arpa" IN {
type master;
file "25.172.loopback.zone";
};
- 添加文件权限
[root@host ~]# chmod 640 /var/named/*.zone
[root@host ~]# chcon -t named_zone_t /var/named/*.zone
[root@host ~]# chown root:named /var/named/*.zone
- 检查配置文件是否OK
named-checkconf -z /etc/named.conf
- 重启服务并设置开机启动
systemctl enable named
systemctl restart named
- 错误时查看日志
systemctl status named
journalctl -xe
- 设置防火墙开启 DNS
firewall-cmd --permanent --add-service=dns
firewall-cmd --reload
firewall-cmd --list-all # 检查是否有 dns
- 验证DNS 是否配置成功
host servera.lab.example.com 172.25.250.10
host serverb.lab.example.com 172.25.250.10
host 172.25.250.10 172.25.250.10
host 172.25.250.11 172.25.250.10
- 在其他服务器上,执行 10 11 步
- 示例文件
# zone 示例文件
/var/named/named.locahost
/var/named/named.loopback
# 在主文件中配置 zone
/usr/share/doc/bind/sample/etc/named/rfc.1912.zones
# 查找示例文件
find /usr -name "*zones*"
|