有时候需要将某个dns指向内容完成一些开发调试或者运维工作,使用dnsmasq可以简单快速的完成我们的需求

docker pull andyshinn/dnsmasq

建立工作目录

mkdir -p dnsmasq/data
cd dnsmasq

建立配置文件

cat >> data/resolv.dnsmasq << EOF
nameserver 218.30.19.50
nameserver 114.114.114.114
nameserver 8.8.8.8
EOF


cat >> data/dnsmasqhosts << EOF
192.168.106.230 c4w.getdemo.cn
EOF


cat >> data/dnsmasq.conf << EOF
resolv-file=/etc/resolv.dnsmasq
addn-hosts=/etc/dnsmasqhosts
EOF

建立启动脚本

cat >> dnsmasq.yaml << EOF
version: "2"
services:
  dnsmasq:
    container_name: dnsmasq
    image: andyshinn/dnsmasq
    hostname: dnsmasq
    volumes:
      - ./data/resolv.dnsmasq:/etc/resolv.dnsmasq
      - ./data/dnsmasqhosts/:/etc/dnsmasqhosts
      - ./data/dnsmasq.conf/:/etc/dnsmasq.conf
      - /etc/localtime:/etc/localtime:ro
    ports:
      - 53:53/tcp
      - 53:53/udp
    cap_add:
      - NET_ADMIN
    restart: on-failure:1
EOF

启动容器

docker-compose -f ./dnsmasq.yaml up -d

测试

C:\Users\jilili>nslookup c4w.getdemo.cn 192.168.106.51
服务器:  UnKnown
Address:  192.168.106.51

名称:    c4w.getdemo.cn
Address:  192.168.106.230

刚才建立的dns服务器的地址是192.168.106.51

[ 编辑 | 历史 ]
最近由“jilili”在“2019-01-16 15:54:48”修改