curl and resolving without modifying hosts file
1 min readMar 11, 2019
a quote from curl man page:
--resolve <host:port:address[,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.By specifying '*' as host you can tell curl to resolve any host and specific port pair to the specified address. Wildcard is resolved last so any --resolve with a specific host and port will be used first.
We can test the site availability or SSL status without adding record into /etc/hosts
with curl resolve parameter.
Example:
$ curl -v --resolve mydomain.com:443:1.2.3.4 https://mydomain.com* Added mydomain.com:443:1.2.3.4 to DNS cache
* Rebuilt URL to: https://mydomain.com/
* Hostname mydomain.com was found in DNS cache
* Trying 1.2.3.4...
As you can see above, curl resolves mydomain.com:443
request as 1.2.3.4
IP address. This is quite useful while testing HTTPS with Server Name Indication (SNI) support.
Ismail YENIGUL
Devops Engineer