MAC 下安裝dnsmasq來搭建dns服務器

1.安裝dnsmasqnginx

brew install dnsmasqjson

2.複製配置文件:api

sudo cp /usr/local/opt/dnsmasq/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf緩存

3.而後修改剛剛複製過來的配置文件:/usr/local/etc/dnsmasq.confapp

subl  /usr/local/etc/dnsmasq.conf #打開配置文件dom

修改處:resolv-file=/usr/local/etc/resolv.dnsmasq.conf測試

            addn-hosts=/etc/dnsmasq.hosts
4.建立/usr/local/etc/resolv.dnsmasq.conf
domain SRTwifi
nameserver 202.96.134.133
nameserver 202.96.128.68
nameserver 114.114.114.114
nameserver 8.8.8.8
nameserver 172.20.135.1lua

5.在/etc/dnsmasq.hosts路徑下添加你所須要解析的hosts域名和ip便可spa

6.在/etc/resolv.conf文件下也添加以下內容:.net

domain SRTwifi
nameserver 202.96.134.133
nameserver 202.96.128.68
nameserver 114.114.114.114
nameserver 8.8.8.8
nameserver 172.20.135.1

7.啓動dnsmasq服務:sudo brew services start dnsmasq

清dns緩存:sudo killall -HUP mDNSResponder

8.測試dnsmasq服務是否正常

dig @127.0.0.1 baidu.com 或nslookup baidu.com 127.0.0.1 #強制指定路徑到這裏去解析(/usr/local/etc/resolv.dnsmasq.conf)

dig baidu.com 或nslookup 127.0.0.1 #表示默認路徑下解析(/etc/resolv.conf)

 

9.應用:

若是用到openresty須要resolv一些域名的話,只需在nginx.conf文件裏的server裏面的location裏面添加resolver 127.0.0.1;便可;

location /test{
    resolver 127.0.0.1;
    default_type 'application/json;charset=utf-8';
    content_by_lua_file /Users/xx/workspace/lua.api.kafka/app/producer.lua;
}
相關文章
相關標籤/搜索