Force DNS resolving in cURL with the --resolve switch

It’s possible to force DNS resolving in cURL using the --resolve switch.

The --resolve switch allows you to tell curl which address to request when it would resolve a given hostname.

The format of the argument is domain:port:ip

# HTTPS Example
curl -I -L https://domain.example.org/ \
  --resolve domain.example.org:443:192.168.0.1

# HTTP Example
curl -I -L http://domain.example.org/ \
  --resolve domain.example.org:80:192.168.0.1

Handy for testing a new server or load balancer you’ve prepared, or when wanting to bypass Cloudflare Proxying without touching Cloudflare’s settings.

~

Did this help you out? Like what you see?
Thank me with a coffee.

I don\'t do this for profit but a small one-time donation would surely put a smile on my face. Thanks!

BuymeaCoffee (€3)

To stay in the loop you can follow @bramus or follow @bramusblog on Twitter.

Published by Bramus!

Bramus is a frontend web developer from Belgium, working as a Chrome Developer Relations Engineer at Google. From the moment he discovered view-source at the age of 14 (way back in 1997), he fell in love with the web and has been tinkering with it ever since (more …)

Unless noted otherwise, the contents of this post are licensed under the Creative Commons Attribution 4.0 License and code samples are licensed under the MIT License

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.