49

The --help output for curl lists a --resolve option, which states

--resolve <host:port:address> Force resolve of HOST:PORT to ADDRESS

I'm not having any luck getting it to work though. The basic command I'm trying to run is

curl --resolve foo.example.com:443:localhost https://foo.example.com:443/

and I keep getting the response Couldn't resolve host 'foo.example.com'. I want do do this because I'm testing a certificate for foo.example.com, but I'm not testing it on the actual server. Instead, I'm testing it on a dummy machine. I know that I can edit /etc/hosts so that foo.example.com resolves to localhost, but this curl approach seems like it would be the "correct" way to go, if I could make it work.

Does anybody see what I'm doing wrong here?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
tsuraan
  • 593
  • 1
  • 4
  • 5

3 Answers3

78

It appears that the address needs to be a numeric IP address, not a hostname.

Try this:

curl --resolve foo.example.com:443:127.0.0.1 https://foo.example.com:443/
Keith Thompson
  • 21,782
  • 6
  • 48
  • 55
7

Some additional help in troubleshooting:

Ensure you're listing the right port for the protocol: http=80; https=443 & etc.

Also curl -v will give the HEADER information for the response server which can be helpful.

$ curl -v --resolve foo.example.com:443:127.0.0.1 https://foo.example.com:443/
## The client request headers prepended by >
> OPTIONS /v1/..
> HOSTS foo.example.com
## The server response prepended by <
< HTTP/1.1 501 Not Implemented
## The html returned
<H1>Unsupported Request</H1>

Basically in this case the OPTIONS HTTP method was not implemented at the edge server for the CDN.

slm
  • 363,520
  • 117
  • 767
  • 871
Manchego
  • 187
  • 1
  • 1
-1

I have the same problem. Very strange, but it seems like it depends on the version. I checked one server with curl --manual | grep resolve for version 7.19.7 and the --resolve parameter is missing. In version 7.29.0, I have this parameter, and resolving is working fine.

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250