當嘗試使用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