Red Hat Enterprise Linux / CentOS

How to Telnet via BASH Script

This article will show you how to Telnet via BASH script and return the status as open or close. This has been tested on CentOS/RedHat and hopefully should work on all other Linux distributions as well.

Create a file This script is to Telnet SSH port i.e. 22

# vi
echo " 22" | \
while read host port; do
  r=$(bash -c 'exec 3<> /dev/tcp/'$host'/'$port';echo $?' 2>/dev/null)
  if [ "$r" = "0" ]; then
    echo $host $port is open
    echo $host $port is closed


telnet script 1

This is when Telnet for SSH Port responds OK.


telnet script 2

This is when Telnet for SSH Port responds FAIL.

If you encounter any errors during the process, let us know via Contact Us and will try our best to help.

Leave a Reply

Your email address will not be published.