实用技巧
终端和 Git 默认不走系统代理时怎么设置:export 代理变量与 proxy_on 开关、Git 和 npm 代理、DNS 泄漏处理,以及看视频、玩游戏、用 ChatGPT / Claude 时怎么挑节点,选机场看稳定性和晚高峰速度。
核对于 2026-09-14
终端代理
很多命令行工具(例如 Claude Code、Codex CLI)默认不走系统代理,需要手动配置;想省事也可以直接开 FlClash TUN 模式 全局接管终端流量。
临时设置
export https_proxy=http://127.0.0.1:7890
export http_proxy=http://127.0.0.1:7890
export all_proxy=socks5://127.0.0.1:7891写入配置文件
在 ~/.zshrc 或 ~/.bashrc 中添加:
# 代理开关
proxy_on() {
export https_proxy=http://127.0.0.1:7890
export http_proxy=http://127.0.0.1:7890
export all_proxy=socks5://127.0.0.1:7891
echo "代理已开启"
}
proxy_off() {
unset https_proxy http_proxy all_proxy
echo "代理已关闭"
}然后用 proxy_on 和 proxy_off 切换。
Git 代理
# 设置
git config --global http.proxy http://127.0.0.1:7890
git config --global https.proxy http://127.0.0.1:7890
# 取消
git config --global --unset http.proxy
git config --global --unset https.proxy只对 GitHub 设置代理:
git config --global http.https://github.com.proxy http://127.0.0.1:7890npm / pnpm 代理
npm config set proxy http://127.0.0.1:7890
npm config set https-proxy http://127.0.0.1:7890或使用镜像源替代:
npm config set registry https://registry.npmmirror.comDNS 泄漏
即使开了代理,DNS 请求可能还是走默认 DNS,导致:
- 访问速度不理想
- 隐私泄漏
解决方案:
- 开启 Clash 的 TUN 模式 配合 fake-ip DNS 接管解析
- 或手动配置 DNS 为
1.1.1.1/8.8.8.8
选择节点的技巧
- 日常浏览:选延迟低的(< 150ms),香港、日本节点通常最快
- 看视频:选带宽大的节点,不一定延迟最低
- 下载文件:选负载低的节点
- ChatGPT / Claude / Antigravity:部分节点 IP 或香港节点会被拒,避坑见 Claude Code 国内网络配置、Codex 中国大陆使用说明 与 Antigravity 国内网络配置
- 游戏:选延迟最低且稳定的节点,开启 UDP 转发
机场选择建议
- 看稳定性而非节点数量
- 关注高峰期(晚 8-11 点)的速度
- 备一个备用机场,主力挂了能应急
- 月付试用,别一上来就年付
参考来源
- Git 官方文档 git-config:https://git-scm.com/docs/git-config(查阅于 2026-09-14)
- npm 官方文档 npm config:https://docs.npmjs.com/cli/commands/npm-config(查阅于 2026-09-14)
- npmmirror 镜像站:https://npmmirror.com/(查阅于 2026-09-14)