当尝试使用 curl 绕过错误配置的 DNS 条目(实验中且当时未知)时,--resolve
似乎是正确的方法。但是,该参数的行为并不像我预期的那样,并且(成功)出现 404。
编辑系统/etc/hosts
文件以添加正确的条目可以正常工作,因此这似乎是 curl 解析 DNS 的一部分。事实上,将 IP 更改为/etc/hosts
无效内容也比--resolve
arg 和 404 具有优先权。
是否可以通过内置参数强制 curl 解析系统提供的名称的特定 IP?(它是否--resolve
与其他东西结合在一起?)
下面的例子;为了保护有罪者,姓名和地址已被更改。
% curl -L -vv --resolve "foo.example.com:80:10.14.0.1" "https://foo.example.com/path"
* Added foo.example.com:80:10.14.0.1 to DNS cache
* Trying 10.15.0.1
* TCP_NODELAY set
* Connected to foo.example.com (10.15.0.1) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/cert.pem
CApath: none
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (OUT), TLS alert, unknown CA (560):
* SSL certificate problem: unable to get local issuer certificate
* Closing connection 0
curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here: https://curl.haxx.se/docs/sslcerts.html
curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.
答案1
我刚刚发现了答案;--resolve
需要指定正确的端口(可能是多个端口)
此外,*
可用于主机(但不能用于端口!),这简化了论点。手册页对此非常清楚。
% curl -L -vv --resolve "*:80:10.14.0.1" --resolve "*:443:10.14.0.1" "https://foo.example.com/path"
* Added foo.example.com:443:10.14.0.1 to DNS cache
* Trying 10.14.0.1