When you're testing a website and the DNS records are not yet pointed to the server, cURL can be a helpful tool for diagnosing issues. With cURL, you can test website responses by manually specifying the host without relying on DNS. This article explains how to use the --resolve
flag and the -H
header modification flag for testing.
Prerequisites
- SSH access to the server
- Basic understanding of SSH commands and cURL options
- Server IP address and domain name
Procedure: Using the -H
Flag to Modify the Host Header
With the -H
flag, you can modify the Host header in cURL, allowing you to test the response of a specific domain before DNS is configured:
curl -IL -H"Host: example_domain.TLD" http://IP.ADDRESS.OF.SERVER/path-to-file.php
This command uses the following options:
-I
: Print header information instead of rendered content-L
: Follow redirects-H
: Specify custom header; in this case, the Host header. Apache uses this header to determine which VirtualHost to serve.http://
: Specify the protocol (as SSL certificates are usually not available before DNS is configured)IP.ADDRESS.OF.SERVER
: Replace with the server's IP address/path-to-file.php
: Optionally, specify the path to a file for testing
Procedure: Using the --resolve
Flag for Complex Redirects
If your application handles redirects to subdomains or forces HTTPS, using the --resolve
flag is ideal. This command allows you to override DNS resolution:
curl -IL --insecure \
--resolve domain.tld:80:SERVER-IP \
--resolve domain.tld:443:SERVER-IP \
--resolve www.domain.tld:80:SERVER-IP \
--resolve www.domain.tld:443:SERVER-IP \
http://domain.tld/path-to-file.php
This command uses the following options:
-I
: Print header information instead of rendered content-L
: Follow redirects--insecure
: Ignore SSL warnings, which is useful if an SSL certificate is not yet installed--resolve
: Override DNS resolution using the formatdomain.tld:port:IP
for both HTTP and HTTPS ports (80 and 443)