- 查找官网镜像
docker search ubuntu
- 获取ubuntu官网镜像
docker pull ubuntu
- 启动容器
docker run -it -p 53:53/udp “替换成刚下载的ubuntu镜像的id” /bin/bash
例如:docker run -it -p 53:53/udp d2a2508453ce /bin/bash
注意:-p 53:53/udp映射宿主机和容器端口,dns协议走53 端口,udp方式
- 安装dnsmasq
容器中运行
apt-get install dnsmasq
配置dnsmasq
修改dnsmasq配置文件/etc/dnsmasq.conf
resolv-file=/etc/resolv.dnsmasq.conf
strict-order
listen-address=192.168.1.15,192.168.1.6,127.0.0.1,172.17.0.2
address=/tom.com/127.0.0.1 #address字段自定义配置
server=114.114.114.114
bogus-nxdomain=114.114.114.114
log-queries
log-facility=/var/log/dnsmasq/dnsmasq.log
cache-size=10240
- resolv.dnsmasq.conf 配置文件:
nameserver 114.114.114.114
nameserver 8.8.8.8
- 启动dnsmasq
service dnsmasq start
- 测试运行
配置工作机dns为此dns容器宿主机ip
访问百度,或者网易,查看上面配置的dnsmasq日志文件
cat /var/log/dnsmasq/dnsmasq.log
即可看到我们配置的dns服务运行日志。