如何让curl使用指定的ip而不是在/ etc / hosts中设置它?

时间:2016-09-01 07:26:45

标签: linux curl

您好我正在尝试使用curl向指定的IP地址发送请求,因为如果我在/etc/hosts中设置它,它就不会立即起作用。那么在curl命令中有没有办法做到这一点?感谢。

1 个答案:

答案 0 :(得分:3)

是肯定的。 一个例子显示在卷曲作者丹尼尔的全新书中。

http://ec.haxx.se/usingcurl-connections.html =>为名称提供自定义IP

您还可以查看联机帮助页

https://curl.haxx.se/docs/manpage.html

--resolve <host:port:address>

Provide a custom address for a specific host and port pair. Using this, you can make the curl requests(s) use a specified address and prevent the otherwise normally resolved address to be used. Consider it a sort of /etc/hosts alternative provided on the command line. The port number should be the number used for the specific protocol the host will be used for. It means you need several entries if you want to provide address for the same host but different ports.

The provided address set by this option will be used even if -4, --ipv4 or -6, --ipv6 is set to make curl use another IP version.

This option can be used many times to add many host names to resolve.

(Added in 7.21.3)