1 min read

快速设置好稳定的网络环境(基于Clash)

柏林墙终有倒塌的一天

Table of Contents

作为程序员,换电脑、多系统开发司空见惯。不仅查资料需要翻墙,git操作没有梯子也不行。今天就总结一下如何快速设置好稳定的网络环境。

安装Clash

  1. 下载clash。windows|mac
  2. 安装,添加到启动项。(可选)
  3. 配置clash,参考clash配置

以上都是安装的GUI,linux脚本安装可以参考clash-for-linux

命令行代理

在GUI上配置好代理,打开代理开关后,就能在浏览器上用Google了。但是在命令行中执行命令,比如npm install, git clone等依旧受到墙的限制。clash的流量默认是通过7890端口转发的。可以通过运行以下命令来设置代理环境变量,将只在当前会话生效。最佳实践是每个会话运行一次,设置成全局可能会带来麻烦。

Windows

# 设置代理环境变量
$env:http_proxy = "http://127.0.0.1:7890"
$env:https_proxy = "http://127.0.0.1:7890"

# 取消代理环境变量
Remove-Item Env:http_proxy
Remove-Item Env:https_proxy

# 验证是否生效
curl.exe -I http://www.google.com

macOS

# 设置代理环境变量
export http_proxy=http://127.0.0.1:7890
export https_proxy=http://127.0.0.1:7890

# 取消代理环境变量
unset http_proxy
unset https_proxy

# 验证是否生效
curl -I http://www.google.com

Jason Lee
Hi, I'm Jason Lee

I hope I can still be curious about the world when I turn 60 years old.

Enjoy!

Contact me:

Email | GitHub


Content licenced under CC BY-NC-ND 4.0