curl: Modify DNS Resolution


You can intercept normal name resolution in curl with the --resolve parameter allowing you to do things like talk to a specific site of a DNS load-balanced setup or talk to a new deployment not yet made productive.

You can specify the resolve option multiple times so you can even catch redirects and move them to where you want as well.

It’s important to note that this intercept does only work on the ports you specify in the entries.

curl http://example.org --resolve example.org:80:203.0.113.2 --resolve example.org:443:203.0.113.2

Combining with config

You can combine this with the -K or --config parameter to build multiple presets to call different sites of your service on demand.

$ cat service-site-a.curl.conf
--resolve api.example.org:443:203.0.113.2
--resolve app.example.org:443:203.0.113.3

$ cat service-site-b.curl.conf
--resolve api.example.org:443:203.0.113.102
--resolve app.example.org:443:203.0.113.103

# Force yourself to site A
$ curl api.example.org -K service-site-a.curl.conf

# Force yourself to site B
$ curl api.example.org -K service-site-b.curl.conf

Combining with inline resolution

You can combine this with inline resolution, using something like dig, to go to a specific application instance inside your cluster.

# Talk to the app-host01 directly
curl https://app.example.org  --resolve app.example.org:443:$(dig +short app-host01.internal.example.org)

# Talk to the app-host04 directly
curl https://app.example.org  --resolve app.example.org:443:$(dig +short app-host04.internal.example.org)

See also