brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: curl --connect-to tests a new server under the real domain name before you switch DNS

Curl
~/tips/tip-curl-connect-to-test-server

curl -I --connect-to example.com::192.168.1.20: https://example.com/

Sends a request for your real domain to another server, keeping the name for TLS.

Moving a site to a new server, I want to check it answers correctly under the real domain before I change DNS. Editing /etc/hosts works, but it is easy to forget to undo. curl can do it for one request.

curl -I --connect-to example.com::192.168.1.20: https://example.com/

--connect-to HOST1:PORT1:HOST2:PORT2 means: for a request meant for HOST1 on PORT1, connect to HOST2 on PORT2 instead. The port fields are left empty here, as in the example in the curl docs, so requests for example.com go to the new IP.

The important part: the curl docs say it does not change the name used for TLS, so SNI and certificate verification still use example.com. You see whether the new server presents a valid certificate for the real name, which is exactly what you want to know before the switch.

There is also --resolve example.com:443:192.168.1.20, which puts a fake DNS answer in curl’s cache for that host and port. For a quick test both work. I find --connect-to clearer, since you can also point a request at a different port.

Caveat: the host name is compared as a plain string with the one in the URL. www.example.com does not match an entry for example.com, so write the exact name you request, or add a second --connect-to for the www version.

Further reading: curl manual: –connect-to, curl manual: –resolve

Going deeper: Run degoog on Unraid as your own search page, compared with SearXNG and 4get

More Curl tips curl --trace-ascii – https://example.com/ Retry-After: 120 curl -fsS --fail-early \ url = "https://example.com/data/latest.json" curl -4 -s -o /dev/null -w '%{remote_ip} %{http_code}\n' https://example.com/ All Curl tips (71) All topics

Link