新办公室使用TPClash实现透明代理访问内网
前情
之前和其他职场办公室组网基本都是每个人都自行拨 VPN 进行组网,换新办公室后,空间比较大,想用一台闲置的 minipc 当作旁路由,在旁路由上进行 VPN 拨号,同时基于 tpclash 进行内网和公网流量分流。
从我目前使用来看,clash premium 目前好像没有什么特别大问题,还是用之前的老内核,反正挺稳定的。
下载 TPClash
由于之前的风波,clash 系基本都删库规避风险了,也有部分存档,但是基本都满足使用了。也可以基于现在已有 github 项目重新构建。
目前我自己用的版本
# tpclash -v
Build: 2023-10-12 21:15:56
Version: v0.0.20-3-g6cb1e54
Clash Core: latest-20231012
Commit: 6cb1e54bff578de905ec07c936885d051c24d1bc
# /data/clash/xclash -v
Clash 2023.08.17-13-gdcc8d87 linux amd64 with go1.21.0 Tue Sep  5 02:15:22 PM UTC 2023
# md5sum tpclash
ad547fe81ac0ee22704fa54382ef1fa3  tpclash
这里就不贴出具体路径了,如果有需要,可以自行编译
git clone https://github.com/xlpppp/tpclash.git
cd tpclash
task
具体配置
我列出上面部分配置,剩余的就是 proxy-groups、rule-providers、rules
mixed-port: 7374
tproxy-port: 7375
allow-lan: true
bind-address: "*"
mode: rule
log-level: debug
routing-mark: 7777
# 你的实际网卡
interface-name: ens18
external-controller: 0.0.0.0:22222
secret: "suibianxiexieysicing"
experimental:
  sniff-tls-sni: true
profile:
  store-selected: true
  store-fake-ip: true
  tracing: true
dns:
  enable: true
  listen: 0.0.0.0:1053
  use-hosts: true
  ipv6: false
  enhanced-mode: fake-ip
  fake-ip-range: 198.18.0.1/16
  default-nameserver:
    - 121.4.4.123
    - 120.53.53.38
    - 119.29.29.29
    - 180.76.76.76
  nameserver:
    - https://doh.pub/dns-query
    - tls://dot.pub
    - tls://dns.alidns.com
    - https://dns.alidns.com/dns-query
  fallback:
    - https://dns.twnic.tw:10443/dns-query
    - tls://dns.google:852
  fake-ip-filter:
    - '+.lan'
    - '+.cluster.local'
    - 'time.*.com'
    - 'time.*.gov'
    - 'time.*.edu.cn'
    - 'time.*.apple.com'
    - 'ntp.*.com'
    - 'localhost.ptlogin2.qq.com'
    - '+.ntp.org.cn'
    - '+.pool.ntp.org'
    - '+.localhost'
  fallback-filter:
    geoip: true
    geoip-code: CN
    ipcidr:
      - 224.0.0.0/4
      - 240.0.0.0/4
      - 169.254.0.0/16
      - 0.0.0.0/8
      - 127.0.0.1/32
  nameserver-policy:
    '+.cluster.local': '10.143.109.50'
太长截断了,分成两部分
tunnels:
- network: [tcp]
  address: 0.0.0.0:853
  target: 1.1.1.1:853
  proxy: proxy
- network: [tcp]
  address: 0.0.0.0:852
  target: 8.8.8.8:853
  proxy: proxy
- network: [tcp]
  address: 0.0.0.0:851
  target: 185.222.222.222:853
  proxy: proxy
- network: [tcp]
  address: 0.0.0.0:850
  target: 94.140.14.14:853
  proxy: proxy
- network: [tcp]
  address: 0.0.0.0:10443
  target: 101.101.101.101:443
  proxy: proxy
- network: [tcp]
  address: 0.0.0.0:10442
  target: 104.16.132.229:443
  proxy: proxy
- network: [tcp]
  address: 0.0.0.0:10441
  target: 45.125.0.26:443
  proxy: proxy
- network: [tcp]
  address: 0.0.0.0:10440
  target: 103.121.210.210:443
  proxy: proxy
hosts:
  "one.one.one.one": "127.0.0.1"
  "dns.google": "127.0.0.1"
  "dot.sb": "127.0.0.1"
  "doh.dns.sb": "127.0.0.1"
  "hk-hkg.doh.sb": "127.0.0.1"
  "dns.cloudflare.com": "127.0.0.1"
  "dns.twnic.tw": "127.0.0.1"
  "dns.adguard.com": "127.0.0.1"
tun:
  enable: true
  stack: system
  dns-hijack:
    - any:53
  auto-route: true
  auto-detect-interface: true
另外记得宿主机 dns 不要是内网地址,因为 dns 劫持只会公网 dns 请求,改成 8.8.8.8 就可以了
配置 systemd
# /etc/systemd/system/tpclash.service
[Unit]
Description=A tpproxy in Go for %i.
After=network.target
[Service]
Type=simple
User=root
Restart=on-abort
ExecStart=/usr/bin/tpclash -c /etc/clash/config.yaml
[Install]
WantedBy=multi-user.target
默认所有的配置都在 /data/clash/ 目录下
其他内网机器配置
ip route delete default
ip route add default via 192.168.99.11 dev ens18
192.168.99.11是部署 tpclash 的机器地址ens18是你当前机器的网卡名,具体情况具体对待- 检查 dns 是否为公网地址,随便写个如 
8.8.8.8 
最后
如何实现标题的功能全靠规则了 😂,比较简单这里不细说了。
仅供参考: 示例配置
