dns服務器一般是按照bind服務
dnsmasq是一款小巧且方便地用於配置DNS服務器和DHCP服務器的工具,適用於小型網絡
提供了dns解析的功能和可選擇的dhcp功能
dnsmasq可以解決小范圍的dns查詢問題,如果業務是跨機房。跨地區的話不建議使用dnsmasq作為dns解析服務器
安裝軟件
yum install dnsmasq -y
dnsmasq的主配置文件
/etc/dnsmasq.conf
#dnsmqsq內部解析所需要的ip和域名,也就是用戶所需要自定義的域名和ip的對應關系編寫、
/etc/dnsmasq.hosts #該文件需要手動創建
#dnsmasq的上游dns服務器地址
/etc/resolv.dnsmasq.conf #手動創建
修改dnsmasq.conf
vim /etc/dnsmasq.conf #打開且修改如下參數
resolv-file=/etc/resolv.dnsmasq.conf
#自定義某些域名及其子域名,都解析到一個ip地址,添加如下參數
address=/baidu.com/123.206.16.61
address=/taobao.com/123.206.16.61
定義dnsmasq的監聽地址的配置文件 ,如果你是本地的linx虛擬機,可以填寫127.0.0.1,也可以是本地的局域網ip
listen-address=本地ip
定義一個本地域名配置文件,需要自定義的一些域名解析記錄
addn-hosts=/etc/dnsmasq.hosts
記錄dns查詢的日志參數
log-queries #打開
包含目錄的語法,能夠包含某一個文件夾下所有符合定義類型的配置文件
#conf-file=/etc/dnsmasq.more.conf
conf-dir=/etc/dnsmasq.d
# Include all the files in a directory except those ending in .bak
conf-dir=/etc/dnsmasq.d,.bak
# Include all files in a directory which end in .conf
conf-dir=/etc/dnsmasq.d/,*.conf
自定義的dnsmasq服務的配置文件,參數如下
[root@localhost ~]# grep -v "^#" /etc/dnsmasq.conf | grep -v "^$"
resolv-file=/etc/resolv.dnsmqsa.conf
address=/baidu.com/123.206.16.61
listen-address=160.116.208.83
addn-hosts=/etc/dnsmasq.hosts
log-queries
conf-dir=/etc/dnsmasq.d
conf-dir=/etc/dnsmasq.d,.bak
conf-dir=/etc/dnsmasq.d/,*.conf
conf-dir=/etc/dnsmasq.d,.rpmnew,.rpmsave,.rpmorig
內部解析的地址關系
[root@localhost ~]# cat /etc/dnsmasq.hosts
160.116.208.83 sprr.com
添加上游dns服務器地址
#當dnsmasq在本地找不到解析記錄的時候,去上游查找
[root@localhost ~]# cat /etc/resolv.dnsmasq.conf
nameserver 119.29.29.29
nameserver 223.5.5.5
啟動dnsmasq服務
通過yum安裝的軟件,直接systemctl啟動
systemctl start dnsmasq
修改本地的dns客戶端配置文件,指定自定義的dnsmasq服務器地址
[root@localhost ~]# cat /etc/resolv.conf
# Generated by NetworkManager
#search domain.com
#nameserver 8.8.8.8
nameserver 160.116.208.83
測試域名解析是否成功