# 科学上网-让终端走代理

## 介绍

在终端环境下，常会遇到要下载某个文件巨慢，甚至无法连接,急需一个方案来拯救.

## 过程

1. 临时

   ```shell
   # 协议填http或socks5
   export http_proxy=http://127.0.0.1:10809
   export https_proxy=https://127.0.0.1:10809
   export http_proxy=socks5://127.0.0.1:10808
   export https_proxy=socks5://127.0.0.1:10808
   # 让环境生效
   source /etc/profile
   # ping是ICMP报文，代理不转发
   # 检查终端是否处于代理状态
   curl cip.cc
   # 针对codex 登录1455可以如上配置
   # 配置后需要新开终端运行 codex login登录,获取到auth.json后，下次插件和终端就都可以使用了
   ```
2. 或使用 `alias`

   ```shell
   alias setproxy='export ALL_PROXY=socks5://127.0.0.1:10808'
   alias unsetproxy='unset ALL_PROXY'
   ```
3. `ssh`走代理 新增 `~/.ssh/config` ::: code-group

   ```shell
   # github socks5 
   Host github.com
       HostName github.com
       User git
       Port 22
       IdentityFile ~/.ssh/id_ed25519
       ProxyCommand nc -v -x 127.0.0.1:10808 %h %p

   # github http
   Host github.com
       HostName github.com
       User git
       Port 22
       IdentityFile ~/.ssh/id_ed25519
       ProxyCommand corkscrew 127.0.0.1:10809 %h %p
   # linux需要单独安装 `corkscrew`
   # sudo apt install corkscrew
   ```

   ```shell
   # 测试 SSH 连接（看到下面提示说明成功）
   ssh -T git@github.com
   # 成功提示：
   # Hi 用户名! You've successfully authenticated, but GitHub does not provide shell access.

   git clone --depth 1 https://github.com/用户名/项目名.git
   ```

   ::: code-group
4. `curl`走代理 新增 `~/.curlrc`

   ```shell
   proxy = http://127.0.0.1:10809
   ```

## 在windows WSL中配置代理

```shell
# 查找本机ip 最后的nameserver就是ip
cat /etc/resolv.conf
# 协议填http或sock
export http_proxy="http://ip:port"
export https_proxy="http://ip:port"
# 让环境生效
source /etc/profile
```

## 在windows CMD中配置代理

```shell
# 协议填http
set http_proxy=http://127.0.0.1:10809
set https_proxy=http://127.0.0.1:10809

# ps:一定要用cmd命令行，千万别用powershell !!!
# 简易测试命令：curl https://www.google.com（别用ping）
```

## 参考

1. [Linux 让终端走代理的几种方法](https://zhuanlan.zhihu.com/p/46973701)
2. [windows终端翻墙，简易方式](https://gist.github.com/dreamlu/cf7cbc0b8329ac145fa44342d6a1c01d)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ougege.gitbook.io/blog/docs/articles/wall/ke-xue-shang-wang-rang-zhong-duan-zou-dai-li.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
