How to Test Any Domain with curl’s --resolve Without Editing Hosts
This guide shows how to use curl's --resolve option to force a specific IP address for a domain during HTTP or HTTPS requests, avoiding hosts file changes, DNS cache flushing, and the need to edit system configurations.
We often encounter situations where a service changes its IP, is deployed on multiple servers, or uses a CDN, and we need to test a specific IP without affecting users.
For example, accessing http://fuckcloudnative.io with a custom IP 1.1.1.1 .
The obvious solution is to edit the hosts file: 1.1.1.1 fuckcloudnative.io This works but requires flushing the DNS cache and remembering to remove the entry later.
Using curl, we can specify the Host header directly, but that fails with HTTPS.
curl provides the --resolve option, which lets you bind a host:port pair to a custom address, working for both HTTP and HTTPS.
--resolve <host:port:address[,address]...>
Provide a custom address for a specific host and port pair.
Using this, you can make the curl request use the specified address
and prevent the normally resolved address from being used.Examples:
$ curl http://fuckcloudnative.io/ --resolve fuckcloudnative.io:80:1.1.1.1
$ curl https://fuckcloudnative.io/ --resolve fuckcloudnative.io:443:1.1.1.1You can also use a wildcard to apply the IP to all hosts on a given port:
$ curl https://fuckcloudnative.io/ --resolve *:443:1.1.1.1Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Programmer DD
A tinkering programmer and author of "Spring Cloud Microservices in Action"
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
