Categories
Uncategorized

Overriding DNS in curl

Often I’ll run into a situation where I need to make an HTTP request for a host name against a server that is at a different IP address than the one the host name resolves to. A common reason for this is to test out changes against a sandbox before deploying the change to production.

One way to deal with this in curl is with the --resolve option. Here is a simple example:

curl – resolve google.com:443:172.217.1.206 https://www.google.com/

Internally curl will make sure that google.com resolves to 172.217.1.206 for the purposes of that request. No need to mess around with hosts files or anything else.

For more suggestions in this area check out curl another host.