Learn a Linux command every day (58): telnet


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  =  # Only login allowed
#Configure the list of clients that are not allowed to log on
no_ access  =  10.0.0.{2,3,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 =

Application examples

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

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

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

Check whether a port is open

[[email protected] ~]# telnet 22
Connected to
Escape character is '^]'.
#The above information indicates that port 22 is open
#If the following prompt appears, the corresponding port is not open
[[email protected] ~]# telnet 80
telnet: connect to address Connection refused
[[email protected] ~]# telnet 9999
telnet: connect to address 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