linux系统的代理设置,socks5与socks5h的区别?

# 设置代理,只在当前终端有效
$ export http_proxy=http://:
或是
$ export http_proxy=socks5://127.0.0.1:1080
$ export HTTPS_PROXY=socks5://127.0.0.1:1080

# 取消代理
$ unset http_proxy
$ unset https_proxy

写入配置文件(如: .bashrc)永久有效

$ vi ~/.bashrc

# 添加如下内容:
# set proxy
function setproxy() {
    export http_proxy=socks5://127.0.0.1:1080
    export HTTPS_PROXY=socks5://127.0.0.1:1080
    export FTP_PROXY=socks5://127.0.0.1:1080
}

# unset proxy
function unsetproxy() {
    unset http_proxy HTTPS_PROXY FTP_PROXY
}

保存退出,执行source ~/.bashrc使得配置立即生效。或是关闭当前终端,重新打开,在终端中输入:

# 设置代理
$ setproxy

# 取消代理
$ unsetproxy

socks5和socks5h的区别

In a proxy string, socks5h:// and socks4a:// mean that the hostname is resolved by the SOCKS server. socks5:// and socks4:// mean that the hostname is resolved locally

socks5(本地解析hostname)

$export HTTPS_PROXY=socks5://127.0.0.1:1080
$curl https://www.baidu.com
curl: (51) SSL: certificate subject name (www.beforeprom.com) does not match target host name 'www.baidu.com'

socks5h(由socks server解析hostname)

$ export HTTPS_PROXY=socks5h://127.0.0.1:1080
$ curl https://www.google.com

....

也就是说socks5适合本地能够解析目标主机域名(比如github.com)但是访问速度慢,来提高下载速度
socks5h用与本地不能解析目标主机域名(比如google),由代理服务器解析目标主机域名

curl通过-x设置代理

curl -x socks5h://127.0.0.1:1080 www.baidu.com

no_proxy设置

局域网内部的线路不要proxy。 

export no_proxy=127.0.0.1,localhost,local,.local,10.10.0.0/16,192.168.60.245/16

另一种取消系统的proxy的方法

# 取消系统环境中的proxy
$ unset `env | grep -iE "tps?_proxy" | cut -d= -f1`
$ env | grep proxy

参考: 

Differentiate socks5h from socks5 and socks4a from socks4 when handling proxy string · Issue #1035 · urllib3/urllib3 · GitHub

In a proxy string, socks5h:// and socks4a:// mean that the hostname is
resolved by the SOCKS server. socks5:// and socks4:// mean that the
hostname is resolved locally. socks4a:// means to use SOCKS4a, which is
an extension of SOCKS4. Let's make urllib3 honor it.

你可能感兴趣的:(linux,linux)