Testing ports using Telnet
Email connections not working? Website seems offline from a certain location? Forgot your customized SSH port? There's many reasons you may want to test a connection to a specific port on a server to see if it is open, and (the best way) to do that is with Telnet.
What is Telnet, exactly?
Telnet originally stood for "teletype network" and provided a text-based command line interface to connect to remote systems. More powerful than FTP, Telnet allowed you to issue commands to remote systems to perform system administration tasks. While most users now perform this work over an SSH connection, Telnet still has useful functions and can be a great troubleshooting tool. Telnet is most often used to test basic connectivity to a certain port or service on a remote system.
In order to follow along with this guide you'll want to make sure you have telnet installed on your system. Every major operating can use telnet, but you may need to enable or install it on your machine before it is available for use. The following details explain how to get Telnet working on your Mac or Windows system.
-In Mac OS X 10.13 (High Sierra):
1. Install Homebrew using a Terminal session, entering this command:
2. Install the Telnet client using homebrew:Code:/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Code:brew install telnet
In Windows 10:
1. Click the Start button and type "control" to bring up the Control Panel menu. Open that menu.
2. Click Programs
3. Click "Turn Windows Features on or off"
4. Click the check box next to "Telnet Client" in the list of available software and click the Okay button. This will install the software for you.
Most Linux distributions will have Telnet installed by default. If not, check with your distribution for the best way to install the Telnet service.
Testing ports with Telnet
Now that telnet is installed and available for use, let's use it to test a connection. Here's a common scenario a lot of server admins face - a client isn't able to send email. Using Telnet, we can test the connectivity from their local workstation to the cPanel email server to see if they can connect to port 25, the default port for sending email. The client having difficulty with email would need to run this test from their Windows workstation:
1. Click the Start button
2. Type the word "command" to bring up the Command Prompt program. Click, or press enter, to open that program.
3. On the command line that appears, type telnet mx1.cpanel.net 25 and then observe the output.
(mx1.cpanel.net is the cPanel mail server so we are using that for our connection test, but an IP address would work just as well in telnet commands)
Here is what the screenshot of that Telnet test will look like from the Windows system that can't connect properly:
You can see from that reply the user was not able to reach port 25, which is likely why their email is not working.
Just to double-check things with that email system, you decide to test this from your local Mac OS X workstation to confirm things are working properly when connecting from a different network. To perform the test on the Mac you would:
1. Click the Spotlight Search magnifying glass icon in the top right of the screen
2. Type "Terminal" in the search box that appears, and press the Enter key to open the Terminal command window.
3. Type telnet mx1.cpanel.net 25 into the command prompt and press Enter to execute the command.
We can see the Mac system was able to reach the cPanel email network over port 25. The problem in this case must be port 25 being blocked at the remote user's local machine or local network.
We can use telnet to check other services as well. To confirm that Apache is running on port 80 you could run the command telnet yourdomain.com 80 as in the example below:
You could also confirm a system is using the default port of 22 for their SSH service by changing the port in your command.
In order for Telnet to connect to a port a service has to be listening on the remote server on the port you specify. This means that you can't rely on telnet to confirm if ports or open in the server's firewall. One example of this is the passive FTP port range on a system. On cPanel systems the passive FTP port range defaults to ports 49152 through 65534, but even though those ports are open in the server's firewall a telnet test to them will fail since nothing is actively listening on those ports - they are just open for use by the FTP service when it needs to use them.
For more information on Telnet you could check the man pages here or run man telnet from your local command line. If you need more details on open ports on your server this forum post has more detail on that.
I hope this guide will help you use Telnet to make your server administration tasks easier!
Written by @cPRex
Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!