参考文献

docker-dnsmasq

环境说明

  • Centos 7
  • docker-compose
  • 192.168.50.100 为DNS服务器所在
  • 192.168.50.101 为目的服务器

步骤说明

1.编辑.env文件增加登录dns web 页账号密码配置

############### Dns #################
TZ=Asia/Shanghai
HTTP_USER=root
HTTP_PASS=root

2.在Docker主机上创建文件/dnsmasq.conf

以下为内容跟github中的一致,这里只是做测试:

#dnsmasq config, for a complete example, see:
#  http://oss.segetech.com/intra/srv/dnsmasq.conf
#log all dns queries
log-queries
#dont use hosts nameservers
no-resolv
#use cloudflare as default nameservers, prefer 1^4
server=1.0.0.1
server=1.1.1.1
strict-order
#serve all .company queries using a specific nameserver
server=/company/10.0.0.1
#explicitly define host-ip mappings
address=/myhost.company/10.0.0.2

3.编辑docker-compose.yml增加dns_server

dns_server:
    container_name: dp_dns_server
    image: 'jpillora/dnsmasq'
    restart: always
    environment:
      - TZ=${TZ}
      - HTTP_USER=${HTTP_USER}
      - HTTP_PASS=${HTTP_PASS}
    ports:
      - "53:53/tcp"
      - "53:53/udp"
      - "8090:8080"
    volumes:
      - "./services/dns/dnsmasq.conf:/etc/dmZsmasq.conf"

4.启动docker-compose并进入管理平台

$ docker-compse up -d

访问192.168.50.100:8090进入web管理页面

dns服务web界面.png

5.测试内网访问

增加一条域名映射

#test www.axinblog.com
address=/sos.axinblog.com/192.168.50.101

此映射是映射到局域网内的一台主机(IP根据你们自己的网络进行更改)点Save保存

保存映射规则.png

更改局域网内另一台Centos 7 主机DNS配置

$ vim /etc/resolv.conf
nameserver 192.168.50.100(这是你搭建dns_server服务器IP)
nameserver 8.8.8.8
nameserver 8.8.4.4

ping sos.axinblog.com 测试映射结果

映射结果.png

成功 ping 通192.168.50.101表示成功