Clash Transparent Proxy 透明代理/网关 在 Linux 设备上的实践和分享
source link: https://hellodk.cn/post/844
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Clash Transparent Proxy 透明代理/网关 在 Linux 设备上的实践和分享
最近折腾 Clash 透明代理/网关,记录一些心路历程,也分享一些我收集到的互联网上关于透明代理写得很好的博客文章。
我的目标是在家里局域网中某台 7x24h working 的 Linux 设备上安装 Clash Core(或者 Clash Premium),然后主路由 Openwrt 修改 lan dhcp config,将 dhcp default gateway 和 default dns 发 offer 给请求 wifi 连接的局域网设备,这样就不需要设备主动修改网关和 DNS(指向透明代理设备的 IP)。为什么不直接使用 OpenWRT 的 Passwall、OpenClash、Shadowsocks R Plus + 这些?因为我用起来总有些问题……
注意:其他普通路由器固件可能不支持修改 dhcp 默认的 gateway 和 dns
本文大概分四个部分:如何安装部署、openwrt 指定客户端获得的默认网关和 dns、透明代理设备的静态 ip 问题、文章分享
一、如何安装部署 Clash 透明代理
关于如何安装部署 clash 透明代理,网上文章很多,后面我也会贴上很多链接。在此非常推荐这个:Clash-Linux-折腾笔记
二、openwrt 的 dhcp 指定客户端获得的网关和 dns 地址
我分享一下 openwrt 如何设置 dhcp 下发的默认 gateway 和 dns, luci 访问到 http://YOUR_ROUTER_LAN_IP:PORT/cgi-bin/luci/admin/network/network/lan
,将高级设置里的 dhcp 选项设置如下
或者 ssh 到 openwrt 设备,通过修改 /etc/config/dhcp
也能达到效果
config dhcp 'lan'
option interface 'lan'
option start '100'
option limit '150'
option leasetime '12h'
option ra_slaac '1'
list ra_flags 'managed-config'
list ra_flags 'other-config'
list dhcp_option '3,10.10.10.4'
list dhcp_option '6,10.10.10.4'
在 config dhcp 'lan' 下新增如下两行即可。这样指定后重启网络 /etc/init.d/network restart
然后让设备 renew dhcp lease 或者“忘记网络”重新连接。重新连接上之后设备获得的网关和 dns 就是透明代理设备的 IP 10.10.10.4
了。否则会是 openwrt lan 接口的 ip(比如我的是 10.10.10.1
)
list dhcp_option '3,10.10.10.4'
list dhcp_option '6,10.10.10.4'
关于 dhcp option 请参考 此帖
option 号 含义 3 设置网关地址选项 6 设置DNS服务器地址选项四、透明代理设备的静态 ip 问题
可以看到 Clash-Linux-折腾笔记 中是强制指定了客户端使用 static ip,但是通过 openwrt 的 /etc/config/dhcp
也可以做到。
config host
option name 't400'
option dns '1'
option mac '00:1c:25:a2:54:c6'
option ip '10.10.10.3'
option leasetime 'infinite'
config host
option name 'n1-armbian'
option dns '1'
option mac 'fc:7c:02:4e:69:f4'
option ip '10.10.10.4'
option leasetime 'infinite'
leasetime 指定为 infinite 无限期
上面的设备 n1-armbian
就是我的透明代理设备。
然后看看 n1-armbian
的网络配置,文件 /etc/network/interfaces
source /etc/network/interfaces.d/*
#auto eth0
allow-hotplug eth0
no-auto-down eth0
iface eth0 inet dhcp
hwaddress fc:7c:02:4e:69:f4
# Local loopback
auto lo
iface lo inet loopback
四、文章分享
- [N1盒子] N1 使用armbian系统设置clash作透明网关 https://www.right.com.cn/forum/thread-712362-1-1.html
- Clash透明代理实现方式总结 https://vlike.work/tech/trans_proxy.html
- Clash 作为网关的透明代理 https://www.wogong.net/blog/2020/11/clash-transparent-proxy
- Clash使用教程 http://zhangshen147.online/post/clash-use
- 在N1的armbian中使用clash搭建透明代理 https://zorz.cc/post/n1-armbian-clash-tproxy.html
- Docker Clash 和 透明代理 https://wayjam.me/posts/docker-clash-with-tproxy/
- 使用 Debian 10 搭建旁路代理网关/透明代理 https://pengjiayou.com/debian-10-transparent-gateway/
- V2RAY 白话文指南 透明代理 https://www.bookset.io/read/v2ray-guide/930901e7691b15ce.md
- Clash-Linux-折腾笔记 https://github.com/yuanlam/Clash-Linux
- 树莓派 + V2Ray 配置翻墙路由器 https://moecm.com/tproxy-with-v2ray-on-rpi/
- 对于所谓“旁路由”的疑惑 https://www.v2ex.com/t/663066
- 又是一个本地 dns 转发器 简单易用的DNS分组/转发器 https://github.com/wolf-joe/ts-dns
- 在 Ubuntu18.04 上使用 clash 部署旁路代理网关(透明代理) https://breakertt.moe/2019/08/20/clash_gateway/
- '透明代理(REDIRECT) · V2Ray 配置指南|V2Ray 白话文教程' https://toutyrater.github.io/app/transparent_proxy.html
- '懵逼的HTTP、Socket与TCP - 简书' https://www.jianshu.com/p/a5410f895d6b
- '如何让【不支持】代理的网络软件,通过代理进行联网(不同平台的 N 种方法) | by 编程随想 | Medium' https://program-think.medium.com/%E5%A6%82%E4%BD%95%E8%AE%A9-%E4%B8%8D%E6%94%AF%E6%8C%81-%E4%BB%A3%E7%90%86%E7%9A%84%E7%BD%91%E7%BB%9C%E8%BD%AF%E4%BB%B6-%E9%80%9A%E8%BF%87%E4%BB%A3%E7%90%86%E8%BF%9B%E8%A1%8C%E8%81%94%E7%BD%91-%E4%B8%8D%E5%90%8C%E5%B9%B3%E5%8F%B0%E7%9A%84-n-%E7%A7%8D%E6%96%B9%E6%B3%95-eb22b8c04623
- Clash TProxy Mode https://lancellc.gitbook.io/clash/start-clash/clash-udp-tproxy-support
- 又双叒叕是一个本地 dns 转发器 DNSCrypt-Proxy https://github.com/XXpE3/clash_raspberrypi/blob/master/dnscrypt-proxy.md 该链接并不是原始项目,原始项目是 https://github.com/DNSCrypt/dnscrypt-proxy (有 8.1k stars 呢)
- 浅谈在代理环境中的 DNS 解析行为 链接:https://blog.skk.moe/post/what-happend-to-dns-in-proxy/
- 代替 Surge 增强模式——使用 KoolClash 作为代理网关 链接:https://blog.skk.moe/post/alternate-surge-koolclash-as-gateway/
- KoolClash 的工作机制 https://blog.skk.moe/post/how-koolclash-worked/
- iptables的四表五链与NAT工作原理 https://tinychen.com/20200414-iptables-principle-introduction/
- 第一篇万字长文:围绕透明代理的又一次探究 https://moecm.com/something-about-v2ray-with-tproxy/
感谢各位大佬的无私分享!!! 这里有很多写得深度的文章,读来受益匪浅。
文章最后:Clash 是个优秀的项目,衍生出来众多平台的版本,感谢开发者们的辛勤付出。
至于 clash tun mode,以及结合其他 dns 转发器之类的实践,暂时不做了,因为现在我的网络已满足当下的需求。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK