Sign inSign up

superxiao666/blocky

By superxiao666

•Updated 4 months ago

Blocky Version 0.31.0 Go 1.26.4

Image
0

2.5K

superxiao666/blocky repository overview

⁠Blocky 官方文档

https://0xerr0r.github.io/blocky/latest/

⁠Blocky GitHub 仓库

https://github.com/0xERR0R/blocky

⁠1. 项目定位

⁠Blocky 是一个:

⁠用 Go 编写的现代 DNS 代理 / DNS 过滤器 / DNS 转发器

⁠核心目标:

  • 做“带过滤能力的 DNS forwarder”
  • 替代 dnsmasq + adblock + 部分 smartdns 能力
  • 提供统一配置 + API + 规则系统

⁠2. 核心功能总览

⁠2.1 DNS 转发(Forwarding)

⁠支持多上游 DNS:
  • UDP DNS
  • TCP DNS
  • DoH(DNS over HTTPS)
  • DoT(DNS over TLS)
⁠可以配置:
  • 多 upstream
  • fallback 机制
  • load balancing(部分策略)
  • 并发查询

⁠2.2 域名过滤(核心功能)

⁠支持多种过滤源:
⁠Block lists
  • hosts 格式
  • domain list
  • regex 规则
  • wildcard
⁠示例:
ads.example.com
*.tracker.com

⁠2.3 DNS 解析策略控制

⁠可以针对域名设置:

  • 指定 upstream DNS
  • fallback DNS
  • blackhole(返回 NXDOMAIN / 0.0.0.0)
  • custom response

⁠类似:

  • “按域名分流 DNS”

⁠2.4 缓存系统(DNS Cache)

⁠支持:

  • TTL cache
  • negative caching(NXDOMAIN缓存)
  • memory cache

⁠提升性能明显:

  • 重复查询几乎 0 延迟

⁠2.5 ECS(EDNS Client Subnet)

⁠支持:

  • 向上游 DNS 传递客户端子网
  • 改善 CDN 解析(如 Google / Netflix)

⁠可配置:

  • 开启/关闭
  • mask size

⁠2.6 DNS over HTTPS / TLS

⁠Blocky 可以作为:

  • DoH client
  • 连接 Cloudflare / Google / AdGuard DNS
  • DoT client
  • TLS 加密 DNS 上游

⁠2.7 本地 DNS Server 功能

⁠监听:

  • UDP 53
  • TCP 53

⁠支持:

  • 多 listener
  • bind 多 IP
  • IPv4 / IPv6

⁠2.8 日志与审计

⁠支持:

  • query log
  • access log
  • block log

⁠输出:

  • console
  • file
  • syslog(部分配置)

⁠2.9 Prometheus 指标(重要)

⁠内置 metrics:

  • DNS query count
  • cache hit ratio
  • blocked queries
  • upstream latency

⁠2.10 规则引擎(Rule Engine)

⁠Blocky 的核心设计之一:

⁠支持规则类型:

  • domain exact match
  • suffix match
  • regex match
  • wildcard
  • CIDR(部分场景)

⁠2.11 多 upstream 分流(关键能力)

⁠可以做到:

  • 国内域名 → 114DNS / DoH CN
  • 国外域名 → Cloudflare / Google
  • 广告域名 → blackhole

⁠类似:

  • MosDNS 的“rule-based upstream routing”

⁠2.12 API / 管理接口

⁠支持 HTTP API:

  • reload config
  • stats
  • health check
  • metrics

⁠2.13 热更新(Hot Reload)

⁠支持:

  • 配置文件变更自动 reload
  • 不需要重启进程

⁠3. 架构设计

           +-------------------+
DNS Query →| Listener (UDP/TCP)| 
           +-------------------+
                     |
                     v
           +-------------------+
           |  Rule Engine      |
           | (match / filter)  |
           +-------------------+
                     |
     +---------------+----------------+
     |                                |
     v                                v
+-----------+                 +---------------+
| Blocklist |                 | Upstream DNS |
+-----------+                 +---------------+
                                     |
                                     v
                              DNS Response

⁠4. 配置体系(核心)

upstream:
  default:
    - 1.1.1.1
    - 8.8.8.8

blocking:
  blackLists:
    ads:
      - https://example.com/list.txt

  clientGroupsBlock:
    default:
      - ads

port: 53

⁠5. 性能特点

⁠优点

  • Go 原生并发
  • cache 性能不错
  • 多 upstream 并发查询 -启动快

⁠运行构建

运行方式:

  1) 基础运行(traceroute 需用 -T 模式):
     docker run -d --name blocky \
       -p 4000:4000 \
       -p 53:53/tcp -p 53:53/udp \
       superxiao666/blocky:latest

  2) 推荐运行(支持 traceroute ICMP 模式):
     docker run -d --name blocky \
       --cap-add=NET_RAW \
       --cap-add=NET_ADMIN \
       -p 4000:4000 \
       -p 53:53/tcp -p 53:53/udp \
       superxiao666/blocky:latest

  3) 使用自定义配置:
     docker run -d --name blocky \
       --cap-add=NET_RAW \
       -v /path/to/config.yml:/app/config.yml:ro \
       -p 4000:4000 \
       -p 53:53/tcp -p 53:53/udp \
       superxiao666/blocky:latest

Tag summary

Content type

Image

Digest

sha256:997eb67f9…

Size

21.9 MB

Last updated

4 months ago

docker pull superxiao666/blocky