2

Assume that you have a pair of UNIX/Linux machines. You want to check if both machines can connect to each other via an arbitrary port, say, TCP 111.

Log into the shell of Machine 1 (10.0.0.1). If Telnet is installed on it, you can check the connectivity with 10.0.0.2 by using the command

$ telnet 10.0.0.2 111

But some UNIX/Linux systems do not have Telnet by default. SSH is more popular thus it may be preferred, especially when you don't want to install exra applications on your machine.

An illustration

Question. Is there any way to test the same with ease, by using the ssh command instead of the telnet command?

(Please answer the question. "You can install Telnet or use Microsoft Windows" doesn't help. TCP 111 is just an example.)

Culip
  • 125
  • 1
  • 6
  • 1
    You can use netcat or just bash with /dev/tcp/ instead of telnet. And probably many other tools. This sounds like a totally artificial question. –  Feb 02 '21 at 00:34
  • `ssh` is the wrong tool (arguably as is `telnet`) – roaima Feb 02 '21 at 00:48
  • No ``nc``, ``telnet``, Microsoft Windows, or any non-standard tools please. As far as I know ``/dev/tcp`` opens a TCP connection to the associated socket.. – Culip Feb 02 '21 at 00:54

1 Answers1

3

I guess you can be certain that ssh is installed, but not nc. In light of that, the question could make sense.

Use the -p option. For example port open:

$ ssh -p 111 192.168.1.16
ssh_exchange_identification: read: Connection reset by peer

Port closed:

$ ssh -p 112 192.168.1.16
ssh: connect to host 192.168.1.16 port 112: Connection refused
berndbausch
  • 3,477
  • 2
  • 15
  • 21
  • I am pretty certain that ``nc`` is not as common as ``ssh``. For example, CentOS 7 doesn't come with ``nc`` by default. – Culip Feb 02 '21 at 16:55