telnet Command: Tutorial & Examples
Connect to a remote host using the Telnet protocol
The telnet
command is used to connect to a remote host using the Telnet protocol, which is a plaintext protocol used to establish a connection and communicate with a remote
server. Telnet is commonly used to test network connectivity and to check the status of various services running on a server.
The basic syntax for using the telnet
command is as follows:
telnet [hostname or IP] [port]
Here are a few examples of how the telnet
command can be used to check different ports on a remote host:
Check if a remote HTTP server is running on port 80:
telnet example.com 80
Check if a remote SSH server is running on port 22:
telnet example.com 22
Check if a remote SMTP server is running on port 25:
telnet example.com 25
In the first example, the telnet
command is used to connect to the remote host example.com
on port 80, which is the default port for the HTTP protocol. In the second example,
the telnet command is used to connect to the remote host on port 22, which is the default port for the SSH protocol. In the third example, the telnet
command is used to connect
to the remote host on port 25, which is the default port for the SMTP protocol.
When you run telnet
command to a port, if the connection is successful, you will see a message like Connected to [hostname]
and you will see a cursor blinking. If the port is
closed or not available the command will return with an error message such as Could not open connection to the host, on port [port]: Connect failed
.
It's worth noting that telnet
is an insecure protocol since it sends data in plaintext, and it's recommended to use SSH protocol to connect to remote servers. Also, Telnet
support is not enabled by default on many modern Linux distributions, so you may need to install it before using it.