Linux 之 搭建本身的DNS服務器

使用DNSMasq搭建本身的DNS服務器

說明:目前已經部署好內網DNS服務器,能夠直接使用前端

做用

  • 將測試包的某個域名直接解析到本地,方便調試
  • 加入本身想要的域名

使用:

  • 通用:應該都在網絡相關設置裏面, 手動配置DNS爲:10.100.2.230
  • 須要加自定義域名指向,請在10.100.2.230(前端測試服務器)上添加規則vim

    > vim /etc/dnsmasq.d/address.conf
  • 上游DNS沒法解析,設置上游DNS服務器

    > vim /etc/resolv.dnsmasq.conf
  • 設置完成,重啓dnsmasq生效網絡

    > systemctl restart dnsmasq

其它

Mac自建DNS服務

> brew install dnsmasq

將以下配置追加到/usr/local/etc/dnsmasq.conf測試

resolv-file=/usr/local/etc/resolv.dnsmasq.conf
strict-order
no-hosts
cache-size=32768
listen-address=127.0.0.1,Your IP # 後面加上你本身內網的IP

將上游DNS配置追加到/usr/local/etc/resolv.dnsmasq.conf調試

nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 42.120.21.30
nameserver 168.95.1.1

將須要解析的域名規則追加到/usr/local/etc/dnsmasq.confrest

address=/mock.yyfe.com/10.100.2.230
address=/mock2.yyfe.com/10.100.2.230

啓動dnsmasq(須要root權限)code

sudo brew services start dnsmasq

CentOS7 自建DNS服務

> yum install -y dnsmasq

將以下配置追加到/etc/dnsmasq.confserver

resolv-file=/usr/local/etc/resolv.dnsmasq.conf
strict-order
no-hosts
cache-size=32768
listen-address=127.0.0.1,Your IP # 後面加上你本身內網的IP

將上游DNS配置追加到/etc/resolv.dnsmasq.confdns

nameserver 10.100.2.16 # 公司內網上游DNS
nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 42.120.21.30
nameserver 168.95.1.1

將須要解析的域名規則追加到/etc/dnsmasq.d/address.conf

address=/mock.yyfe.com/10.100.2.230
address=/mock2.yyfe.com/10.100.2.230

啓動dnsmasq

systemctl start dnsmasq
相關文章
相關標籤/搜索