Systems, Tools, and Terminal Science

Main menu

Post navigation

Testing HTTP/1.1 responses

Before changing DNS A records for a website, it’s prudent to check that the
webserver with the IP address to which you’re going to change the records will
actually serve a website with the relevant hostname; that is, if it’s an Apache
HTTPD webserver, that it has a valid VirtualHost definition for the site.

If you don’t actually have administrative access to the webserver to check
this, there are many basic ways to test it; from the command line, three of the
most useful include using curl, wget, or plain old telnet. For each, the
method comprises manipulating the HTTP/1.1 request of the target webserver
such that the website you want to test is used as the hostname in the Host
header.

Using curl

Perhaps the quickest and tidiest way to check this from a Unix command line is
using curl, the binary frontend to the libcurl library. You do this by
making an HTTP/1.1 request of the target server’s IP address, while including
an explicitly specified value for the Host. This is done using the -H
option:

$ curl -H "Host: blog.sanctum.geek.nz" 69.163.229.57

This spits out quite a lot of information, including some on stderr, so you
may choose to filter it and just check for the <title> tag, with a little bit
of context, to make sure the site you expected really is being returned as the
appropriate response:

Using wget

An equivalent to the curl method can be achieved using the --header option
for the commonly available wget:

$ wget --header="Host: blog.sanctum.geek.nz" 69.163.229.57 -q -O -

Using telnet

If you don’t have curl available, Telnet works just as well on both Windows
and Unix-like systems, though it’s a little more awkward to work with, as you
have to type the request and its headers straight into the TCP session:

Note that you need to press Enter twice after writing in the hostname
to check to complete the HTTP request. If this spits the HTML of your expected
page back at you and closes the connection, then you’ve got some indication
that things are configured correctly.

Yet another option to test this, particularly if you want to actually view the
site in a browser, is to change your system’s hosts file to force DNS
resolution to be different for the appropriate hostname on your local system.

Thanks to commenter Jaime Herazo for suggesting the wget method in the
comments, and commenter sam for suggesting the -C option for grep.

6 thoughts on “Testing HTTP/1.1 responses”

I’ll offer another option: If your computer doesn’t already use an HTTP proxy, set your HTTP proxy to the IP address of the new web server, and port to 80. Then ALL requests will go to that server, and you can test sites that haven’t had their DNS redirected yet.

Remember to turn it off, as to not see “Host not configured” errors when going to google.com or any other site!