CentOS7.9 搭建DNS服务器

CentOS7 搭建DNS服务器,实现局域网域名访问,内网域名解析

dns服务		       192.168.199.170
vm-dev001.wowo.com 192.168.199.171
vm-dev002.wowo.com 192.168.199.172
vm-dev003.wowo.com 192.168.199.173

安装DNS服务器软件包bind

yum install bind

配置文件

在主配置文件中实现或主配置文件辅助配置文件中实现:/etc/named.conf或者/etc/named.rfc1912.zones

  • 格式
zone "ZONE_NAME" IN {
  type {master|slave|hint|forward};
  file "ZONE_NAME.zone";
};
  • 例子
# 下面添加etc/named.rfc1912.zones
zone "wowo.com" IN {
	type master;
	file "wowo.com.zone";
};

创建区域数据文件

1.在/var/named/目录下建立区域数据文件;

[root@vm-wowo-dev0-base named]# pwd
/var/named
[root@vm-wowo-dev0-base named]# cat wowo.com.zone
$TTL 1D
@   IN SOA  dns.wowo.com admin.wowo.com. (
                    123 ; serial
                    1D  ; refresh
                    1H  ; retry
                    1W  ; expire
                    3H )    ; minimum
@   IN  NS  dns
@   IN  MX  5   mail
dns     	IN  A   192.168.199.170
mail    	IN  A   192.168.199.170
www 		IN  A   192.168.199.170
vm-dev001	IN  A   192.168.199.171
vm-dev002       IN  A   192.168.199.172
vm-dev003       IN  A   192.168.199.173

2.修改区域文件的权限及属组

[root@vm-wowo-dev0-base named]# chown :named wowo.com.zone

3.检查配置文件和区域文件是否有语法错误

[root@vm-wowo-dev0-base named]# named-checkconf
[root@vm-wowo-dev0-base named]# named-checkzone wowo /var/named/wowo.com.zone
zone enzhi.com/IN: loaded serial 213
OK

让服务器重载配置文件和区域文件

rndc restart | reload
或者
systemctl reload  named.service

修改配置文件 vim /etc/named.conf

listen-on port 53 { 127.0.0.1; 192.168.199.170;};

下面这些都注释掉,至于为啥不知道
//      dump-file       "/var/named/data/cache_dump.db";
//      statistics-file "/var/named/data/named_stats.txt";
//      memstatistics-file "/var/named/data/named_mem_stats.txt";
//      recursing-file  "/var/named/data/named.recursing";
//      secroots-file   "/var/named/data/named.secroots";
//      allow-query     { localhost; };
//      dnssec-enable yes;
//      dnssec-validation yes;

命令

#启动DNS服务(说明:DNS服务的守护进程为named)
[root@vm-wowo-dev0-base named]# systemctl start named.service

#将DNS设为开机自启动
[root@vm-wowo-dev0-base named]# systemctl enable named.service

#查看DNS服务的状态
[root@vm-wowo-dev0-base named]# systemctl status named.service

#nslookup一下
[root@vm-wowo-dev001 ~]# nslookup -qt=ns vm-dev001.wowo.com
*** Invalid option: qt=ns
Server:		192.168.199.170
Address:	192.168.199.170#53

Name:	vm-dev001.wowo.com
Address: 192.168.199.171

测试

[root@vm-wowo-dev0-base named]# dig -t A www.wowo.com @192.168.199.170

; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.3 <<>> -t A www.wowo.com @192.168.199.170
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 9528
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
//
;www.wowo.com.			IN	A

;; ANSWER SECTION:
www.wowo.com.		86400	IN	A	192.168.199.170

;; AUTHORITY SECTION:
wowo.com.		86400	IN	NS	dns.wowo.com.

;; ADDITIONAL SECTION:
dns.wowo.com.		86400	IN	A	192.168.199.170

;; Query time: 0 msec
;; SERVER: 192.168.199.170#53(192.168.199.170)
;; WHEN: 二 1月 05 00:28:49 CST 2021
;; MSG SIZE  rcvd: 91

CentOS7.9 搭建DNS服务器_第1张图片

参考

https://www.cnblogs.com/6relation/p/6992070.html
https://blog.csdn.net/yelllowcong/article/details/78823520
https://blog.csdn.net/dyw_666666/article/details/103551865
https://www.cnblogs.com/wangenzhi/p/6308957.html

2021学习交流Q群号:939627878

你可能感兴趣的:(linux,linux,centos,dns服务器,域名,局域网)