如何在 Linux 机器上使用 no_proxy - 通配符、前导点

onk*_*ows 14 proxy

no_proxy我对Linux上的环境变量感到困惑。

互联网上有很多说明显示前导点,例如.localdomain.com /sf/answers/1380391281/

export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
Run Code Online (Sandbox Code Playgroud)

这个例子是与使用有关的wget。但我无法确认这是否有效。例如,在 Ubuntu 18.04 上,我删除了前导点以使其正常工作。请注意,例如我使用的是子域wget mysite.localdomain.com

export no_proxy="localhost,127.0.0.1,localaddress,localdomain.com"
Run Code Online (Sandbox Code Playgroud)

当我使用 a 时,curl它将与前导点一起使用。

看来no_proxy配置方式应该取决于工具?curl对于和 来说是不同的wget

no_proxy是否存在适用于所有工具的约定?

我想写出每个完整的域名都会起作用。

Pra*_*obo 6

据我所知,没有标准,因此您需要设置/使用的内容取决于您使用的工具的实现。Curl 将在删除前导点时使用它,而 wget 则不起作用(不删除它)。

请阅读https://about.gitlab.com/blog/2021/01/27/we-need-to-talk-no-proxy/的一些详细分析:

该文章摘录:

然而,如果有一个领先的 . 在 no_proxy 设置中,行为有所不同。例如,curl 和 wget 的行为不同。卷曲总是会剥离前导。并与域后缀匹配。此调用绕过代理:

$ env https_proxy=http://non.existent/ no_proxy=.gitlab.com curl https://gitlab.com
<html><body>You are being <a> href="https://about.gitlab.com/">redirected</a>.</body></html>
Run Code Online (Sandbox Code Playgroud)

但是,wget 不会去除前导 . 并对主机名执行精确的字符串匹配。因此,如果使用顶级域,wget 会尝试使用代理:

$ env https_proxy=http://non.existent/ no_proxy=.gitlab.com wget https://gitlab.com
Resolving non.existent (non.existent)... failed: Name or service not known.
wget: unable to resolve host address 'non.existent' ```
Run Code Online (Sandbox Code Playgroud)