Dnsmasq使用上比bind要簡便得多,可以做正向、反向dns解析,支持DHCP服務。也可以做內部dns服務器用。
默認下,dnsmasq使用系統的/etc/resolv.conf,並讀取/etc/hosts文件。
1.安裝dnsmasq軟件
yum install dnsmasq
2.編輯配置文件/etc/dnsmasq.conf
cache-size=10000 #緩存條數 resolv-file=/etc/dnsmasq-resolv.conf #上一級DNS addn-hosts=/etc/dnsmasq.hosts #本地域名配置文件(不支持泛域名) log-queries log-facility=/var/log/dnsmasq.log local-ttl=600 #DHCP租約時間 conf-dir=/etc/dnsmasq.d
3.修改上游DNS配置文件/etc/dnsmasq-resolv.conf
nameserver x.x.x.x
3.1編輯本地域名配置文件/etc/dnsmasq.hosts(添加內部需要解析的地址和域名)(重新加載即可生效)
127.0.0.1 www.qq.com #IP 域名
3.2 編輯支持泛域名的配置文件/etc/dnsmasq.d/address.conf(編輯后需要重啟服務才生效)
address=/www.taobao.com/127.0.0.1 #正向解析 ptr-record=127.0.0.1.in-addr.arpa,www.taobao.com #反向解析(可選) address=/baidu.com/127.0.0.1 #泛域名解析
4.配置日志輪轉,編輯/etc/logrotate.d/dnsmasq
/var/log/dnsmasq.log { daily copytruncate missingok rotate 30 compress notifempty dateext size 200M }