Ping ports from the command line using Telnet
Sometimes you may want to ping an IP and a specific port or ping ports. If you are looking to Ping IPs and not ports. See our fping guide. This is useful for a number of reasons one being if you are trying to resolve a connection timed out error on your cPanel VPS Server when sending Email or when a connection is blocked like SSH. For example, Exim or your mail program might be reporting an error like this;
Connecting to gatekeeper.media [214.15.56.28]:25 ... failed: Connection timed out
The actual full error would look something like this ;
LOG: MAIN
cwd=/usr/local/cpanel/whostmgr/docroot 4 args: /usr/sbin/exim -v -M 1f5Vqj-00033t-Vq
delivering 1f5Vqj-00033t-Vq
LOG: MAIN
Sender identification U=gatekeeper D=gatekeeper.media [email protected]
Connecting to gatekeeper.media [214.15.56.28]:25 ... failed: Connection timed out (timeout=5m)
LOG: MAIN
H=kinspan.com [214.15.56.28] Connection timed out
LOG: MAIN
== [email protected] R=dkim_lookuphost T=dkim_remote_smtp defer (110): Connection timed out
A connection refused error means something is terminating the connection between your mail server and the remote mail server. Something like a firewall possibly. Unless you have access to the remote mail server then you won’t be able to fix this error and you would need to contact the administrator of that mail server to have the connection allowed.
We can use a range of programs to verify our theory. The most common would be Telnet or NMAP. We’re going to use Telnet to ping the offending mail servers IP and the port 25 which is showing the connection refused error above.
Installing Telnet on CentOS/RHEL 6/7
Issue the yum command below to deploy the program
yum install telnet telnet-server -y
Next, using a text editor edit the configuration file
nano /etc/xinetd.d/telnet
Edit the line “Set disable” as below
Set disable = no:
On CentOS 6 systems issue the below command. You can just copy the whole line and paste it into the console
/bin/systemctl start xinetd.service ; chkconfig telnet on; chkconfig xinetd on
On CentOS 7 issue the below commands one at a time.
systemctl start telnet.socket
systemctl enable telnet.socket
The default port for Telnet is 23 so you need to allow this through your firewall. If you are using IPtables you can use the following command.
For CentOS 6 systems using a text editor open the IPtables file
nano /etc/sysconfig/iptables
And add this line then save and close the file.
-A INPUT -p tcp -m state --state NEW --dport 23 -j ACCEPT
Next, restart IPtables
service iptables restart
For CentOS 7 systems issue the following commands one at a time.
firewall-cmd --permanent --add-port=23/tcp
firewall-cmd --reload
Ping Ports
You now have Telnet installed and its ready to use. In your SSH console, you can noping IPs and ports.
The syntax is as follows;
telnet [HOST] [IP]
We want to ping the IP 214.15.56.28 and port 25 so we would use
telnet 214.15.56.28 25
It’s best to try this from different servers, if they all fail with the connection refused error you know the problem is with the remote mail server and not your server.
[[email protected] ~] telnet 214.15.56.28 25
Trying 204.11.56.48...
telnet: connect to address 214.15.56.28: Connection timed out
From the returned error we know that the other mail server is not allowing connections from our server and they would need to be contacted to have connections allowed.
How was this article? – How to ping specific ports from the command line using Telnet
More from All About Linux
Install Ioncube Loaders In Ubuntu, Debian, CentOS and AlmaLinux
Ioncube Loaders are a piece of software that is used to protect the underlying code in PHP applications. Its aim …
How to install FTP and configure FTP on an Ubuntu 22 LTS instance
If you need to upload files to your NVMe VPS you have a couple of options. You can use a …
How to install a Cloudflare Origin SSL Certificate – NGINX
An SSL Certificate is vital to encrypt data between you and your clients. SSLs can be complicated things. If they …