The beauty of Telnet is that it’s available for almost any operating system, and it’s installed by default on many. While the use of insecure Telnet for network communication eventually gave way to encrypted protocols, like SSH, its usefulness lives on. Telnet is the perfect tool for testing TCP port connectivity. Let’s walk through how to use Telnet for TCP connection testing, as taught in Linux Networking and Troubleshooting.
Perhaps you’ve just finished building an environment in AWS, and you’re getting ready to migrate some on-premises web content to something more scalable. You’ve configured your VPC, added the security groups, and instantiated the EC2 instances. How can you verify your ingress rules are set appropriately for the workload you plan to move to the EC2 instances?
For services listening on TCP ports, it’s simple – just use Telnet! Here’s an example.
Check HTTP Connectivity
Let’s say you want to check HTTP connectivity to www.example.com, you’d use:
telnet www.example.com 80
And what you’d be looking for is this:
Connected to example.com. Escape character is '^]'
This tells you when the connection was able to be made successfully. At this point, you’ll usually hit
CTRL+C and type “
quit” to exit Telnet, but you could also use Telnet to request some data.
Pull HTTP Headers
Let’s say you want to pull the HTTP headers of www.example.com, instead of quitting, you’d type:
HEAD / HTTP/1.1 Host: www.example.com
Not only will you be able to verify that port 80 was open and permitting communication, but you’ll also be able to perform some validation against the service itself. The use case can be extended to pull the web page’s HTML as well using something like:
GET /index.html HTTP/1.1
This, of course, assumes
index.html exists at the root level of the site, and that 1.1 is the right HTTP host header specification.
These are just a few examples of what Telnet can help with. For even more flexibility, including the ability to listen on TCP and UDP ports, you should check out netcat! Get a deeper dive of all this and more in the latest hands-on training course: Linux Networking and Troubleshooting.