讓Linux終端流量走socks5代理
把代理服務器地址寫入shell配置文件.bashrc
或者.zshrc
直接在.bashrc
或者.zshrc
添加下面內容
1 2 |
export http_proxy="http://localhost:port" export https_proxy="http://localhost:port" |
以使用shadowsocks代理爲例,ss的代理端口爲1080
,那麼應該設置爲
1 2 |
export http_proxy="socks5://127.0.0.1:1080" export https_proxy="socks5://127.0.0.1:1080" |
或者直接設置ALL_PROXY
1 |
export ALL_PROXY=socks5://127.0.0.1:1080 |
localhost
就是一個域名,域名默認指向 127.0.0.1
,兩者是一樣的。
然後ESC
後:wq
保存文件,接着在終端中執行source ~/.bashrc
或者退出當前終端再起一個終端。 這個辦法的好處是把代理服務器永久保存了,下次就可以直接用了。
或者通過設置alias簡寫來簡化操作,每次要用的時候輸入setproxy
,不用了就unsetproxy
。
1 2 3 |
alias setproxy="export ALL_PROXY=socks5://127.0.0.1:1080" alias unsetproxy="unset ALL_PROXY" alias ip="curl -i http://ip.cn" |