下面创建一个完整的dns配置
1.创建区域文件,/etc/named.rfc1912.zones
尾巴追加
zone "cnpc.com" { #域
type master; #主dns
file "cnpc.com.zone"; #/var/named/dynamic 数据库文件
};
2.创建数据库文件vim /var/named/cnpc.com.zone
数据库文件精简写法
$TTL 1D
@ IN SOA nds1.cnpc.com. dnsadmin.john.com. (
20211127 ; serial
10M ; refresh
3M ; retry
1D ; expire
3D ) ; minimum
NS dns1
NS dns2
A 127.0.0.1
dns1 A 10.0.0.10
dns2 A 10.0.0.10
websrv A 10.0.0.10
ftpsrv A 1.1.1.1
数据库文件完整写法
cnpc.com. 1D IN SOA nds1.cnpc.com. dnsadmin.john.com. (
20211127 ; serial
10M ; refresh
3M ; retry
1D ; expire
3D ) ; minimum
cnpc.com 1D IN NS dns1
dns1.cnpc.com A 10.0.0.10
dns2.cnpc.com A 10.0.0.10
websrv A 10.0.0.10
ftpsrv A 1.1.1.1
- 精简和完整写法对比
4.配置文件编写完语法检查
/etc/named.conf配置文件语法检查
named-checkconf
数据库文件语法检查
[root@centos7 ~]#named-checkzone "cnpc.com" /var/named/cnpc.com.zone
zone cnpc.com/IN: loaded serial 20211127
OK
6.解析检测
[root@centos7 ~]#dig websrv.cnpc.com @10.0.0.10
; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.7 <<>> websrv.cnpc.com @10.0.0.10
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 53342
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 3 ## aa表示权威结果,权威就是本服务直接返回结果,不是经过向别人查询获得结果
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION: ##问把websrv.cnpc.com解析成ip
;websrv.cnpc.com. IN A
;; ANSWER SECTION: ##回答 websrv.cnpc.com.的IP是10.0.0.10
websrv.cnpc.com. 86400 IN A 10.0.0.10
;; AUTHORITY SECTION:
cnpc.com. 86400 IN NS dns1.cnpc.com.
cnpc.com. 86400 IN NS dns2.cnpc.com.
;; ADDITIONAL SECTION:
dns1.cnpc.com. 86400 IN A 10.0.0.10
dns2.cnpc.com. 86400 IN A 10.0.0.10
;; Query time: 0 msec
;; SERVER: 10.0.0.10#53(10.0.0.10)
;; WHEN: Sun Nov 28 05:00:25 CST 2021
;; MSG SIZE rcvd: 130
7.CNAME别名记录
www CNAME websrv
点击查看代码
[root@centos7 ~]#dig www.cnpc.com @10.0.0.10
; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.7 <<>> www.cnpc.com @10.0.0.10
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 51577
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 2, ADDITIONAL: 3
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.cnpc.com. IN A
;; ANSWER SECTION:
##www.cnpc.com. 86400 IN CNAME websrv.cnpc.com.
##websrv.cnpc.com. 86400 IN A 10.0.0.10
;; AUTHORITY SECTION:
cnpc.com. 86400 IN NS dns2.cnpc.com.
cnpc.com. 86400 IN NS dns1.cnpc.com.
;; ADDITIONAL SECTION:
dns1.cnpc.com. 86400 IN A 10.0.0.10
dns2.cnpc.com. 86400 IN A 10.0.0.10
;; Query time: 0 msec
;; SERVER: 10.0.0.10#53(10.0.0.10)
;; WHEN: Sun Nov 28 05:48:27 CST 2021
;; MSG SIZE rcvd: 148
8.其他记录
$GENERATE 1-100 server$ A 10.0.0.$ #访问server1.cnpc.com 由10.0.0.1解析 访问 server2.cnpc.com 由10.0.0.2.......
* A 10.0.0.10 #访问不存在的 比如 aaa.cncp.com 转发到10.0.0.10,防止用户输入网址错误