利用dnsmasq搭建内网解析服务

一. 准备工做
系统版本 Hostname IP 备注
CentOS7.9 DNS 192.168.3.7 地址解析
CentOS7.9 test 192.168.3.8 测试解析端
CentOS7.9 ERP 192.168.3.9 ERP服务器
关闭防火墙
systemctl status firewalld
systemctl stop firewalld
systemctl disable firewalld
关闭SELINUX
vim /etc/selinux/config
SELINUX=disabled
修改hostname,方便识别
192.168.3.7
hostnamectl set-hostname DNS
192.168.3.8
hostnamectl set-hostname test
192.168.3.9
hostnamectl set-hostname DFW3RF93
二.在服务器上安装dnsmasq
yum install -y dnsmasq*
修改dnsmasq的配置
cp -a /etc/dnsmasq.conf dnsmasq.conf.bak
vim /etc/dnsmasq.conf
#自定义配置文件,让dnsmasq启动的时候读取自定义的配置
#定义dnsmasq从哪里获取上游DNS服务器的地址, 默认从/etc/resolv.conf获取
resolv-file=/dnsmasq/dnsmasq.d/resolv.dnsmasq.conf
no-poll
#表示严格按照resolv-file文件中的顺序从上到下进行DNS解析
strict-order
#不加载本地hosts
no-hosts
#读取自定义hosts
addn-hosts=/dnsmasq/dnsmasq.d/dnsmasq.hosts
#dnsmasq日志存放位置
log-queries
log-facility=/dnsmasq/dnsmasq.d/dnsmasq.log
#DNS缓存设置
cache-size=1500
#本机使用只加环回IP,全网使用须要在环回后加本机IP
listen-address=192.168.3.7,127.0.0.1
建立目录和文件
mkdir -p /dnsmasq/dnsmasq.d
touch /dnsmasq/dnsmasq.d/{resolv.dnsmasq.conf,dnsmasq.hosts,dnsmasq.log}
编辑resolv.dnsmasq.conf
vim /dnsmasq/dnsmasq.d/resolv.dnsmasq.conf
#添加上有DNS(公网DNS)
nameserver 114.114.114.114
nameserver 223.5.5.5
nameserver 223.6.6.6
编辑dnsmasq.hosts(经过hosts解析内网服务器)
vim /dnsmasq/dnsmasq.d/dnsmasq.hosts
192.168.3.9 test
三.调试命令
systemctl status dnsmasq.service
#查看启动状态
systemctl start dnsmasq.service
#启动dns服务
systemctl restart dnsmasq.service
#重启dns服务
systemctl enable dnsmasq.service
#开机启动

注意:配置文件从新编辑过,须要重启dns服务器linux

四.测试DNS解析是否成功
利用nslookup测试(解析百度)
[root@test ~]# nslookup
> www.baidu.com
Server:         192.168.3.7
Address:        192.168.3.7#53

Non-authoritative answer:
www.baidu.com   canonical name = www.a.shifen.com.
Name:   www.a.shifen.com
Address: 36.152.44.96
Name:   www.a.shifen.com
Address: 36.152.44.95
利用nslookup测试(DNS服务器hosts解析内网服务器)
[root@test ~]# nslookup 192.168.3.9
9.3.168.192.in-addr.arpa        name = DFW3RF93.
#
[root@test ~]# nslookup DFW3RF93
Server:         192.168.3.7
Address:        192.168.3.7#53

Name:   DFW3RF93
Address: 192.168.3.9

经过测试,能够看到DNS能成功解析,服务器工做正常。shell

相关文章
相关标签/搜索