Skip to content

Instantly share code, notes, and snippets.

@kinfables
Last active February 7, 2024 09:31
Show Gist options
  • Star 27 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save kinfables/6db6c745457bc5ab3ce065a741a6fe81 to your computer and use it in GitHub Desktop.
Save kinfables/6db6c745457bc5ab3ce065a741a6fe81 to your computer and use it in GitHub Desktop.
Setup Allow LAN Environment with CFW

利用 Clash for Windows 部署局域网代理环境

Clash for Windows 是基于 Clash Core 开发的 Windows 平台代理工具,支持 Shadowsocks(R) / V2Ray / Trojan / Socks5 / HTTP(S) 等代理协议,支持策略组及规则分流。

下载地址: Github Releases

第一次使用?查看 快速上手

在配置好 Clash for Windows(下文略称为 CFW )后,我们可以考虑开启 Allow LAN (局域网代理共享),以便处于同一局域网内的其他设备接入到本机代理环境中。这不仅可以节省在多台设备中重复部署代理软件的时间,同时也可以通过 CFW 内置的 Connections 对局域网内设备的网络情况实时地管理与监控。

具体方法如下:

Clash for Windows 设置方法

启动 CFW 后,在 General 设置中点击 General YAML 选项,将 Profile 中的 allow-lan 值设置为 true ,随后保存并关闭配置文件窗口。最终效果如下:

# HTTP 端口
port: 7890
# Socks 5 端口
socks-port: 7891
# 局域网代理共享
allow-lan: true

此时,我们已经开启 CFW 的局域网代理共享,且可以在 General 设置中看到 Allow LAN 为启动状态。

将鼠标悬浮于 Allow LAN 选项上,可以显示此时 Windows 的内网 IP 地址。

局域网设备设置方法

以 Android 设备为例

  • 进入手机的 WLAN 设置页面,选择局域网无线设备,点击详情
  • 将代理选项改为手动,填入 Proxy hostname 及 Proxy port
  • 保存并退出

此处填入的 Proxy hostname 为部署 CFW 设备的内网 IP 地址,Proxy port 为 CFW 配置文件中指定的 HTTP 端口

Telegram 代理设置

由于 Telegram 不遵循系统代理设置,默认的 HTTP 代理并不会生效,因此需要单独配置 Socks5 代理转发其流量至 CFW。

  • 在 Telegram 中打开代理设置页面
  • 新建本地 Socks5 代理,填入 Server 及 Port
  • 保存并退出

此处填入的 Server 为部署 CFW 设备的内网 IP 地址,Port 为 CFW 配置文件中指定的 Socks5 端口

配置 Clash Dashboard

Clash Dashboard 可以在 Web 端实时显示 Clash 的流量信息、配置情况等。在局域网内其他设备中配置 Clash Dashboard 使我们不必访问桌面客户端即可完成网络监控、代理切换等操作。

项目地址:clash-dashboard | yet-another-clash-dashboard

Web 地址:http://clash.razord.top/ | http://yacd.haishan.me/

Profile 设置

打开 General 设置中 General YAML 配置文件,将 Profile 中的 external-controller 值设置为 '0.0.0.0:9090' ,如有需要,也可一并设置 secret。最终效果如下:

# RESTful API for clash
external-controller: '0.0.0.0:9090'
# RESTful API secret
secret: ''

Clash Dashboard 设置

以 yacd 为例

  • 浏览器访问 http://yacd.haishan.me/
  • 在弹出的页面中填入 Hostname 及 Port,若配置了 Secret 也应填入
  • 点击 Confrim 进入后台

此处填入的 Hostname 为部署 CFW 设备的内网 IP 地址,Port 为 CFW 配置文件中指定的 external-controller 端口

至此,Clash for Windows 的局域网代理环境及 Clash Dashboard 均已部署完毕。

参考资料

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment