DNS-学习目录
1、配置流程
用户通过 DNS 服务器 192.168.10.19 解析 www.example.com
1、添加 example.com 区域配置文件
2、添加区域数据库文件,配置NS记录,返回 DNS权威服务器地址
3、该域的 DNS权威服务器为 192.168.10.19
4、添加该域的 A 记录解析
2、新增区域-【配置文件】
2.1、增加zone
dns-master ~]# cat /etc/named.conf
...
listen-on port 53 { 192.168.10.19; };
allow-query { any; };
zone "example.com" IN {
type master;
file "example.com.zone";
};
...
2.2、检查语法是否正常
3、新增区域-【数据库文件】
3.1、添加区域数据库文件
3.1.1、example.com.zone配置
cat << CAT_END >/var/named/example.com.zone
example.com. 600 IN SOA example.com. sa.example.com. (
2023051644
10800
900
604800
86400)
;ns服务器配置
example.com. IN NS ns.example.com.
ns.example.com. IN A 192.168.10.19
;域名A记录解析,末尾需要.结尾,不然解析不出来
www.example.com. IN A 1.1.1.1
test.example.com. IN A 2.2.2.2
CAT_END
chmod 640 /var/named/example.com.zone
chown root.named /var/named/example.com.zone
3.1.2、配置解析
# example.com. 域名可以使用@表示
# 600 TTL是 Time To Live的缩写
# SOA ns.example.com. 指定ns服务器
# sa.example.com. 管理员邮箱地址解析为:sa@example.com
example.com. 600 IN SOA ns.example.com. sa.example.com. (
2023051644
10800
900
604800
86400)
;ns服务器配置
example.com. IN NS ns.example.com.
ns.example.com. IN A 192.168.10.19
;域名A记录解析
www.example.com. IN A 1.1.1.1
test.example.com. IN A 2.2.2.2
解析过程: example.com. -> ns.example.com. -> 192.168.10.19 -> www.example.com/test.example.com -> 1.1.1.1/2.2.2.2
3.2、语法检查
dns-master ]# named-checkzone example.com /var/named/example.com.zone
/var/named/example.com.zone:9: using RFC1035 TTL semantics
zone example.com/IN: loaded serial 2023051644
OK
4、重载 DNS服务器
4.1、配置rndc【首次需要配置】
# 首次需要配置
rndc-confgen -r /dev/urandom -a
chown root:named /etc/rndc.key
chmod 640 /etc/rndc.key
systemctl restart named
4.2、重新加载DNS
5、客户端测试-dig命令-解析域名
5.1、解析www.example.com的域名【打印完整信息】
]# dig test.example.com @192.168.10.19
; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.13 <<>> test.example.com @192.168.10.19
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 21893
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;test.example.com. IN A
;; ANSWER SECTION:
test.example.com. 600 IN A 2.2.2.2 # 解析出来的IP地址
;; AUTHORITY SECTION:
example.com. 600 IN NS ns.example.com. # 使用ns服务器地址
;; ADDITIONAL SECTION:
ns.example.com. 600 IN A 192.168.10.19 # 使用此IP地址解析
;; Query time: 0 msec
;; SERVER: 192.168.10.19#53(192.168.10.19)
;; WHEN: Sun May 07 18:35:54 CST 2023
;; MSG SIZE rcvd: 94
5.2、解析www.example.com的域名【只打印解析结果的IP地址】
~]# dig test.example.com @192.168.10.19 +short
2.2.2.2