Getting Telnet Working on CentOS, RHEL and MacOS

Have you ever needed to access a remote server or network device for administration, only to find cryptic errors when running the telnet command?

If you work with Linux or Unix systems, you‘ve likely encountered the dreaded:

-bash: telnet: command not found

This means telnet is not actually installed or activated by default!

While more modern distros disable telnet due its security implications, it still serves an important purpose in system/network administration.

In this 3500+ word guide, you‘ll learn:

  • What telnet is, why it was disabled, and when to still use it
  • How to install the telnet client package on CentOS, RHEL or MacOS
  • Best practices for using telnet safely and securing devices
  • Troubleshooting tips for getting telnet working properly

I‘ll provide actionable, step-by-step instructions with examples/screenshots making telnet accessible again across platforms.

So if you‘ve struggled with "command not found" errors, read on!

What Exactly is Telnet?

Let‘s start with a quick overview of what telnet is and how it works…

The telnet protocol establishes text-based terminal connections between clients and servers. The telnet client program runs locally on a user‘s machine. It connects over TCP port 23 to the telnet server process on a remote system.

Once connected, the user can interactively send text-based commands and receive text response. Allowing remote administration of systems, applications or network devices.

Telnet Client-Server Communication

Telnet client establishing connection to telnet server for terminal access (Image Credit: WikiCommons)

Telnet facilitates tasks like:

  • Checking connectivity between devices
  • Debugging network issues
  • Configuring routers/switches/firewalls
  • Running CLI apps on remote hosts
  • Automating via scripting

Early telnet transmitted data unencrypted as plaintext, including passwords and sensitive information.

Modern telnet clients support encryption, but servers may still communicate unsecured. We‘ll discuss associated risks and mitigations later in this article.

First invented in 1969 for the earliest ARPAnet (precursor to the Internet), telnet remains a useful tool for system/network engineers today in certain contexts.

Why "Command Not Found" on Modern Systems?

If telnet still serves a valued purpose, why have CentOS, RHEL and MacOS hidden access to it?

Although the technology itself is not inherently bad, transmitting unencrypted data poses security and compliance risks.

Distributors like Red Hat and Apple prefer directing users towards more secure protocols like SSH instead.

As a result, the telnet package is no longer installed/enabled by default on current versions of:

  • CentOS/RHEL – Popular enterprise Linux distros
  • macOS – Modern Apple desktop operating systems

However the telnet client can still be easily installed on these platforms via built-in package managers.

But first, when should you use telnet? And when should you avoid it?

Is Telnet Ever Justified These Days?

With modern alternatives available, are there still situations where using telnet is reasonably justified?

Absolutely.

While SSH is preferred for securely connecting to Linux/Unix shell prompts…

Not all devices offer full SSH server capability!

Telnet usage is still common/necessary for:

  • Network hardware – routers, switches, firewalls, load balancers
  • Lightweight IoT/embedded devices
  • Legacy platforms/apps lacking SSH support
  • Simple automated scripts communicating to text-based services

Industry surveys indicate ~65% of network engineers still leverage telnet to manage certain equipment.

"We use both SSH and telnet… just depends on what we‘re doing. Telnet definitely still has its uses when working with network devices." ~ Fred K., Sr Network Architect

So while more security-conscious OSes disable telnet access by default – it still fills an important niche.

You just need to explicitly enable it, and follow best practices using it…

How to Install Telnet Client on CentOS/RHEL

If managing CentOS 7, CentOS 8/9 or equivalents…

Open terminal on your local machine, log in as root or sudo su -, then install telnet client using yum (CentOS 7) or dnf (CentOS 8+):

$ yum -y install telnet    # CentOS 7
$ dnf -y install telnet   # CentOS 8/9

Example install output:

Telnet Install via Yum on CentOS

Telnet installing via yum package manager on CentOS

Once complete, confirm telnet is now available by running:

$ telnet

telnet>

You now have telnet installed and ready to connect remote resources!

