Domain-Name-System
curl 將提供的用於解析 arg(或其他)的 IP 優先於其他 DNS 選項
當嘗試使用 curl 繞過配置錯誤的 DNS 條目時(正在試驗,當時還不知道),
--resolve
似乎是正確的方法。然而,這個論點並沒有像我預期的那樣(成功地)404。編輯系統
/etc/hosts
文件以添加正確的條目可以正常工作,因此它似乎必須是 curl 解析 DNS 的一部分。實際上,將 IP 更改為/etc/hosts
無效的 IP 也優先於--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.
我剛剛發現了答案;
--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