cURL to an IP address With a Hostname

I recently modified this website to be accessible via IPv6 so I needed to test that Apache would respond with the site when accessed over IPv6.

cURL allows access to an IP address of a server and supply a hostname, bash-prompt.net. This means that cURL will initiate the HTTPS connection to the IP address and then reply with the correct website when it receives the hostname.

The cURL command to do this is as follows:

 curl --silent --verbose --resolve <host>:<port>:<IP> <URL>

The IPv6 hostname must be wrapped in square brackets e.g. [2a01:4ff:f0:e625::1].

This is the command for connecting to this website over IPv6 with the start of the output:

$ curl --silent --verbose --resolve bash-prompt.net:443:[2a01:4ff:f0:e625::1] https://bash-prompt.net
* Added bash-prompt.net:443:[2a01:4ff:f0:e625::1] to DNS cache
* Hostname bash-prompt.net was found in DNS cache
*   Trying [2a01:4ff:f0:e625::1]:443...

The Apache log entry also confirms that the connection was successful:

2402:800:629c:dbf3:fcbe:e4eb:1ab4:b573 - - [13/Apr/2025:08:53:49 +0000] "GET / HTTP/2.0" 200 5569 "-" "curl/8.13.0"