[email protected]Office hours: Mon – Fri 9:00AM – 5:00PMLinkedInXFacebook
NexonHost
Netherlands Dedicated ServersAmsterdam · Equinix AM6Germany Dedicated ServersFrankfurt · Equinix FR4Romania Dedicated ServersBucharest · VoxilityAustria Dedicated ServersVienna · Interxion VIEBulgaria Dedicated ServersSofia · TelepointFrance Dedicated ServersParis · Interxion PAR — Marseille · Digital Realty MRS3Ireland Dedicated ServersDublin · Equinix DB2Italy Dedicated ServersMilan · Irideos AvalonPoland Dedicated ServersWarsawSpain Dedicated ServersMadrid · Equinix MD2United States Dedicated ServersAshburn · Equinix DC
All articles
Knowledge BaseJanuary 12, 2024

How to use telnet command.

What is telnet command:

Telnet is a network protocol used on the Internet or local area networks to provide a bidirectional interactive text-oriented communication facility using a virtual terminal connection. The term “telnet” also refers to the command-line utility that uses the Telnet protocol, allowing you to connect to remote systems or devices.

Installing Telnet in Different Linux Distributions

Depending on the Linux distribution you are using, follow the steps below to download and install telnet.

CentOS, Fedora, and RHEL

CentOS, Fedora, and RHEL use yum (Yellowdog Update Manager) as the primary package manager. Follow the steps below:

  1. Update the system package

repository to make sure the latest version is installed:

sudo yum update
  1. Run the following commands to install

telnet and the telnet server packages required for it to function properly:

sudo yum install telnet telnet-server -y

The command installs the two packages. The -y flag automatically answers Yes to any prompts during the installation.

  1. After the installation completes, start and enable the

telnet service by running:

systemctl start telnet.socket
systemctl enable telnet.socket
  1. Allow the

telnet port (the default port is 23) through the firewall on the remote machine. Run the following command:

sudo firewall-cmd --permanent --add-port=23/tcp
  1. Reload the firewall to apply the changes:
sudo firewall-cmd --reload

The telnet port is now allowed through the firewall.

Ubuntu and Debian-Based Distributions

Ubuntu and other Debian-based distributions use the apt package manager by default. Follow the steps below to install telnet:

Note: Learn the difference between apt and yum.

  1. Update the system package repository:
sudo apt update
  1. Run the following command to install

telnet:

sudo apt install telnetd -y

Wait for the installation to complete. The service should start automatically.

  1. Check if

telnet is properly installed by running:

sudo systemctl status inetd

The output shows that the daemon is up and running.

  1.  

Allow port 23 through the firewall on the remote machine by running:

sudo ufw allow 23/tcp
  1. Reload the firewall:
sudo ufw reload

The telnet port is now allowed through the firewall.

Note: The command above is for the ufw firewall. If you are using a different firewall, follow the instructions for that specific program.

How to Use telnet in Linux

A vital prerequisite for using telnet is to have it installed on both the local and remote machine, and that the default port 23 is allowed through the firewall on the remote machine.

The syntax for the telnet command is:

telnet [options] [remote_server_address] [port]

The [options] and [port] parameters are optional. For [remote_server_address], telnet accepts symbolic and numeric addresses.

Running the command without options or without specifying an address opens the telnet interactive mode:

Use the interactive shell to connect to remote servers, print the connection status, etc.

To end a session and exit telnet, run:

quit

The sections below provide practical telnet use case examples.

Check for Open Ports

Although it is not a secure option for establishing a remote connection, telnet is a great way to check if a specific port is open on a server. Check if a certain port is answering any calls by specifying the port number in the command. Doing so allows you to see what’s going on in a network and if a port is responsive or not.

  1. Use the following syntax:
telnet [server_address] [port]
  1. Not specifying a port number defaults to port 23. For example, to check if port 22 is open on a server, run:
telnet google.com 22

The connection breaks, which means that the specified port is not open.

  1. However, trying port 80 yields a different result:
telnet google.com 80

The output shows that the port is open since the connection was established.

Download Web Page to File

telnet allows users to connect to port 80 of a website and download the HTML source code to the terminal. This allows you to save and inspect the source code, check it for errors, etc.

  1. For example, the following command connects to port 80 on Google :
telnet staging.nexonhost.com/ 80
  1. After establishing the connection, download the HTML web page by running:
GET /index.html

The screenshot above shows that the command has downloaded the homepage source code.

  1. Save the code to a file or inspect it in the terminal.

Test SMTP Communication

Another useful feature of telnet is that it allows users to test the SMTP port by sending emails directly from the command line. To do so, you need an email server that doesn’t require authentication. It is a great way to troubleshoot problems in an email client.

Follow the steps below to send an email using telnet:

  1. Connect to the server via the SMTP port:
telnet [server_address] [port]

For [server_address], specify the SMTP server address. For example, for Gmail it is smtp.gmail.com, while the SMTP [port] can be 25, 465, 587, etc., depending on the provider.

  1. Greet the server with

HELO or EHLO:

HELO [your_IP_address]
  1. Specify the sender:
MAIL FROM: <[email protected]>
  1. Specify the recipient:
RCPT TO: <[email protected]>
  1. Specify the subject and email body, separated by a blank line:
SUBJECT: This is the email subject.
""
This is the email body.

Note: Most mail servers flag unsolicited anonymous mail, which means that it will likely end up in the spam folder.

Connect to Remote System

If you decide to use telnet for remote connections despite its lack of security, do it by specifying the remote machine’s IP address.

telnet [remote_machine_IP]

Make sure that telnet is installed on both machines and port 23 is allowed through the firewall on the remote machine.

When prompted, enter the account username and password to log in to the system. After logging in, you can operate the other machine remotely.

For example:

After the connection is established, you are in control of the remote machine.

Conclusion:

This tutorial showed how to use the telnet command in Linux. Although it has poor security features and isn’t recommended for remote connections, the command has other uses that make it beneficial.

 

Keep reading
How to Implement Network Segmentation and Resource Isolation in Linux.
February 6, 2024

How to Implement Network Segmentation and Resource Isolation in Linux.

How to Implement Network Segmentation and Resource Isolation in Linux. Securing and managing networks in a Linux environment involves advanced practices like network segmentation and resource isolation. This guide explores these concepts, providing detailed instructions and examples for…

Read article
How to open or close ports in Linux.
February 6, 2024

How to open or close ports in Linux.

How to open or close ports in Linux. Effectively managing ports on your Linux system is crucial for both security and service accessibility. This comprehensive guide will provide a detailed walkthrough on opening and closing ports using the robust tools iptables and ufw. Understanding these…

Read article
How to use ypdomainname command.
January 23, 2024

How to use ypdomainname command.

How to use ypdomainname command. In the realm of Linux networking, the ypdomainname command plays a crucial role in the context of the Network Information Service (NIS). NIS, formerly known as Yellow Pages, is a distributed database service that facilitates the sharing of network configuration and…

Read article
Get in Touch

Together, Let’s Build a Faster, Safer Internet.

Build scalable infrastructure with NexonHost — high-performance dedicated servers, VPS hosting, colocation, and DDoS protection across Europe.

Get Started →Contact Us
[email protected]Office hours: Mon – Fri 9:00AM – 5:00PM