新办公室使用TPClash实现透明代理访问内网

本文最后更新于 86 天前, 如有失效请评论区留言.

本文应该是懒人版使用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-groupsrule-providersrules

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

最后

如何实现标题的功能全靠规则了😂,比较简单这里不细说了。

仅供参考: 示例配置

Sponsor

Like this article? $1 reward

Comments

IM3133 ·v1 浙江杭州 Reply

013133xyz@gmail.com 老铁 amd64来一份,万分感谢呀

ysicing 👨‍💻 ·v1 Reply

@IM3133 github有相关源码,可以自行编译,感觉现在sb可以替换它了

lean ·v1 加利福尼亚旧金山 Reply

402300862@qq.com 找好久了,十分感谢,x86 64

老铁 ·v1 新南威尔士悉尼 Reply

hanigege911@gmail.com,找好久了,十分感谢,x86 64,如果有arm的二进制也同时给一份吧。

ysicing 👨‍💻 ·v1 Reply

@老铁 只有amd64的,记得查收

老铁 ·v1 加利福尼亚 Reply

@ysicing 大佬 ,根据你上面的具体配置里的代码,运行到你第二部分,第一行tunnels: 这一行下面一行是空格,运行时提示错误。

ysicing 👨‍💻 ·v1 Reply

@老铁 更新文章了仅供参考

update-GOGO ·v1 加利福尼亚旧金山 Reply

2662247899@qq.com 老铁 来一份 万分感谢

ysicing 👨‍💻 ·v1 Reply

@update-GOGO github有相关源码,可以自行编译,感觉现在sb可以替换它了

According to the relevant laws and regulations of the People's Republic of China, the comment function of the current website has been disabled. If you need to comment, please visit ysicing.me, but the comments still need to be reviewed by AI.