Using Telnet To Debug Web Servers

Troubleshooting web servers

When a webserver is setup and configured, especially when it will be serving several sites from the same IP being able to craft exact HTTP(S) requests is important to troubleshoot and ensure everything is working as you want it to.

If you notice in the Samba example:

telnet 445
Connected to
Escape character is '^]'.

The connection pauses and this is where commands can be issued to the server you have connected to. In the case of a web server we can issue HTTP requests as they are in plain text.

In order to request the landing page for this website (index.html) we need to do the following.

  1. Establish a connection:
telnet 80

Which then gives the following output:

Connected to
Escape character is '^]'.

Now, we need to supply the following commands:

GET /<file> HTTP/1.1
Host: <hostname>

You will need to replace /<file> with the file you want or just leave / to get the default file (usually index.html/php). The <hostname> is used by the webserver to determine which web site is wanted by matching it, in the case of Apache, with the value set as the SeverName value in the VirtualHost configuration for the site.

After the Host: line ENTER must be pressed on a blank line. The webserver will then end through the HTML.

Doing all of this for give the following:

telnet 80
Connected to
Escape character is '^]'.
GET / HTTP/1.1

HTTP/1.1 301 Moved Permanently
Date: Sun, 31 Dec 2017 10:26:42 GMT
Server: Apache/2.4.25 (Debian)
Content-Length: 323
Content-Type: text/html; charset=iso-8859-1

<title>301 Moved Permanently</title>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="">here</a>.</p>
<address>Apache/2.4.25 (Debian) Server at Port 80</address>

telnet> quit

As you can see, there is a permanent redirect from to Normally, you would not see this page as the browser would immediately load the https:// site without displaying all this useful information.

Using telnet like this allows us to connect directly to the IP of the server and request any site that the webserver is configured for and specific file whilst also getting the web server’s output.

This is invaluable information when it is compared with the web server log file to see exactly what is happening with page requests when there is a problem.