Using Bash to test if a TCP port on a remote system is open
search cancel

Using Bash to test if a TCP port on a remote system is open

book

Article ID: 334203

calendar_today

Updated On:

Products

VMware Aria Suite

Issue/Introduction

When configuring Adapter connections for the various vROps True Visibility Suite Packs, it may be necessary to verify port connectivity.  This test could be used to validate new firewall rules, or checking if a default or configured port is open and accepting connections.

 

Many vROps installations are deployed from the VMware provided OVA file.  This system is pre-hardened by VMware and does not have many common network testing tools installed, such as telnet or nc. As an alternate method, we can use bash provided /dev/tcp/ to test if a port is open on a remote system.

 

/dev/tcp/host/port

If host is a valid hostname or Internet address, and port is an integer port number

or service name, bash attempts to open a TCP connection to the corresponding socket.

 

The format for this test is as follows:

 

$ cat < /dev/tcp/<hostname_or_ip>/<port_number>


If the port is closed, the result will read as "No route to host" or "Connection refused". Example given:

 

$ cat < /dev/tcp/em-oel6-d2.bluemedora.localnet/99

-bash: connect: Connection refused

-bash: /dev/tcp/em-oel6-d2.bluemedora.localnet/99: Connection refused

 

If it is open, it will appear that nothing has happened. The connection is open and waiting for further commands. Do a ctrl-C to exit.

 

$ cat < /dev/tcp/em-oel6-d2.bluemedora.localnet/1521

^C



Environment

VMware vRealize True Visibility Suite 1.0