基于大鹅dae配置自建一个超简单透明代理

304 阅读5分钟

免责声明:

本文中信息来源于网络,作者不保证其绝对正确性。读者在依据本文内容做出任何决策或行动前,应自行进行充分的调查与核实。对于因使用本文内容而产生的任何直接或间接损失,作者不承担任何责任。

本文为技术性文章分享,观看需要一定的技术能力

现状

目前自建代理服务软件 mihomo, sing-box 其实已经可以方便的跨平台部署了,但是如果自建的话,还要考虑维护成本,它们的配置文件有点复杂(参考下面对比),维护成本较高。

实现效果

今天小编实现在家用路由器 r68s 上部署一个 dae 实现透明代理服务,综合安装,配置,维护成本以最小的花销实现一个家用的透明代理服务。

安装

使用工具

  • r68s 硬件路由器

  • immortalWrt 24.10

  • daed (是 dae + webUI 的实现)

今天主角 Dae 是一个基于 eBPF 的 linux 高性能透明代理解决方案,官方提供了方便的安装脚本部署简单,配置文件语法直观易懂。小编使用它的webUI版本 daed 在 r68s 上部署一个服务。

官方地址 github.com/daeuniverse…

安装

ImmortalWrt 24.10 版本的源中已经有编译好的 dae/daed, 打开软件包菜单,更新源后直接搜索 daed 安装就好。

安装好 daed 后,在服务菜单中,选中启用并保存应用。

现在访问路由器的2023端口,开始配置 daed.

在 daed 中配置 dae 其实非常简单,基本步骤如下

  • 在 global 全局配置中,主要指定我们网络流量【进出口网卡】等
  • 在 dns 中指定直连/代理的dns分流规则
  • 在 “路由” 中 指定域名/ip的转发规则
  • 在”节点” 中配置自己的节点地址,基本可以配置所有的代理协议(vmess/ss/ssr/trojan/tuic/hy2)
  • 把”节点”拖放到 proxy 的组中
  • 启动服务。

这样就大功告成了。

小编的 global 配置

小编的 dns 配置

小编的 routing 配置

以下给出一些简单具体的 dns 与 routing 配置供参考。

简化的 dns 配置,完全够用了

# https://github.com/daeuniverse/dae/blob/main/docs/en/configuration/dns.md
dns {
  upstream {
    googledns: 'tcp+udp://dns.google:53'
    alidns: 'udp://dns.alidns.com:53'
  }
  routing {
    # 根据 DNS 查询,决定使用哪个 DNS 上游。
    # 按由上到下的顺序匹配。
    request {
      # 对于中国大陆域名使用 alidns,
      qname(geosite:cn) -> alidns

      # 其他使用 googledns 查询。
      # fallback 意为默认规则
      fallback: googledns
    }
  }
}

带注释的路由 routing 规则,基本够用了。

# https://github.com/daeuniverse/dae/blob/main/docs/en/configuration/routing.md
pname(NetworkManager, systemd-resolved, dnsmasq) -> must_direct
# 局域网内广播,防止被代理转发
dip(224.0.0.0/3, 'ff00::/8') -> direct
# 私有地址走直连
dip(geoip:private) -> direct
# 目标非常用端口都走直连,避免BT流量走代理
!dport(21,23,53,80,123,143,194,443,465,587,853,993,995,998) -> direct
# 阻断广告连接
domain(geosite:category-ads, geosite:category-ads-all) -> block
dscp(4) -> direct

#公共domain规则
### DIRECT MACHINE
# mac("BC:24:11:XX:XX:XX") -> direct
### AppleCN
domain(geosite:apple@cn) -> direct
### WeChat & Tencent Optimization (High Priority - Direct)
domain(suffix: cdn-go.cn) -> direct
domain(suffix: smtcdns.com) -> direct
domain(suffix: smtcdns.net) -> direct
domain(geosite:tencent) -> direct
### CN Direct Services
domain(geosite:alibaba) -> direct
domain(geosite:apple@cn) -> direct
domain(geosite:microsoft@cn) -> direct
domain(geosite:steam@cn) -> direct
domain(suffix: cm.steampowered.com) -> direct
domain(suffix: steamserver.net) -> direct
### Game
domain(geosite: category-games@cn) -> direct
### OpenAI
domain(geosite:openai) -> proxy  

# Dev & Tools
domain(geosite:github) -> proxy
domain(geosite:docker) -> proxy
domain(suffix: gradle.org) -> proxy
domain(suffix: linux.do) -> proxy

# Google
domain(geosite:google) -> proxy

# Trading & Finance
domain(keyword: tradingview) -> proxy

### User Custom Rules (Proxy)
### 如果使用小米路由器,配置放行,避免内存泄露
#domain(suffix: miwifi.com) -> direct(must)


### 禁用Quic,避免CPU高负载及内存泄露
l4proto(udp) && dport(443) -> block
domain(geosite:geolocation-!cn) -> proxy
dip(geoip:cn) -> direct
domain(geosite:cn) -> direct

# 未匹配,走代理
fallback: proxy

导出配置

daed 本身未提供配置导出功能,考虑到方便备份。小编手搓了一个零依赖的 python3 脚本实现 daed 配置备份功能

# 未考虑设计,未充分测试
import sqlite3
import sys
from pathlib import Path


def read_tables(db_path, tables):
    daed_config_map = {"configs": "global", "dns": "dns", "routings": "routing"}
    try:
        # 连接数据库
        conn = sqlite3.connect(db_path)
        cursor = conn.cursor()

        for table in tables:
            # print(f"--- Table: {table} ---")
            try:
                daed_config_key = daed_config_map.get(table)
                if daed_config_key:
                    # 获取特定类型的数据
                    cursor.execute(f"SELECT {daed_config_key} FROM {table}")
                else:
                    cursor.execute(f"SELECT * FROM {table}")

                rows = cursor.fetchall()
                for row in rows:
                    print(row[0])

            except sqlite3.OperationalError as e:
                print(f"Error reading {table}: {e}")

    except sqlite3.Error as e:
        print(f"Database error: {e}")
    finally:
        if conn:
            conn.close()


if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("Usage: python main.py <database_path>")
        sys.exit(1)

    dbname = sys.argv[1]

    if Path(dbname).stat().st_size == 0:
        print("Database file is empty.")
        sys.exit(1)

    target_tables = ["configs", "dns", "routings"]
    read_tables(dbname, target_tables)

使用方式

# 在 r68s 上安装好 python3
$ python run.py daed_database_path

总结

经小编使用对比 mihomo/dae 的经验总结,从代理的安装,配置,维护角度来看; dae 整体领先一步。

它们的配置文件对比(mihomo 稍微复杂,而且维护成本高一点。)

以上观点仅为小编本人观点,仅供参考。

希望小编文章能帮助到大家,欢迎关注本公众号;有问题留言交流。

其他

欢迎关注本公众号其他社媒平台

点击以下链接关注我的数字名片!

muselink.cc/hamisay

"如果您觉得这篇文章对您或您的朋友有所帮助,不妨动动手指,关注我们、点赞并分享到朋友圈,让更多人受益。您的每一次互动都是对我们最大的支持和鼓励!"

往期文章

量大管饱的wifi6无线路由器!最低2x包邮?

都2026了,如何获得一个性价比,性能合适,又省心的家用路由器