I am attempting to use curl's --resolve option to connect to the specified IP address when performing the HTTP request, but curl keeps reverting back to the IP address as retrieved by my local DNS cache/resolver.


curl -s -S -I -H "Host: example.com" --resolve example.com:80: --verbose http://example.com/

(where example.com is replaced by my domain name, and replaced by the desired destination IP address)


* Added example.com:80: to DNS cache
* Hostname was NOT found in DNS cache
*   Trying
* Connected to example.com ( port 80 (#0)
> HEAD / HTTP/1.1
> User-Agent: curl/7.35.0
> Accept: */*
> Host: example.com

(where is replaced by the IP address cached in my local DNS resolver for my domain name)

So, it looks like curl attempts to add to the DNS cache for example.com, but fails somehow and reverts back to original IP address.

Any ideas on how to fix this problem or troubleshoot further to find out why its not working?


After trying this with other domain names, I found that the issue was being caused by the domain names not matching in the --resolve option and the URL (one had www, the other didn't). User error!


curl -s -S -I -H "Host: example.com" --resolve example.com:80: --verbose http://www.example.com/


curl -s -S -I -H "Host: example.com" --resolve example.com:80: --verbose http://example.com/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.