Linux Setting Terminal Proxy

臨時設定

Terminal

export ALL_PROXY=socks5://127.0.0.1:<port>
export HTTP_PROXY=http://127.0.0.1:<port>
curl ip.gs

高級設定

Script

Write the following code in ~.bash_profile

# 設定終端代理
function setProxy() { 
    export ALL_PROXY="socks5://127.0.0.1:${1}" 
} 

# 取消終端代理 
function unsetProxy() { 
    unset ALL_PROXY 
} 

# 測試終端代理
function testProxy() { 
    curl -i 'http://ip.cn' 
}

我們執行如下指令使~.bash_profile剛才的配置生效

source ~.bash_profile

使用

而後,我們就可以在terminal中可以使用上述函數來設定、取消、測試功能。

setProxy # 設定終端代理
unsetProxy # 取消終端代理
testProxy # 測試終端代理