Docker安装dnsmasq服务及相关配置

本文介绍了如何使用Docker安装dnsmasq服务,提供了一个简单的配置示例,并指导了验证步骤,适合小型网络环境使用。
摘要由CSDN通过智能技术生成
概述

dnsmasq是一轻量级的适用于小型网络的DHCP和DNS服务应用。

Dnsmasq官方

官方地址: http://www.thekelleys.org.uk/dnsmasq/doc.html在这里插入图片描述

使用Docker快速搭建服务
#搜索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.

#
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值