Five ways to override DNS resolution with curl
A very useful article about curl: everything.curl.dev/usingcurl/connections/name.
It comes in handy when your web server is moving to new addresses and you want to verify the new address works with curl without changing DNS yet.
I ran the article through the sieve of personal experience, and here’s the picture.
Option 1: /etc/hosts The most “portable” approach, so it works beyond just curl — but it changes the setting globally, which can cause isolation or user-permission issues.
Option 2: the Host header The classic approach; easy to copy a command from browser history and tweak it. Downside: it breaks certificate validation, so you also have to pass --insecure — which means you can’t verify your SSL setup.
Option 3: --connect-to Handy when you need to override the port in addition to the host: --connect-to host:443:otherhost:8443. You can pass it multiple times for different hosts.
Option 4: --resolve Handy when you need to point a bunch of hosts at a specific address: --resolve '*:443:5.5.5.5'. Also repeatable. You can’t change the port with it.
Option 5: --dns-servers You can use dnsmasq to override specific domains and return the IP you want:
dnsmasq -d -p5333 --address=/example.org/1.2.3.4
curl --dns-servers 127.0.0.1:5333 https://example.org The catch: this requires curl to be built with the c-ares option (a DNS-client library). Rarely available out of the box.
Originally posted on my Telegram channel Ламповый ТехДир.