12

There is a --resolve option in the curl utility that allows you to add a DNS entry and force a certain IP address when calling a host.

Since version 7.21.3 cURL allows specifying an IP address, thus forging the hostname for the request.

$ curl --resolve www.example.com:80:127.0.0.1 http://www.example.com/

The --resolve switch allows you to tell curl which address to request when it would resolve a given hostname. In the above snippet cURL uses 127.0.0.1 (localhost) instead of resolving www.example.com via DNS.

This option works correctly when used without an http proxy, the DNS entry is found in cache.

The problem is I would like to use this option simultaneously with the curl --proxy parameter. When this last parameter is set, the DNS entry is not found when calling the same host.

$ curl --proxy 1.2.3.4:80 --resolve www.example.com:80:127.0.0.1 http://www.example.com/

Any idea how to get around this problem?

I have an idea that the proxy is using its own DNS cache and we can't change it but maybe I'm wrong ?

not2qubit
  • 14,531
  • 8
  • 95
  • 135
YoyoS
  • 639
  • 1
  • 7
  • 19
  • 2
    Why not simply use $ curl --proxy 1.2.3.4:80 127.0.0.1 – T33C Jun 28 '16 at 20:52
  • 11
    There's no way to try to do both of those things in one curl command. Whatever HTTP proxy you're using has to do its own DNS resolution for the host. It has no way of knowing that you've specified "--resolve" in your command. You need to fiddle with the DNS for the proxy you're using. – mrcheshire Jun 28 '16 at 20:52
  • 1
    That's what I thought. Only way is to call 127.0.0.1 trought proxy and set the http Host header it seems. Thanks – YoyoS Jun 29 '16 at 07:33

1 Answers1

0

In case you have access to it you could also modify /etc/hosts in the proxy server.