forked from talkgo/night
-
Notifications
You must be signed in to change notification settings - Fork 1
/
macos-terminal-proxy-set.md
48 lines (39 loc) · 1.5 KB
/
macos-terminal-proxy-set.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
Macos 终端设置代理
===============
前提是需要有个http代理 例如端口号为 1081
下面的命令加入到 ` ~/.bash_profile`(如果使用系统终端) 或者 `~/.zshrc`(如果使用zsh),更改完成之后请在当前终端执行 `source ~/.bash_profile` or `source ~/.zshrc`
```
alias setproxy="export http_proxy=http://127.0.0.1:1081 && export https_proxy=http://127.0.0.1:1081 && curl -i http://ip.cn"
alias unsetproxy="unset http_proxy && unset https_proxy && curl -i http://ip.cn"
```
上面的方式来自群友 @Amor
因为我的代理设置了pac,所以使用 ip.cn还是被转发到国内, 测试就不准了,于是使用 `google.com` 来作为测试url, 使用方式同上
```
alias setproxy="export http_proxy=http://127.0.0.1:1081 && export https_proxy=http://127.0.0.1:1081 && curl -i http://google.com"
alias unsetproxy="unset http_proxy && unset https_proxy && curl -i http://google.com"
```
使用
```
▶ setproxy
HTTP/1.1 301 Moved Permanently
Content-Length: 219
Date: Thu, 11 Oct 2018 01:58:28 GMT
Expires: Sat, 10 Nov 2018 01:58:28 GMT
Cache-Control: public
Location: http://www.google.com/
Content-Type: text/html; charset=UTF-8
Server: gws
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Age: 171
Connection: keep-alive
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>
~
▶ unsetproxy
^C
```