0%

CMD、Powershell、Bash终端配置走代理

CMD

1
2
3
4
5
6
;; 设置代理(其中sock5可以设置为http,https)
set http_proxy="sock5://127.0.0.1:1080"
set https_proxy="sock5://127.0.0.1:1080"
;; 清除代理设置
set http_proxy=
set https_proxy=

Powershell

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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 = 'sock5://127.0.0.1:1080'

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')
}

Bash

1
2
3
export ALL_PROXY="socks5://127.0.0.1:1080"
export http_proxy="http://127.0.0.1:1080"
export https_proxy="http://127.0.0.1:1080"

注意:

如果代理服务器需要登陆,这时可以直接把用户名和密码写进去

1
http_proxy=http://userName:password@proxyAddress:port

欢迎关注我的其它发布渠道