概述
dnsmasq是一轻量级的适用于小型网络的DHCP和DNS服务应用。
Dnsmasq官方
官方地址: http://www.thekelleys.org.uk/dnsmasq/doc.html
使用Docker快速搭建服务
- Linux环境中的Docker安装流程可参考:Linux环境安装Docker(官方手册)
- 安装好Docker之后可执行下列命令安装dnsmasq
#搜索dnsmasq镜像,可选择jpillora/dnsmasq(包含web界面)最新版
docker search dnsmasq
#拉取镜像
docker pull jpillora/dnsmasq
#新建配置,配置内容参考[配置文件示例]章节
vi /path/to/your/dnsmasq.conf
#运行镜像
#-p 53:53/udp DNS服务端口
#-p 8053:8080 Web管理平台端口,可查看、修改和重载配置,也可以查看日志。
#-v /path/to/your/dnsmasq.conf:/etc/dnsmasq.conf 映射本地文件至容器
#-e "HTTP_USER=admin" Web管理平台登录用户名
#-e "HTTP_PASS=123456" Web管理平台登录密码
#--restart always 跟随Docker启动而启动
docker run \
--name dnsmasq \
-d \
-p 53:53/udp \
-p 8053:8080 \
-v /path/to/your/dnsmasq.conf:/etc/dnsmasq.conf \
--log-opt "max-size=100m" \
-e "HTTP_USER=admin" \
-e "HTTP_PASS=123456" \
--restart always \
jpillora/dnsmasq
#查看容器运行状态
docker ps
#阿里云服务器需要在控制台开启53和8053端口
#在浏览器请求http://dnsServerIp:8053,即可打开Web交互界面
配置文件示例
- 简单配置
#log all dns queries
log-queries
#dont use hosts nameservers
no-resolv
#listen for DHCP and DNS requests only on specified interfaces (and the loopback) give the name of the interface (eg eth0) here. Repeat the line for more than one interface.
interface=eth1
#use cloudflare as default nameservers, prefer 1^4
server=8.8.4.4
server=1.1.1.1
#try each query with each server strictly in the order they appear in config file
strict-order
# Add other name servers here, with domain specs if they are for non-public domains.
#server=/localnet/192.168.0.1
#explicitly define host-ip mappings
address=/www.bilibili.com/211.150.64.54
验证
- Windows
#修改DNS服务器,使用管理员在cmd执行
#name参数值为实际的网络适配器名,使用ipconfig可查看
#addr参数值为DNS服务器地址
netsh interface ip set dns name="以太网" source=static addr=192.168.10.1
#刷新DNS信息
ipconfig /flushDNS
#浏览器请求bilibili,将会解析到263企业邮箱
https://www.bilibili.com
完整配置说明
#
# /etc/dnsmasq.conf (0644): server dnsmasq configuration
#
# Configuration file for dnsmasq.
#
# Format is one option per line, legal options are the same
# as the long options legal on the command line. See
# "/usr/sbin/dnsmasq --help" or "man 8 dnsmasq" for details.
# The following two options make you a better netizen, since they
# tell dnsmasq to filter out queries which the public DNS cannot
# answer, and which load the servers (especially the root servers)
# uneccessarily. If you have a dial-on-demand link they also stop
# these requests from bringing up the link uneccessarily.
#