Telnet is a network protocol used to provide a command-line interface for communication with remote devices or servers. It allows users to connect to remote systems over a TCP/IP network, making it useful for troubleshooting and accessing network equipment, such as routers and switches, as well as some legacy systems. However, because Telnet transmits data in plain text, it is considered insecure for sensitive tasks and has largely been replaced by SSH (Secure Shell) in modern environments. Despite this, Telnet is still valuable for specific administrative tasks, testing, and debugging network services.
On Ubuntu 24.04, 22.04, or 20.04, Telnet can be installed easily via the Ubuntu default repository. This installation method provides a straightforward way to access and use Telnet when needed, particularly for testing and troubleshooting purposes. This guide will walk you through the steps to install Telnet using the command-line terminal on your Ubuntu system.
Update Ubuntu Before Telnet Installation
Before installing Telnet, update your Ubuntu system fully by running the following command in the terminal:
sudo apt update && sudo apt upgrade
This command will check for updates and upgrade the existing packages to their latest versions. It is an excellent practice to update your system to ensure the smooth running of Telnet and other installed packages.
Install Telnet via APT Command
Telnet, included in Ubuntu’s standard repository, simplifies the installation process. To install Telnet on Ubuntu, execute the following command in the terminal:
sudo apt install telnetd telnet
Once installed, ensure the Telnet status is okay with the following command.
systemctl status inetd
If the Telnet service is not active, run the following command to start it immediately.
sudo systemctl start inetd
Telnet Command Examples
With Telnet now installed and running on your Ubuntu system, the following are examples of using Telnet via the command line.
Connect to a specific host on a specific port.
telnet [hostname or IP address] [port]
Example:
telnet example.com 23
Connect to a specific host on a specific port with a specified timeout.
telnet [hostname or IP address] [port] [timeout in seconds]
Example:
telnet example.com 80 20
Connect to a specific host on a specific port with a specified timeout and several attempts.
telnet [hostname or IP address] [port] [timeout in seconds] [attempts]
Example:
telnet example.com 80 20 3
After running the commands, the terminal may prompt you to enter your credentials and follow additional instructions to complete the task. Completing these steps is standard when modifying firewall rules. If you intend to use Telnet often on sensitive networks, secure it using step 4 and the UFW firewall for maximum protection. This approach safeguards your system against unauthorized access and potential security threats.
Secure Telnet via UFW Firewall
Securing Telnet on Ubuntu using the ufw firewall can help protect against unauthorized access and potential security threats.
Verify UFW is Installed and enabled
Before securing Telnet on Ubuntu with the UFW firewall, first check the firewall’s status. Run the following command in the terminal to accomplish this.
sudo ufw status
This command furnishes information about the UFW firewall’s current status and existing rules. Notably, all Ubuntu systems have UFW pre-installed, ensuring its presence on your system.
Enable the UFW firewall on your Ubuntu system, if not already active, by running the following command in the terminal:
sudo ufw enable
This command will activate the firewall and begin enforcing the rules set. Enabling the firewall is essential to secure Telnet and protect your system from unauthorized access and potential security threats.
After enabling UFW, the next step is configuring the firewall’s basic rules. By default, this includes denying all incoming and outgoing connections. You can set these rules by running the following commands in the terminal.
sudo ufw default deny incoming
sudo ufw default allow outgoing
Note that the system might have these rules set by default. If not, you should set them. These rules block all incoming connections while allowing outgoing connections by default, providing an extra layer of security to shield your system from unauthorized access and potential security threats.
Basic Telnet UFW Application Rules
To enable Telnet connections through the UFW firewall, you can use the following command in the terminal:
sudo ufw allow telnet
To block Telnet connections through the UFW firewall, you can use the following command in the terminal.
sudo ufw deny telnet
This command will add a firewall rule blocking incoming Telnet connections. This will prevent any unauthorized access to your system using Telnet. This command helps avoid potential security threats and secure Telnet on your Ubuntu system.
Advanced Telnet UFW Example Rules
Here are some examples of how to use the ufw firewall to secure Telnet on Ubuntu.
To allow Telnet connections on port 23, use the command:
sudo ufw allow 23/tcp
Block Telnet connections on port 23; use the command:
sudo ufw deny 23/tcp
Allow Telnet connections from a specific IP address; use the command:
sudo ufw allow from 192.168.1.10 to any port 23
Block Telnet connections from a specific IP address; use the command:
sudo ufw deny from 192.168.1.10 to any port 23
Allow Telnet connections from a specific IP range; use the command:
sudo ufw allow from 192.168.1.0/24 to any port 23
Additional Telnet Commands
Remove Telnet From Ubuntu
To remove Telnet from your Ubuntu system, you can use the following command in the terminal:
sudo apt remove telnet telnetd
Conclusion
Installing Telnet on your Ubuntu system from the default repository is a simple process that enables you to utilize this protocol for basic network testing and connectivity tasks. While Telnet is not recommended for secure communications, it remains a useful tool for specific scenarios, especially in controlled environments. Regular updates through Ubuntu’s package management system will ensure that your Telnet installation is maintained, allowing you to use it effectively when needed on Ubuntu.