Docker下搭建DNS服务器



1.拉镜像
docker pull andyshinn/dnsmasq

2.dns挂载配置文件
mkdir -p /dockerdata/docker-dns
cd /dockerdata/docker-dns

vi resolv.dnsmasq
nameserver 202.96.209.133
nameserver 114.114.114.114
nameserver 8.8.8.8

vi dnsmasqhosts
192.168.14.51 vhost1-vm1 vhost1-vm1.localdomain
192.168.14.52 vhost1-vm2 vhost1-vm2.localdomain
...
注意windows客户端一定要使用有后缀域名,否则不能使用

vi dnsmasq.conf
resolv-file=/etc/resolv.dnsmasq
addn-hosts=/etc/dnsmasqhosts

3.docker启动文件
vi dns.yaml
[plain]  view plain  copy
  1. version: "2"  
  2. services:  
  3.   docker-dns:  
  4.     container_name: docker-dns  
  5.     image: andyshinn/dnsmasq  
  6.     hostname: docker-dns  
  7.     volumes:  
  8.       - /dockerdata/docker-dns/resolv.dnsmasq:/etc/resolv.dnsmasq  
  9.       - /dockerdata/docker-dns/dnsmasqhosts/:/etc/dnsmasqhosts  
  10.       - /dockerdata/docker-dns/dnsmasq.conf/:/etc/dnsmasq.conf  
  11.       - /etc/localtime:/etc/localtime:ro  
  12.     ports:  
  13.       - 53:53/tcp  
  14.       - 53:53/udp  
  15.     cap-add: NET_ADMIN  
  16.     restart: on-failure:1  

4.运行容器
docker-compose -f ./dns.yaml up -d

5.进入容器(不是bash,是/bin/sh)
docker exec -it docker-dns /bin/sh



dnsmasq requires NET_ADMIN capabilities to run correctly. Start it with something like docker run -p 53:53/tcp -p 53:53/udp --cap-add=NET_ADMIN andyshinn/dnsmasq:2.75.

The configuration is all handled on the command line (no wrapper scripts here). The ENTRYPOINT is dnsmasq -k to keep it running in the foreground. If you wanted to send requests for an internal domain (such as Consul) you can forward the requests upstream using something like docker run -p 53:53/tcp -p 53:53/udp --cap-add=NET_ADMIN andyshinn/dnsmasq:2.75 -S /consul/10.17.0.2. This will send a request for redis.service.consul to 10.17.0.2

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值