内网DNS服务搭建

内网DNS服务搭建 docker搭建DNS服务

  1. docker pull andyshinn/dnsmasq
  2. 工作目录 /websys/opt/dnsmasq
  3. 域名映射ip文件 my_dnsmasq_hosts
192.168.1.102   test1.com
192.168.1.102   test2.com
  1. dns文件 my_resolv.dnsmasq
nameserver 114.114.114.114
nameserver 8.8.8.8
  1. 启动容器
sudo docker run -d \
-p 192.168.1.102:53:53/tcp \
-p 192.168.1.102:53:53/udp \
-v /websys/opt/dnsmasq/my_dnsmasq_hosts:/etc/my_dnsmasq_hosts \
-v /websys/opt/dnsmasq/my_resolv.dnsmasq:/etc/my_resolv.dnsmasq \
--cap-add=NET_ADMIN \
--name my_dns_server \
andyshinn/dnsmasq
  1. 进入容器修改文件 docker exec -it my_dns_server /bin/sh
vi /etc/dnsmasq.conf 
# 修改两处地方,都需要取消掉注释,并制定文件
addn-hosts=/etc/my_dnsmasq_hosts
resolv-file=/etc/my_resolv.dnsmasq
  1. 退出容器重启-docker restart my_dns_server
  2. 修改路由器上的DNS或客户端电脑上的DNS

docker-compose.yml 版

version: '2'
services:
registry:
  image: andyshinn/dnsmasq:latest
  container_name: my_dns_server
  tty: true
  cap_add:
    - NET_ADMIN
  ports:
    - 192.168.1.102:53:53/tcp
    - 192.168.1.102:53:53/udp
  volumes:
    - /home/wilker/Desktop/a_dns/my_dnsmasq_hosts:/etc/my_dnsmasq_hosts
    - /home/wilker/Desktop/a_dns/my_resolv.dnsmasq:/etc/my_resolv.dnsmasq

相关资料

ubuntu_内网dns服务器搭建

发表评论