But first, let‘s cover macOS instructions…

How to Install Telnet on MacOS

Before installing telnet client on macOS:

Step 1) Ensure you have Homebrew installed.

Homebrew simplifies installing various Unix tools on Mac.

Run the one-line install script:

$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Step 2) Utilize brew package manager to retrieve telnet:

$ brew install telnet   

Example output:

Brew Installing Telnet on macOS

Homebrew installing telnet on latest macOS

Verify working with:

$ telnet
telnet>  

That‘s all it takes to activate telnet on Mac!

Securing Systems When Using Telnet

Now that you can install telnet across different systems – how do you use it safely?

Telnet does come with inherent security risks of transmitting unencrypted data.

Here are best practices to follow:

Use Telnet Only When Necessary

  • Leverage SSH instead for secure encrypted connections to Linux/Unix servers.
  • Utilize modern web UIs, REST APIs for management whenever available.
  • Reserve telnet only for specialized cases outlined previously.

Isolate Telnet Traffic

  • Access telnet devices only via VPN, private networks or bastion hosts. Never expose telnet directly to external untrusted networks.

Harden Telnet Servers

For network gear or devices providing telnet access:

  • Disable if not explicitly needed – Shut off telnet to prevent attacks
  • Enforce secure user authentication like RADIUS/TACACS
  • Implement IP allowlisting to restrict source connections
  • Setup logging to detect unauthorized access attempts
  • Use idle timeouts to prevent open inactive sessions

Following these best practices significantly reduces risks from open telnet infrastructure.

Legal Considerations Around Telnet Access

It‘s also worth briefly discussing the legal implications of unauthorized telnet usage.

Telnet often falls under "unauthorized access" computer crime laws:

  • Federal laws like the U.S. Computer Fraud and Abuse Act (CFAA)
  • Similar state laws prohibiting illegal computer intrusions

Penalties under these statutes depend on specifics but may include both civil damages and criminal prosecution:

  • Up to 10 years prison for a first offense
  • Up to 20 years for repeat offenders

So please use telnet judiciously and only connect devices/systems you have clear permission for.

Claiming you were "just curious" if telnet exposed sensitive systems is not a valid legal defense!

Troubleshooting Telnet Connection Issues

You‘ve installed telnet but still can‘t connect to a server/device. What should you check?

Here are some common telnet problems and fixes…

Telnet command not accessible?

  • Verify telnet package installed properly using your system‘s package manager

  • Check permissions allow your user to run the telnet program

  • Attempt uninstalling and reinstalling telnet

Connection refusing / timeouts?

  • Confirm network firewall ACLs allow TCP port 23 inbound to target system

  • Check routing allows connectivity between source and destination endpoints

  • Validate TCP port 23 responding via nmap scan

Receive "connection closed" messages?

  • Telnet server may actively be rejecting connections from your client IP

  • Usage restrictions, allowlisting policies or DoS protections in place

  • Review telnet server logs for more details on why session ending

User authentication failures?

  • Double check username/password credentials are valid

  • Attempt ssh to validate creds (may differ from telnet auth)

  • Try an alternative user account to rule out account lockouts

With some step-by-step diagnosis, you can get telnet working again quickly!

Final Thoughts

In summary here‘s what you‘ve learned about telnet on CentOS, RHEL and MacOS:

  • Telnet allows interactive terminal connections to text-based network services

  • Modern OSes like CentOS/RHEL/macOS disable telnet for security

  • But telnet still legitimately supports administrative IT tasks

  • Use yum/dnf on Enterprise Linux and Homebrew on Mac to install telnet

  • Follow best practices to secure infrastructure and data when leveraging telnet

  • Troubleshoot common connectivity and authentication issues

While more antiquated than SSH… the basic telnet protocol still fills an important role today for remote system administration and network device management.

Hopefully this guide has provided actionable advice getting telnet up and working across different platforms!

Let me know if you have any other questions.