一. 準備工做
系統版本 | 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