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 samba.example.com 445 Trying 172.31.25.31... Connected to samba.example.com. 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.
- Establish a connection:
telnet bash-prompt.net 80
Which then gives the following output:
Trying 184.108.40.206... Connected to bash-prompt.net. 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.
Host: line ENTER must be pressed on a blank line. The webserver will then end through the HTML.
Doing all of this for http://bash-prompt.net give the following:
telnet bash-prompt.net 80 Trying 220.127.116.11... Connected to bash-prompt.net. Escape character is '^]'. GET / HTTP/1.1 Host: bash-prompt.net HTTP/1.1 301 Moved Permanently Date: Sun, 31 Dec 2017 10:26:42 GMT Server: Apache/2.4.25 (Debian) Location: https://bash-prompt.net/index.html Content-Length: 323 Content-Type: text/html; charset=iso-8859-1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>301 Moved Permanently</title> </head><body> <h1>Moved Permanently</h1> <p>The document has moved <a href="https://bash-prompt.net/index.html">here</a>.</p> <hr> <address>Apache/2.4.25 (Debian) Server at bash-prompt.net Port 80</address> </body></html> ^] telnet> quit
As you can see, there is a permanent redirect from http://bash-prompt.net to https://bash-prompt.net. Normally, you would not see this page as the browser would immediately load the
https:// site without displaying all this useful information.
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.