1

I am using telnet from my command line to test connectivity to a remot host and below are the commands I used. I think I can connect to host but not able to completely understand the telnet outputs

yabhi$ telnet <remote host_ipaddr> 22
Trying <remote host_ipaddr>…
Connected to <remote host>
Escape character is '^]'.
SSH-2.0-OpenSSH_5.3
Connection closed by foreign host.

yabhi$ telnet <remote host_ipaddr> 23
Trying <remote host_ipaddr>…
telnet: connect to address <remote host_ipaddr>: Connection refused
telnet: Unable to connect to remote host

In the first command where I telnet to port 22, I get the confirmation that connection has been established to port 22(SSH port). But as I try to test any commands, like 'ping ' or 'date'(to print date), I get the connection closed error message. Does this behavior confirm if the connection has been established to remote host

Surprisingly, when I telnet to port 23(port where telnet server is running), I get the unable to connect message.

3

telnet used in this fashion is just establishing a somewhat raw TCP connection. nc or netcat is a better tool for command line testing of IP network connectivity.

In the first instance, you connected to a listening sshd on port 22, and got the first part of an SSH handshake--the server version string.

In the second instance, you connected to port 23 where telnetd traditionally listens. However, as telnet is less secure than ssh, it is typically not enabled by default on modern systems. You are unable to connect because there is no telnetd listening on <remote_host_ipaddr>.

You are not establishing a remote shell session when using telnet like this, which is why you cannot execute shell commands on the remote system, such as ping or date. You are establishing a network connection which allows you to hand-type what would normally be sent over the network for the relevant protocol. With SSH, you are pretty much stuck after the initial version exchange, as the exchanged data is encrypted past this point.

A more typical use would be to test a server running a protocol which is text-based, such as HTTP, IMAP, or SMTP, e.g.

$ telnet <remote_host_ipaddr> 80
> GET /index.html HTTP/1.0
>
...
$
  • 1
    See also nagios's check_tcp or nmap for even more appropriate commands – Stéphane Chazelas Mar 15 '17 at 16:51
2

With telnet you can check if a port is opened and listening. But not really run commands on the remote host. telnet is majorly insecure and all modern systems have it disabled. That is also the reason why your connection to port 23 fails: the system is not supposed to accept tenet connections and the port is closed. Connection refused means that the connection has been blocked by a firewall or closed port.

0

For a more dedicated way of testing you may use our test tool dda-serverspec (https://github.com/DomainDrivenArchitecture/dda-serverspec-crate) for such tasks. You may define your expectation

{:netcat [{:host "mywebserver.com" :port "443"}
          {:host "telnet mywebserver.com" :port "80"}
          {:host "telnet mywebserver.com" :port "8443"}]}

and test these expectation either against localhost or against remote hosts (connect by ssh). For remote tests you've to define a targets:

{:existing [{:node-name "test-vm1"
             :node-ip "35.157.19.218"}
            {:node-name "test-vm2"
             :node-ip "18.194.113.138"}]
 :provisioning-user {:login "ubuntu"}}

You may run the test with java -jar dda-serverspec.jar --targets targets.edn serverspec.edn

Under the hood we're using netcat with some special settings for timeout or minimizing traffic ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.