Learn a Linux command every day (58): telnet

Time:2021-4-29

Learn a Linux command every day (58): telnet

Yesterday’s recommendation:Learn a Linux command every day (57): cal

Command introduction

Telnet command is used to communicate with another host using telnet protocol. You can login and manage another host remotely. You can also confirm whether a port of the remote host is open through telnet? It is also an important part of daily network troubleshooting.

Grammatical format

telnet [OPTIONS] [host [port]
[host] remote host  # Specify the remote host to log in for management;
[port] port     # Specifies the port number used by the telnet protocol.

Option description

-4   # Force IPv4 address resolution
-6   # Force IPv6 address resolution
-a   # Try to log in to the remote host system automatically
-B < host alias >   # Use the specified remote host name
-c   # Do not read the. Telnetrc file in the user's exclusive directory
-d   # Start debugging mode
-E < escape character >   # Set breakaway character
-E   # Filter out detached characters
-K   # Do not automatically log on to the remote host
-L < user name >   # Specifies the user name to log on to the remote host
-L   # It is allowed to output 8-bit character data
-N < record file >   # Specify the file to record relevant information
-x   # If the host has the function of supporting data encryption, use it
-X < authentication form >   # Turn off the specified authentication mode

Telnet service configuration

Telnet service configuration is as follows:

#Generally, the parameters are configured as follows:
service telnet
{
    disable  =  no  # Enable
    flags  =  REUSE  # Socket reusable
    socket_ type  =  stream  # The connection mode is TCP
    wait  =  no  # Start a process for each request
    user  =  root  # The user who starts the service is root
    server  = / usr/sbin/in.telnetd  # Process to activate
    log_ on_ failure  +=  USERID  # Log in user name when login failed
}
 
#Configure the list of clients allowed to log in
only_ from  =  10.0.0.2  # Only 10.0.0.2 login allowed
 
#Configure the list of clients that are not allowed to log on
no_ access  =  10.0.0.{2,3,4}   # 10.08.0.2, 10.0.0.3, 10.0.0.4 login is prohibited
 
#Set opening hours
access_ times  =  9:00-12:00   13:00-17:00  #  Only these two hours are open every day
#Configure the user to log in to telnet service only from a certain address
bind = 10.0.0.2

Application examples

Try to open the connection with the remote host baidu.com

[[email protected] ~]# telnet www.baidu.com
Trying 36.152.44.96...

Try opening a connection to the remote host mingongget.com on port 9999 using the login name mingongge. If the connection is successful, you will be prompted to enter the password of mingongge

[[email protected] ~]# telnet -l mingongge mingongge.com 9999
Trying 104.164.133.141...

Check whether a port is open

[[email protected] ~]# telnet 127.0.0.1 22
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
SSH-2.0-OpenSSH_7.4
#The above information indicates that port 22 is open
#If the following prompt appears, the corresponding port is not open
[[email protected] ~]# telnet 127.0.0.1 80
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
[[email protected] ~]# telnet 127.0.0.1 9999
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused

Learn a Linux command every day (54): W

Learn a Linux command every day (55): ID

Learn a Linux command every day (56): Su / sudo