[toc]
dns 服务器使用
一. 配置文件
- docker-compose配置文件(docker-compose.yaml)
version: '2'
services:
dns:
container_name: dns
image: jpillora/dnsmasq
restart: always
volumes:
- ./dnsmasq.conf:/etc/dnsmasq.conf
#command: mongod
environment:
- HTTP_USER=admin
- HTTP_PASS=admin
ports:
#- 27017:27017
- 53:53/udp
- 8080:8080
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "10"
- dns配置文件自定义域名解析(dnsmasq.conf)
#dnsmasq config, for a complete example, see:
# http://oss.segetech.com/intra/srv/dnsmasq.conf
#log all dns queries
log-queries
#dont use hosts nameservers
no-resolv
#use cloudflare as default nameservers, prefer 1^4
server=1.0.0.1
server=1.1.1.1
strict-order
#serve all .company queries using a specific nameserver
server=/company/10.0.0.1
#explicitly define host-ip mappings
address=/myhost.company/10.0.0.2
二. 使用步骤
-
启动dns服务
在机器a(ip=192.168.0.110)上执行docker-compose -f docker-compose.yaml up -d
-
修改 /etc/resolv.conf 文件
在机器a和b上nameserver 127.0.0.1 # dns服务与其他容器在同一台机器上时必须添加(否则可以不加) nameserver 192.168.0.110 # 192.168.0.110 为dns服务的ip
-
在浏览器中打开192.168.0.110:8080可以在线,查看,修改,保存,重启
三. 接口
1. 保存接口
- 方法: POST
- url: /save
- header:
key | value | 备注 |
---|---|---|
Accept-Encoding | gzip, deflate, br | |
Content-Type | application/json | |
Authorization | Basic YWRtaW46YWRtaW4= | 用户名,密码的base64编码 |
- body:
特别注意每个配置项一定要用\n
隔开
{
"/etc/dnsmasq.conf": "#dns解析日志\nlog-queries\nserver=223.5.5.5\n#定义主机与IP映射\naddress=/h0/172.17.205.28 \naddress=/h1/192.168.0.15"
}
2. 重启接口
- 方法: PUT
- url: /restart
- header:
| key | value | 备注 |
| --------------- | ---------------------- | ----------------------- |
| Accept-Encoding | gzip, deflate, br | |
| Content-Type | application/json | |
| Authorization | Basic YWRtaW46YWRtaW4= | 用户名,密码的base64编码 |
四. 注意事项
- dns服务与其他容器在同一台机器上时必须在
/etc/resolv.conf
在nameserver 127.0.0.1
并放在第一行
网友评论