Terminal 使用网络代理

904 阅读1分钟

windows

cmd


rem 环境:shadowsocks、windows
rem 本地ss端口设置(这里1080)

rem cmd命令行:(不用socks5)(临时设置)(也可放置环境变量)
set http_proxy=http://127.0.0.1:1080
set https_proxy=http://127.0.0.1:1080

rem 恢复
set http_proxy=
set https_proxy=

rem 需要登录的
set http_proxy_user=user
set http_proxy_pass=pass

set https_proxy_user=user
set https_proxy_pass=pass

PowerShell

# ps:一定要用cmd命令行,千万别用powershell !!!
# 简易测试命令:curl https://www.google.com(别用ping)

# PowerShell 的:
$env:http_proxy="http://127.0.0.1:1080"
$env:https_proxy="http://127.0.0.1:1080"

################

# NOTE: registry keys for IE 8, may vary for other versions
$regPath = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings'

function Clear-Proxy
{
    Set-ItemProperty -Path $regPath -Name ProxyEnable -Value 0
    Set-ItemProperty -Path $regPath -Name ProxyServer -Value ''
    Set-ItemProperty -Path $regPath -Name ProxyOverride -Value ''

    [Environment]::SetEnvironmentVariable('http_proxy', $null, 'User')
    [Environment]::SetEnvironmentVariable('https_proxy', $null, 'User')
}

function Set-Proxy
{
    $proxy = 'http://example.com'

    Set-ItemProperty -Path $regPath -Name ProxyEnable -Value 1
    Set-ItemProperty -Path $regPath -Name ProxyServer -Value $proxy
    Set-ItemProperty -Path $regPath -Name ProxyOverride -Value '<local>'

    [Environment]::SetEnvironmentVariable('http_proxy', $proxy, 'User')
    [Environment]::SetEnvironmentVariable('https_proxy', $proxy, 'User')
}

Linux OR GitBash

# http
export http_proxy="http://localhost:port"
export http_proxy='http://127.0.0.1:1080'

# https
export https_proxy="http://localhost:port"
export https_proxy='http://127.0.0.1:1080'

# socks5
## socks 与 socks5
export http_proxy='socks://localhost:port'
export http_proxy='socks5://localhost:port'

export http_proxy="socks5://127.0.0.1:1080"
export https_proxy="socks5://127.0.0.1:1080"

# 为了方便可以设置 Terminal 全局代理
export ALL_PROXY='socks5://127.0.0.1:1080'
# or
export ALL_PROXY='http://127.0.0.1:1080'


## 设置别名 setproxy,unsetproxy
alias setproxy="export ALL_PROXY=socks5://127.0.0.1:1080" 
alias unsetproxy="unset ALL_PROXY"

git

git config --global http.proxy 'socks5://127.0.0.1:1080' 
git config --global https.proxy 'socks5://127.0.0.1:1080'