Resolve Host to IP with cURL
Debug virtual hosts without changing DNS.
Suppose you have a website distributed across multiple servers using load balancing. To verify its functionality, you might execute a command like curl example.com
. However, to individually assess each server by its IP address, you would need to manually input the IP addresses.
host=<host>; ip=<ip>; port=<port>; \
curl -svk --resolve $host:$port:$ip \
--location "https://$host:$port/" \
--header "Host: $host"
For example, the following command will fetch index
from example.com
on 198.51.100.15
.
host=example.com; ip=198.51.100.15; port=443; \
curl -svk --resolve $host:$port:$ip \
--location "https://$host:$port/" \
--header "Host: $host"
Connect-To
In version 7.49.0
cURL also introduced connect-to
.
host=example.com; ip=198.51.100.15; port=443; \
curl -svk --connect-to $host:$port:$ip:$port \
--location "https://$host:$port/" \
--header "Host: $host"