Curl host with different hostname

Sometimes it is convenient to set a dns hostname so you can for example test your reverse proxy without having to set a dns record.


The below command will request an answer from the server listening on 127.0.0.1:80:

curl --header "Host: yourdomain.com" http://127.0.0.1/

Be aware that the above command will overwrite the Host header for the request even redirects. If you want to use it with ssl you need to add -k to skip the certificate validity check.

If you want to spoof the DNS and also check the certificate validity you can use the curl --resolve parameter.

curl --resolve "yourdomain.com:443:127.0.0.1" https://yourdomain.com/optionallocation/

The --resolve parameter will spoof a dns lookup.