个人家用无障碍网络的几种常用实现机制方案

现实中基本可归结如下三种方式来实现

以下基于上面第三种方式介绍个配置案例

所需依赖涉及到的硬件及软件资源包括:

Raspberry Pi 初始化系统配置

开源工具 Clash 的使用及网关路由的配置

# config.yaml
port: 7890
socks-port: 7891
redir-port: 7892
mixed-port: 7893
ipv6: false
allow-lan: true
mode: Rule
log-level: info
external-controller: '0.0.0.0:6300'
external-ui: clash-dashboard
secret: ''
experimental:
  ignore-resolve-fail: false
dns:
  enable: true
  ipv6: false
  listen: 0.0.0.0:53
    #enhanced-mode: redir-host
  enhanced-mode: fake-ip #如果要玩netflix,需要使用fake-ip
  fake-ip-range: 198.18.0.1/16
  nameserver:
    - https://dns.alidns.com/dns-query # DNS-over-HTTPS

hosts:
  "dns.alidns.com": 223.5.5.5

# 配置节点代理服务器
proxies:
  # shadowsocks
  # 支持加密方式:
  #   aes-128-gcm aes-192-gcm aes-256-gcm
  #   aes-128-cfb aes-192-cfb aes-256-cfb
  #   aes-128-ctr aes-192-ctr aes-256-ctr
  #   rc4-md5 chacha20 chacha20-ietf xchacha20
  #   chacha20-ietf-poly1305 xchacha20-ietf-poly1305
  #- name: "ss"
  #  type: ss
  #  server: https.server.domain
  #  port: 443
  #  cipher: chacha20-ietf-poly1305
  #  password: "passowrd"
  #  # udp: true

  # vmess
  # 支持加密方式:auto / aes-128-gcm / chacha20-poly1305 / none
  - name: "vmess"
    type: vmess
    server: gfw.yousri.org
    port: 443
    uuid: *******
    alterId: 0
    cipher: auto
    # udp: true
    tls: true
    skip-cert-verify: true
    # servername: example.com # 优先级高于 wss host
    network: ws
    ws-path: /
    ws-headers:
      Host: gfw.yousri.org

  # socks5
  #- name: "socks"
  #  type: socks5
  #  server: server
  #  port: 443
  #  # username: username
  #  # password: password
  #  # tls: true
  #  # skip-cert-verify: true
  #  # udp: true

# 配置 Group
proxy-groups:
  # 自动切换
  - name: "auto"
    type: url-test
    proxies:
      #- http
      #- ss
      - vmess
      #- socks
    # tolerance: 150
    url: 'https://www.google.com/'
    interval: 600
  # 按需选择 - 可以在UI上选择
  - name: "netflix"
    type: select
    proxies:
      #- https01
      #- ss
      - vmess
      #- socks

rules:
# LAN
  - DOMAIN-SUFFIX,local,DIRECT
  - IP-CIDR,127.0.0.0/8,DIRECT
  - IP-CIDR,172.16.0.0/12,DIRECT
  - IP-CIDR,192.168.0.0/16,DIRECT
  - IP-CIDR,10.0.0.0/8,DIRECT

# Netflix
  - DOMAIN-SUFFIX,fast.com,netflix
  - DOMAIN-SUFFIX,api-global.netflix.com,netflix
  - DOMAIN-SUFFIX,netflix.com,netflix
  - DOMAIN-SUFFIX,netflix.net,netflix
  - DOMAIN-SUFFIX,nflxext.com,netflix
  - DOMAIN-SUFFIX,nflximg.com,netflix
  - DOMAIN-SUFFIX,nflximg.net,netflix
  - DOMAIN-SUFFIX,nflxso.net,netflix
  - DOMAIN-SUFFIX,nflxvideo.net,netflix

# 最终规则(除了中国区的IP之外的,全部翻墙)
  - GEOIP,CN,DIRECT
  - MATCH,auto

需要注意以下的一些配置。

关于其他 proxies、proxy-groups 以及 rules 的配置,则可以根据需要自行编辑。更多 Clash 示例配置及说明可以参考 config.yaml 中的内容。

cd $HOME/.config/clash/
git clone https://github.com/Dreamacro/clash-dashboard.git
cd clash-dashboard/
git checkout -b gh-pages origin/gh-pages

局域网内的其他设备配置网关和 DNS

最后,将局域网内需要使用无墙模式的其他设备的网关和 DNS 均配置为 Pi 的 IP 地址即可,下图以 iOS 设备为例。在浏览器中访问 http://IP:6300/ui/ 可以查看到经由 Clash 处理的所有当前连接。

参考文档

How to use Raspberry Pi Imager | Install Raspberry Pi OS to your Raspberry Pi

家用旁路网关