docker-compose 搭建dns服务
这边选择的是带图像化界面的开源软件 adguardhome 快速搭建dns服务
安装docker-compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
编写docker-compose.yml
version: "3"
services:
adguardhome:
image: adguard/adguardhome:latest
container_name: adguard
hostname: localhost # set to fqdn of host
ports:
- 53:53/tcp
- 53:53/udp
- 67:67
- 68:68
- 3000:3000
- 853:853
- 80:80
volumes:
- ./services/dns/workdir:/opt/adguardhome/work
- ./services/dns/confdir:/opt/adguardhome/conf
environment:
TZ: "Asia/Shanghai"
networks:
- default
启动容器
[root@DNS dns]# vim docker-compose.yml
[root@DNS dns]# docker-compose up -d
Recreating adguard ... done
[root@DNS dns]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
db769cda4cf7 adguard/adguardhome:latest "/opt/adguardhome/Ad…" 3 seconds ago Up 2 seconds 0.0.0.0:53->53/tcp, 80/tcp, 0.0.0.0:67-68->67-68/tcp, 0.0.0.0:853->853/tcp, 0.0.0.0:3000->3000/tcp, 0.0.0.0:53->53/udp, 67-68/udp, 443/tcp adguard
配置图形化界面
adguard的详细使用方法可以看官网文档,这里只是用dns重写功能
修改dns
在master和worker上修改dns,这里使用过的是network manager修改
[root@master conf.d]# nmtui
[root@master conf.d]# /etc/init.d/network restart
Restarting network (via systemctl): [ OK ]
验证
在没有改host 的情况下,ping ping master.com 是出的局域网ip,证明dns生效
[root@worker01 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
[root@worker01 ~]# ping master.com
PING master.com (192.168.189.128) 56(84) bytes of data.
64 bytes from 192.168.189.128 (192.168.189.128): icmp_seq=1 ttl=64 time=0.233 ms
[root@master conf.d]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
[root@master conf.d]# ping node1.com
PING node1.com (192.168.189.129) 56(84) bytes of data.
64 bytes from 192.168.189.129 (192.168.189.129): icmp_seq=1 ttl=64 time=0.241 ms
64 bytes from 192.168.189.129 (192.168.189.129): icmp_seq=2 ttl=64 time=0.487 ms