Using Telnet Commands in Linux and Unix
Telnet (telecommunications network) is a network protocol (operating over a TCP connection) designed for manual control of remote machines using console terminal commands.
With Telnet, commands are entered on the local machine but executed on the remote one. That is, the user first enters the IP address and port (by default, 23) of the remote server, and then executes commands on it.
Although SSH is more commonly used today, Telnet still remains a popular tool for managing remote hosts.
And if you’re looking for a reliable, high-performance, and budget-friendly solution for your workflows, Hostman has you covered with Linux VPS Hosting options, including Debian VPS, Ubuntu VPS, and VPS CentOS.
This guide will cover the basic use of Telnet commands in Linux-based operating systems. All examples shown were run on a Hostman cloud server running Ubuntu 22.04.
Telnet vs SSH Copy link
Telnet and SSH are similar technologies that allow you to execute console commands on remote machines.
However, a side-by-side comparison of Telnet and SSH is not entirely correct. Rather, SSH, introduced in 1995, is an evolutionary successor to Telnet, which was created in 1969.
Unlike Telnet, the SSH protocol fully encrypts data. Therefore, Telnet, being the older technology, is more vulnerable to interception.
In addition, SSH supports secure authentication methods using a private–public key pair, while Telnet uses simple plain-text authentication.
Nevertheless, due to its simplicity, Telnet is still relevant. It is used in tasks that do not require high security, for example in closed networks.
Based on this, we can highlight some key differences between Telnet and SSH:
|
Feature |
Telnet |
SSH |
|
Release |
1969 |
1995 |
|
Port |
23 |
22 |
|
Vulnerability |
High |
Low |
|
Data |
Plain text |
Encrypted text |
|
Specialization |
Private nets |
Public nets |
|
Bandwidth |
Low |
High |
|
Colored/graphic terminal |
Not supported |
Supported |
Installing Telnet Copy link
To check if Telnet is installed on the system, you can enter a console command with an incorrect option:
telnet -qIf Telnet is present in the system, the console terminal will display an error message and a short help listing possible options:
telnet: invalid option -- 'q'
Usage: telnet [-4] [-6] [-8] [-E] [-L] [-a] [-d] [-e char] [-l user]
[-n tracefile] [ -b addr ] [-r] [host-name [port]]If instead you see an output like this:
-bash: /usr/bin/telnet: No such file or directoryOr this:
telnet: command not found
Try: apt install <deb name>Then you need to manually download and install the Telnet utility. For Ubuntu, use the APT package manager:
sudo apt install telnetAfter this, you can proceed to using the Telnet protocol to manage remote hosts.
Using Telnet Copy link
Establishing a connection to a remote machine using the Telnet utility does not require complex commands and largely resembles working with SSH.
The general command format looks like this:
telnet [OPTIONS] [IP ADDRESS] [PORT]Here we specify three main types of parameters for connecting to a remote machine:
IP ADDRESS. Either the IP address (IPv4 or IPv6) or the domain name of the remote machine you are connecting to.PORT. The open port on the remote machine through which the connection is established. By default, Telnet listens on port 23.OPTIONS. Additional flags with parameters that refine the details of the connection.
A small list of useful Telnet options, each performing a specific function:
-4— Use an IPv4 address during connection-6— Use an IPv6 address during connection-8— Use 8-bit encoding when sending data-e— Change the escape character (disconnect hotkey)-E— Disable the escape character-l— Explicitly specify a username for authentication on the remote machine-a— Use the username from the environment variable USER for authentication
Thus, a real Telnet connection command might look like this:
telnet -4 166.1.227.100 23In this case we specified:
- The
-4option, telling it to use an IPv4 address - The IP address of the remote machine
- The standard port 23, on which the remote server listens for Telnet connections
Since defaults can be omitted, you can simplify the command to:
telnet 166.1.227.100After establishing a connection with the remote host, Telnet can work in two modes:
- Line mode (default). Commands and data are typed character by character but sent to the remote server line by line. This allows you to correct mistakes before sending a command.
- Character mode. Commands and data are both typed and sent character by character. In this mode, you cannot correct typing errors.
Managing the remote machine is done with a set of commands. Here are the main ones:
OPEN— Connect to a remote machineCLOSE— Disconnect from a remote machineLOGOUT— Disconnect from a remote machine and exit TelnetSTATUS— Check connection status with the remote machineMODE— Switch between line and character modes
Connecting to a Local Host Copy link
The simplest way to check Telnet functionality is to connect to a local host:
telnet localhostTypically, this command results in an error:
Trying ::1...
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refusedThis happens because the Telnet service (server daemon), which listens on port 23 by default and handles connections, is not installed on the local machine.
You can install it using the APT package manager:
sudo apt install telnetd -yNote the letter d after telnet—this is not a typo! The -y flag automatically answers “yes” to prompts during installation.
After this, you can retry connecting to the local host:
telnet localhostThe console will show connection status and a login prompt:
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Ubuntu 22.04.5 LTS
3833269-yn55665 login:For testing, you can log in as the root user. The console will then ask for the password.
After successful authentication, all entered commands will be executed on the remote machine.
For example, you can immediately exit the remote host console:
exitThe local machine console will then display a logout message:
logout
Connection closed by foreign host.You can also skip entering the username interactively by specifying it in advance with the -l option:
telnet -l root localhostIn this case, the console will directly prompt for the password:
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Password:Performing an HTTP Request to a Remote Host Copy link
Another way to use Telnet is to execute HTTP requests to remote servers.
For example, you can load the main page of a website like this:
telnet hostman.com 80Note that port 80 is explicitly specified in the command, since it is the default port for HTTP connections.
After that, the terminal will prompt you to enter the HTTP request:
GET / HTTP/1.0
Host: hostman.comOnce sent, the console will display the server’s response and a message about connection closure:
HTTP/1.1 301 Moved Permanently
Server: QRATOR
Date: Sun, 07 Aug 2025 11:02:03 GMT
Content-Length: 0
Connection: close
location: https://hostman.com/
Connection closed by foreign host.The received response from the remote server indicates that the requested website has permanently moved to the HTTPS protocol.
Telnet Options Copy link
When using Telnet, you can specify additional options that refine the connection mechanism with the remote machine.
Some options require specifying an additional parameter after them.
-4
This option explicitly tells Telnet to use an IPv4 address for the connection:
telnet -4 166.1.227.100-6
This option explicitly tells Telnet to use an IPv6 address for the connection:
telnet -6 2a03:6f00:a::4ca1At the same time, it is important to make sure that the listening server (for example, telnetd) supports working with IPv6 addresses.
-8
This option instructs Telnet to use 8-bit data transfer:
telnet -8 166.1.227.100Today, this option can be considered irrelevant, since modern machines support higher bit depths when transmitting data.
-e
If you start Telnet without explicitly specifying an escape sequence, the console will display an informational message about the connection status:
telnet 166.1.227.100Output:
Trying 166.1.227.100...
Connected to 166.1.227.100.
Escape character is '^]'.
Ubuntu 22.04.5 LTS
3833269-yn55665 login:In this output, you can see the line:
Escape character is '^]'.By default, the escape sequence looks like this:
^]This means that when you press the key combination Ctrl + ] in the active console terminal of the remote machine, Telnet will disconnect from it and switch to its own terminal, which usually opens after entering the command to launch the utility:
telnetAfter that, you can exit the Telnet terminal, returning to the standard console terminal of the local machine:
quitAccordingly, the exit hotkey combination can be changed:
telnet -e ^P 166.1.227.100In this case, disconnecting from the remote machine will be performed after pressing Ctrl + P simultaneously.
If you do not put the caret symbol (^) before the key character, then Telnet will react to pressing only the specified key without using Ctrl:
telnet -e ] 166.1.227.100In this case, you can disconnect from the remote machine by pressing the single key ].
However, you must be careful—if the entered username or password (even if copied and not typed on the keyboard) contains the specified single character (for example, the square bracket ]), Telnet will react to it and terminate the connection with the remote host even at the authentication stage.
The same applies to entering characters as control commands in the remote terminal after authentication.
For example, if you set the lowercase letter t as the escape character, Telnet will terminate the connection at the moment of typing the last character of the username root:
telnet -e t 166.1.227.100Output:
root@3833269-yn55665:~# telnet -e t 166.1.227.100
Telnet escape character is 't'.
Trying 166.1.227.100...
Connected to 166.1.227.100.
Escape character is 't'.
Ubuntu 22.04.5 LTS
3833269-yn55665 login:-E
You can completely disable the exit hotkey combination (escape sequence):
telnet -E 166.1.227.100After this, the console terminal will show a message about the connection status:
Trying 166.1.227.100...
Connected to 166.1.227.100.
Escape character is 'off'.
Ubuntu 22.04.5 LTS
3833269-yn55665 login:In it, the corresponding line will indicate the absence of an escape sequence:
Escape character is 'off'.After that, you can exit the console terminal of the remote machine (for example, if it runs Ubuntu) only with an explicit exit command:
exit-l
When connecting via Telnet, the console terminal will prompt you to enter a username for authentication on the remote machine:
Trying 166.1.227.100...
Connected to 166.1.227.100.
Escape character is 'off'.
Ubuntu 22.04.5 LTS
3833269-yn55665 login:You can avoid entering a username by explicitly specifying it in the command:
telnet -l root 166.1.227.100In this case, the console terminal will immediately prompt you to enter the password for the specified account:
Trying 166.1.227.100...
Connected to 166.1.227.100.
Escape character is '^]'.
Password:-a
In Linux operating systems, there is an environment variable USER, which contains the name of the user currently using the system:
echo $USERThe console terminal will display the current username:
rootYou can pass this name to Telnet for automatic authentication:
telnet -a 166.1.227.100After that, Telnet will take the required username from the USER environment variable and only prompt you for a password:
Trying 166.1.227.100...
Connected to 166.1.227.100.
Escape character is '^]'.
Password:Telnet Commands Copy link
Unlike options, commands are keywords followed by additional parameters. You can enter Telnet commands only in its own terminal:
telnetAfter this, the active console terminal line will have this prompt:
telnet>To view a description of a specific command, you need to enter a question mark before its name:
? commandTo view help on a specific command, you need to enter a question mark after its name:
command ?OPEN
Establishes a connection to a host based on its IP address and port:
open localhostAfter that, the console terminal will display the usual login prompt:
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Password:You can request additional help on the command:
open ?After that, the console terminal will display the command usage scheme with all possible parameters and options:
usage: open [-l user] [-a] host-name [port]As you can see, you can use the -l option with this command, which allows you to specify the username before authentication:
open -l root localhostA short description of the command can be read as follows:
? openIn this case, the console terminal will display this output:
connect to a siteCLOSE
Closes the open connection to a host:
closeThis command is not used during interaction with the remote host terminal. Usually, it is relevant when connecting to systems of another type.
LOGOUT
The command is similar to CLOSE, but works somewhat differently. Unlike independently closing the connection on the local machine side, as in the case of CLOSE, this command forces the remote host to close the connection:
logoutSTATUS
Displays the current connection status:
statusMODE
Switches modes of working with the remote host.
For example, this activates line mode:
mode lineAnd this activates character mode:
mode characterConclusion Copy link
As the predecessor of SSH, the Telnet protocol does not provide sufficient security—it does not use the encryption methods that are standard in SSH.
Nevertheless, Telnet is still relevant for private tasks. Therefore, it is worth knowing the basics of working with it.
Interaction with Telnet is based on executing commands with specific options. In this way, you can make connections (requests) to remote machines over various addresses and ports, as well as execute console commands as if they were being run locally.
You can find comprehensive information on using Telnet in the official documentation.