![How to use the command 'telnet' (with examples)](/images/commands/general-1_hu8992dbca8c1707146a2fa46c29d7ee58_10802_1110x0_resize_q90_h2_lanczos_2.webp)
How to use the command 'telnet' (with examples)
Telnet is a command-line tool that allows users to connect to a remote host over a network using the telnet protocol. It is commonly used for troubleshooting network connectivity, testing network services, and accessing remote devices or services. Telnet has various use cases, and in this article, we will illustrate each of them with examples.
Use case 1: Telnet to the default port of a host
Code:
telnet host
Motivation: This use case allows us to connect to the default port of a remote host using the telnet protocol. It is useful when we want to establish a telnet session with a host without specifying a specific port.
Explanation:
telnet
: The telnet command.host
: The hostname or IP address of the remote host.
Example Output:
Trying 192.168.0.1...
Connected to example.com.
Escape character is '^]'.
Use case 2: Telnet to a specific port of a host
Code:
telnet ip_address port
Motivation: This use case allows us to connect to a specific port of a remote host using the telnet protocol. It is useful when we want to establish a telnet session with a host on a non-default port.
Explanation:
telnet
: The telnet command.ip_address
: The IP address of the remote host.port
: The port number on the remote host.
Example Output:
Trying 192.168.0.1...
Connected to example.com.
Escape character is '^]'.
Use case 3: Exit a telnet session
Code:
quit
Motivation: This use case allows us to exit a telnet session. It is useful when we want to disconnect from a remote host after completing our task.
Explanation:
quit
: The command to exit the telnet session.
Example Output:
Connection closed by foreign host.
Use case 4: Emit the default escape character combination for terminating the session
Code:
Ctrl + ]
Motivation: This use case allows us to emit the default escape character combination, which is useful for terminating a telnet session.
Explanation:
Ctrl + ]
: The keyboard shortcut to emit the default escape character combination.
Example Output:
telnet>
Use case 5: Start telnet with a specific session termination character
Code:
telnet -e x ip_address port
Motivation: This use case allows us to start a telnet session with a specific session termination character. It is useful when we want to define a custom character to terminate the telnet session.
Explanation:
telnet
: The telnet command.-e x
: Specifies the character ‘x’ as the session termination character.ip_address
: The IP address of the remote host.port
: The port number on the remote host.
Example Output:
Trying 192.168.0.1...
Connected to example.com.
Escape character is 'x'.
Use case 6: Telnet to Star Wars animation
Code:
telnet towel.blinkenlights.nl
Motivation: This use case allows us to watch a Star Wars animation through the telnet protocol. It is purely for entertainment purposes.
Explanation:
telnet
: The telnet command.towel.blinkenlights.nl
: The hostname that provides the Star Wars animation.
Example Output:
<Star Wars animation starts playing>
Conclusion:
The telnet command offers a range of use cases for connecting to remote hosts, troubleshooting network connectivity, and accessing remote services. By utilizing the examples provided in this article, users can make the most out of the telnet command and accomplish their desired tasks efficiently.