Operations 4 min read

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.

Programmer DD
Programmer DD
Programmer DD
How to Test Any Domain with curl’s --resolve Without Editing Hosts

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.1

You 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.1
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

HTTPcommand-lineDNScURLHTTPSnetwork testing
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.