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

本文介绍了如何在终端中设置和取消HTTP及HTTPS代理,特别是使用Socks5协议的代理。区别了socks5和socks5h在域名解析上的差异,socks5适用于本地能解析目标主机但速度慢的情况,而socks5h则用于本地无法解析目标主机时,由代理服务器进行解析。此外,还提到了curl命令通过代理访问网页的用法以及no_proxy环境变量的设置,用于排除不需要通过代理的局域网内部地址。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

# 设置代理,只在当前终端有效
$ export http_proxy=http://<IP>:<PORT>
或是
$ 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
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en"><head><meta content="Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for." name="description">
....

也就是说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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

路边闲人2

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值