Linux telnet Command with Practical Examples

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to use the Linux telnet command to connect to remote servers and troubleshoot network connectivity issues. The lab covers the purpose and syntax of the telnet command, how to establish a connection to a remote server, and how to use telnet for network troubleshooting. The steps provide practical examples and demonstrate the versatility of the telnet command in a Linux environment.

Linux Commands Cheat Sheet


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/RemoteAccessandNetworkingGroup(["`Remote Access and Networking`"]) linux/RemoteAccessandNetworkingGroup -.-> linux/ssh("`Secure Connecting`") linux/RemoteAccessandNetworkingGroup -.-> linux/telnet("`Network Connecting`") linux/RemoteAccessandNetworkingGroup -.-> linux/ping("`Network Testing`") linux/RemoteAccessandNetworkingGroup -.-> linux/nc("`Networking Utility`") subgraph Lab Skills linux/ssh -.-> lab-422954{{"`Linux telnet Command with Practical Examples`"}} linux/telnet -.-> lab-422954{{"`Linux telnet Command with Practical Examples`"}} linux/ping -.-> lab-422954{{"`Linux telnet Command with Practical Examples`"}} linux/nc -.-> lab-422954{{"`Linux telnet Command with Practical Examples`"}} end

Understand the Purpose and Syntax of the telnet Command

In this step, you will learn about the purpose and basic syntax of the telnet command in Linux. The telnet command is a network protocol used to establish a connection to a remote server or device over a TCP/IP network.

First, let's understand the purpose of the telnet command:

$ telnet --help
Usage: telnet [OPTION]... [HOST [PORT]]
Open a terminal to a remote host
  -a, --autologin                 Attempt automatic login
  -b, --binary                    Enable binary mode
  -c, --crlf                      Use CRLF for line endings
  -d, --debug                     Turn on debugging
  -e, --escape=CHAR               Set escape character
  -E, --noesc                     Disable escape character
  -f, --forward-x11               Automatically forward X11 connections
  -F, --rlogin                    Assume rlogin protocol
  -k, --tick                      Send telnet kludge
  -l, --user=USER                 Specify remote username
  -n, --tracefile=FILE            Dump network traffic to a file
  -r, --rsh                       Shorthand for -rlogin
  -S, --skip-source-address       Skip test of source address
  -t, --tunnel                    Do port forwarding
  -x, --xdisplay=DISPLAY          X display to use
      --help                      Display this help and exit
      --version                   Output version information and exit

The telnet command allows you to connect to a remote server or device, and interact with it as if you were directly connected to that system. This can be useful for troubleshooting network connectivity issues, testing services, or accessing remote systems.

Now, let's look at the basic syntax of the telnet command:

$ telnet [host] [port]

Here, [host] is the IP address or hostname of the remote server you want to connect to, and [port] is the port number you want to connect to on that server. For example, to connect to a web server running on port 80, you would use:

$ telnet www.example.com 80

Example output:

Trying 93.184.216.34...
Connected to www.example.com.
Escape character is '^]'.

In this example, the telnet command connects to the web server running on www.example.com on port 80. The "Escape character is '^]'" message indicates that you can use the Ctrl+] key combination to enter the telnet command prompt.

Connect to a Remote Server Using the telnet Command

In this step, you will learn how to use the telnet command to connect to a remote server.

First, let's try connecting to a web server using the telnet command:

$ telnet www.example.com 80

Example output:

Trying 93.184.216.34...
Connected to www.example.com.
Escape character is '^]'.

Once connected, you can send HTTP requests directly to the web server. For example, to request the root page, you can type:

GET / HTTP/1.1
Host: www.example.com

Example output:

HTTP/1.1 200 OK
Date: Fri, 14 Apr 2023 12:34:56 GMT
Server: Apache
Content-Length: 1256
Content-Type: text/html

<!doctype html>
<html>
<head>
    <title>Example Domain</title>
    ...
</head>
<body>
<div>
    <h1>Example Domain</h1>
    <p>This domain is for use in illustrative examples in documents. You may use this
    domain in examples without prior coordination or asking for permission.</p>
    ...
</div>

In this example, we used the telnet command to connect to the web server running on www.example.com on port 80. We then manually sent an HTTP GET request to the server and received the response.

The telnet command can be used to connect to various types of servers, not just web servers. For example, you can use it to connect to an FTP server, an email server, or any other network service that uses a TCP/IP protocol.

Troubleshoot Network Connectivity with the telnet Command

In this step, you will learn how to use the telnet command to troubleshoot network connectivity issues.

One common use case for the telnet command is to test the connectivity to a specific port on a remote server. This can help you identify if a network service is running and accessible.

Let's try connecting to a web server on port 80:

$ telnet www.example.com 80

Example output:

Trying 93.184.216.34...
Connected to www.example.com.
Escape character is '^]'.

In this case, the connection was successful, indicating that the web server is running and accessible on port 80.

Now, let's try connecting to a port that is not open:

$ telnet www.example.com 8080

Example output:

Trying 93.184.216.34...
telnet: Unable to connect to remote host: Connection refused

The "Connection refused" message indicates that there is no service listening on port 8080 on the remote server.

You can also use the telnet command to test the connectivity to a specific IP address or hostname, without specifying a port. This can help you determine if the network connection is working at all:

$ telnet www.example.com

Example output:

Trying 93.184.216.34...
telnet: Unable to connect to remote host: No route to host

In this case, the "No route to host" message indicates that there is a problem with the network connection, and the remote host is not accessible.

By using the telnet command to test connectivity to different ports and hosts, you can quickly identify where the network issue might be occurring, whether it's a problem with the remote server, the network infrastructure, or your own network connection.

Summary

In this lab, you learned about the purpose and basic syntax of the telnet command in Linux. The telnet command is a network protocol used to establish a connection to a remote server or device over a TCP/IP network. You also learned how to connect to a remote server using the telnet command, which can be useful for troubleshooting network connectivity issues, testing services, or accessing remote systems. Finally, you explored how to use the telnet command to troubleshoot network connectivity by testing the connection to a remote server.

Linux Commands Cheat Sheet

Other Linux Tutorials you may like