Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify the IP address on curl?

My server has 5 different external IPs (all working)

I added them by using:

 ip addr add xx.xx.xx.xx/32 dev eth0
 ip addr add yy.yy.yy.yy/32 dev eth0
 ip addr add zz.zz.zz.zz/32 dev eth0

How can I should curl to use either zz.zz.zz.zz IP address ?

like image 393
yarek Avatar asked Apr 13 '17 18:04

yarek


People also ask

Can you curl to an IP address?

...will force cURL to use "127.0. 0.1" as the IP address when requesting "www.example.com" over port 80 (HTTP). ...which will force cURL to use "127.0. 0.1" as the IP address for requests to "www.example.com" over ports 80 (HTTP and 443 (HTTPS).

How do I use an IP address instead of a URL?

To use an IP address instead of a domain name, simply enter the IP address in the URL in place of the domain name. For example, the URL http://192.168.1.1/index.html would take you to the same page as http://www.pcwebopedia.com/index.html.

How does curl resolve host name?

If no connection can be reused, libcurl resolves the host name to the set of addresses it resolves to. Typically this means asking for both IPv4 and IPv6 addresses and there may be a whole set of those returned to libcurl. That set of addresses is then tried until one works, or it returns failure.


1 Answers

You should be able to use

curl --interface zz.zz.zz.zz http://example.com/
like image 133
faffaffaff Avatar answered Oct 20 '22 06:10

faffaffaff