bind区域解析
蒜香大龙虾
2024-08-07 23:24:23
Categories:
Tags:
环境
linux1作为dns服务器
linux2-5作为客户端
bind区域解析
安装
1
| yum install bind bind-utils -y
|
修改配置
配置文件有如下
1 2
| /etc/named.conf # 主配置文件 /etc/named.rfc1912.zones # 区域配置文件
|
配置监听端口为所有地址
修改named.conf
原配置:
1 2
| listen-on port 53 { 127.0.0.1; }; allow-query { localhost; };
|
修改为:
1 2
| listen-on port 53 { any; }; allow-query { any; };
|
添加区域
添加在主配置文件或区域文件
正向区域
1 2 3 4 5
| zone "skills.com" IN { type master; file "skills.zone"; allow-update { none; }; };
|
反向区域
1 2 3 4 5
| zone "20.20.172.in-addr.arpa" IN { type master; file "skills.arpa"; allow-update { none; }; };
|
添加区域文件
默认位置在/var/named
内
复制现有的文件
1 2 3
| cd /var/named/ cp -a named.localhost skills.zone cp -a named.loopback skills.arpa
|
编辑正向文件,添加数据
1 2 3 4 5
| linux1 A 172.20.20.11 linux2 A 172.20.20.12 linux3 A 172.20.20.13 linux4 A 172.20.20.14 linux5 A 172.20.20.15
|
编辑反向文件,添加数据
1 2 3 4 5
| 11 PTR linux1.skills.com. 12 PTR linux2.skills.com. 13 PTR linux3.skills.com. 14 PTR linux4.skills.com. 15 PTR linux5.skills.com.
|
启动&防火墙
启动
1
| systemctl enable --now named
|
放行端口
1 2
| firewall-cmd --add-port=53/udp firewall-cmd --add-port=53/udp --permanent
|
测试
指定dns服务器
1 2 3
| cat >> /etc/resolv.conf << EOF nameserver 172.20.20.11 EOF
|
也可以用nmcli添加(推荐)
1
| nmcli c m <你的配置名称> ipv4.dns 172.20.20.11
|
查询(首先需要安装bind-utils)
1 2
| nslookup linux1.skills.com nslookup 172.20.20.11
|
输出结果如下
1 2 3 4 5 6 7 8 9
| [root@linux2 ~]# nslookup linux1.skills.com Server: 172.20.20.11 Address: 172.20.20.11#53
Name: linux1.skills.com Address: 172.20.20.11
[root@linux2 ~]# nslookup 172.20.20.11 11.20.20.172.in-addr.arpa name = linux1.skills.com.
|