How to Use Telnet to Test HTTP and HTTPS Service


Consider these conditions:

  • You've deployed a new Linux server.
  • The server shall have HTTP/S service running.
  • It must also have firewall installed.
  • It's accessible via SSH only.

Most of the time, the installation process should be pretty straight forward. But there's some occasions which need extra attention. In my case, the VPS provider uses a hardware based firewall, which by default blocks all incoming and outgoing connections by default. Each system administrator must request the provider to open a specific port.

Because I want to run a web server, I asked the provider to open port 80 and 443 for me. After they replied that my request we're executed, I tested by opening a web browser and going to my server's URL.

Strangely enough, my web browser just keeps on loading until timeout. I double checked my server's log and configuration files and I found nothing suspicious. This leads me to suspect the issue is on their firewall.

Before sending another email, I must gather some evidence. I must know that the web server is running fine and waiting for connection.

Testing HTTP Service

Because we have SSH access to the server, we can utilize it. To test HTTP service, we need help from a software called telnet. It should be installed by default on many distributions.

First, we need to make sure telnet is installed. On your terminal, type this command:

$ which telnet

If the system responds with /usr/bin/telnet, then you're good to go. Otherwise, you need to install it first.

Next, enter this command to your terminal:

$ telnet localhost 80

Above command will run telnet to connect with localhost on port 80. If you run your HTTP server on different port, adjust accordingly.

If your system responds with:

$ telnet localhost 80
telnet: Unable to connect to remote host: Connection refused

It means that your web server is not running yet. Make sure it's running first.

Otherwise, if your web server is already running, the system should respond with:

$ telnet localhost 80
Connected to localhost.
Escape character is '^]'.

After we make sure that our web server is running, now let's send a HTTP request to simulate a web browser.

Under this line "Escape character is '^]'.", enter these commands:

GET / HTTP/1.1
host: localhost

Press Enter twice to send the request. If your web server runs correctly, it should respond with something similar like below:

HTTP/1.1 200 OK
Server: nginx/1.18.0 (Ubuntu)
Date: Thu, 29 Apr 2021 21:51:33 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 21 Apr 2020 14:09:01 GMT
Connection: keep-alive
ETag: "5e9efe7d-264"
Accept-Ranges: bytes

<!DOCTYPE html>
<title>Welcome to nginx!</title>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href=""></a>.<br/>
Commercial support is available at
<a href=""></a>.</p>

<p><em>Thank you for using nginx.</em></p>
Connection closed by foreign host.

If you have a similar response, that's good. It means that our web server runs correctly.

Testing HTTPS Service

Now that I have evidence that my web server is running correctly, I need to find another evidence for HTTPS service. To test a HTTPS service we need help from another program called openssl. Similar to telnet, this program should be already installed, otherwise you might need to install it on your own.

Back to our terminal, enter this command:

openssl s_client -connect

Note: We must use a valid TLD here.

After pressing Enter, you should see SSL certificate details scroll by. When the scrolling is done, enter these commands:

GET / HTTP/1.1

Similar to telnet command, we must press Enter twice. If your web server runs correctly, it should respond with something similar like the response from the telnet program with extra SSL details.

Final Words

I hope that you now know how to use telnet to test HTTP and HTTPS service. If you run into any issues or have any feedback feel free to drop a comment below.

Tags Linux

0 comment

Leave a reply

Your email address will not be published. Required fields are marked *