Loading

docker搭建部署dnsmasq服务

配置文件

dnsmasq.conf

# dnsmasq configure file
user=dnsmasq
group=dnsmasq

server=/taobaocdn.com/223.5.5.5
server=/taobao.com/223.5.5.5
server=/aliyun.com/223.5.5.5
server=/github.com/223.5.5.5
server=/baidu.com/180.76.76.76
server=/qq.com/119.29.29.29
server=/tencent.com/119.29.29.29
server=/google.com/8.8.8.8
server=/google.com.hk/8.8.8.8

address=/ad.youku.com/127.0.0.1
address=/ad.iqiyi.com/127.0.0.1
address=/jb51.cc/127.0.0.1

# A, AAAA 和 PTR 记录 
#host-record=<name>[,<name>....],[<IPv4-address>],[<IPv6-address>][,<TTL>]

# CNAME 别名记录
#cname=<cname>,<target>[,<TTL>]

# PTR 记录 
#ptr-record=<name>[,<target>]
#naptr-record=<name>,<order>,<preference>,<flags>,<service>,<regexp>[,<replacement>]

# TXT 记录
#txt-record=<name>[[,<text>],<text>]

# IP反查域名
bogus-priv

# 缓存条数,默认为150条,cache-size=0 禁用缓存。
cache-size=4096

# 不缓存未知域名缓存,默认情况下dnsmasq缓存未知域名并直接返回为客户端。
no-negcache

# 指定DNS同属查询转发数量
dns-forward-max=256

# 严格按照resolv.conf中的顺序进行查找
strict-order

# 向所有上游服务器发送查询,而不是一个
all-servers

# 重启后清空缓存
#clear-on-reload

resolv-file=/etc/dnsmasq.resolv.conf

log-queries
#log-facility=/var/log/dnsmasq.log
log-facility=/dev/null
log-async=20

conf-dir=/etc/dnsmasq.d/,*.conf

dnsmasq.resolv.conf

nameserver 223.5.5.5
nameserver 180.76.76.76
nameserver 8.8.8.8

anti-ad-for-dnsmasq.conf

# https://anti-ad.net/

Dockerfile

FROM alpine:latest
LABEL maintainer "hbgs"
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g'  /etc/apk/repositories \
    && apk --no-cache add dnsmasq \
    && mkdir -p /etc/dnsmasq.d
EXPOSE 53 53/udp
ENTRYPOINT ["/usr/sbin/dnsmasq", "-k"]

docker-compose

version: '3'
services:
  dnsmasq:
    image: registry.cn-hangzhou.aliyuncs.com/hbgs/dnsmasq:v2.6 
    ulimits:
      nproc: 1024
      nofile:
        soft: 2048
        hard: 4096
    restart: always
    container_name: dnsmasq
    volumes:
      - ./dnsmasq.conf:/etc/dnsmasq.conf
      - ./anti-ad-for-dnsmasq.conf:/etc/dnsmasq.d/anti-ad-for-dnsmasq.conf 
      - ./dnsmasq.resolv.conf:/etc/dnsmasq.resolv.conf 
      - /etc/localtime:/etc/localtime:ro
    ports:
      - "53:53/udp"
      - "53:53/tcp"
    healthcheck:
      test: "netstat -ntpl | grep -q ':53'"
      interval: 60s
      timeout: 15s
      retries: 2
      start_period: 10s
    networks:
      - net
    cap_add:
      - NET_ADMIN
    
networks:
  net:
    driver: bridge

启动服务

docker-compose up -d
posted @ 2022-04-24 15:06  后边跟上。  阅读(842)  评论(0编辑  收藏  举报