知乎专栏 | 多维度架构 |
一般配置下面三处即可
# vim /etc/dnsmasq.conf resolv-file=/etc/dnsmasq.resolv.conf addn-hosts=/etc/dnsmasq.hosts conf-dir=/etc/dnsmasq.d /etc/init.d/dnsmasq restart
让dnsmasq 接管DNS解析
# vim /etc/dnsmasq.conf resolv-file=/etc/dnsmasq.resolv.conf resolv-file
sudo cp /etc/resolv.conf /etc/dnsmasq.resolv.conf cat > /etc/dnsmasq.resolv.conf <<EOF nameserver 208.67.222.222 nameserver 208.67.220.220 EOF
或者
nameserver 8.8.8.8 nameserver 4.4.4.4
/etc/resolv.conf 设置用本机做解析
echo "nameserver 127.0.0.1″ > /etc/resolv.conf or sudo vim /etc/resolv.conf nameserver 127.0.0.1
reload
/etc/init.d/dnsmasq reload or sudo killall -s SIGHUP dnsmasq
dnsmasq 默认会读取 /etc/hosts 如果你不想让它解析/etc/hosts文件,可以自己定义一个文件。
# vim /etc/dnsmasq.conf no-hosts addn-hosts=/etc/dnsmasq.hosts
echo "172.16.0.1 test.example.com" > /etc/dnsmasq.hosts
重新起动
/etc/init.d/dnsmasq restart
查看日志
cat /var/log/message Sep 15 18:17:24 J10-51-MemCache dnsmasq[13799]: read /etc/hosts - 2 addresses Sep 15 18:17:24 J10-51-MemCache dnsmasq[13799]: read /etc/dnsmasq.hosts - 40 addresses
使用nslookup测试
nslookup test.example.com 172.16.3.51
提示 | |
---|---|
注释no-hosts选项,可以实现 /etc/hosts 与 /etc/dnsmasq.hosts 共用 |
配置域名使用那些DNS解析
vim /etc/dnsmasq.d/dnsmasq.server.conf server=/google.com/8.8.8.8 server=/yahoo.com/4.4.4.4 server=/qq.com/202.96.134.133 server=/com.cn/202.96.128.68 server=/us/208.67.222.222 server=/uk/208.67.220.220
反向解析
# Add other name servers here, with domain specs if they are for # non-public domains. #server=/localnet/192.168.0.1 # Example of routing PTR queries to nameservers: this will send all # address->name queries for 192.168.3/24 to nameserver 10.1.2.3 #server=/3.168.192.in-addr.arpa/10.1.2.3
vim /etc/dnsmasq.d/dnsmasq.address.conf address=/www.mydomain.com/172.16.0.254
deny domain
address=/www.facebook.com/127.0.0.1 address=/www.google.com/127.0.0.1