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 [220.127.116.11]: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 [18.104.22.168]:25 ... failed: Connection timed out (timeout=5m) LOG: MAIN H=kinspan.com [22.214.171.124] 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
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
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
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 126.96.36.199 and port 25 so we would use
telnet 188.8.131.52 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 184.108.40.206 25 Trying 220.127.116.11... telnet: connect to address 18.104.22.168: 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
Ioncube Loaders are a piece of software that is used to protect the underlying code in PHP applications. Its aim …