Linux and Unix telnet command
telnet [-468ELadr] [-S tos] [-b address] [-e escapechar] [-l user] [-n tracefile] [host [port]]
The telnet command is used for interactive communication with another host using the TELNET protocol. It begins in command mode, where it prints a telnet command prompt ("telnet>").
If telnet is invoked with a host argument, it performs an open command implicitly (see the Commands section below for details).
|-4||Force IPv4 address resolution.|
|-6||Force IPv6 address resolution.|
|-8||Request 8-bit operation. This causes an attempt to negotiate the TELNET BINARY option for both input and output. By default telnet is not "8-bit clean" (it does not recognize 8-bit character encodings such as Unicode).|
|-E||Disables the escape character functionality; that is, sets the escape character to "no character".|
|-L||Specifies an 8-bit data path on output. This causes the TELNET BINARY option to be negotiated on just output.|
|-a||Attempt automatic login. Currently, this sends the user name via the USER variable of the ENVIRON option if supported by the remote system. The username is retrieved via the getlogin system call.|
|-b address||Use bind on the local socket to bind it to a specific local address.|
|-d||Sets the initial value of the debug toggle to TRUE.|
|-r||Emulate rlogin. In this mode, the default escape character is a tilde. Also, the interpretation of the escape character is changed: an escape character followed by a dot causes telnet to disconnect from the remote host. A ^Z (Control-Z) instead of a dot suspends telnet, and a ^] (Control-Close Bracket, the default telnet escape character) generates a normal telnet prompt. These codes are accepted only at the beginning of a line.|
|-S tos||Sets the IP type-of-service (TOS) option for the telnet connection to the value tos.|
|-e escapechar||Sets the escape character to escapechar. If no character is supplied, no escape character will be used. Entering the escape character while connected causes telnet to drop to command mode.|
|-l user||Specify user as the user to log in as on the remote system. This is accomplished by sending the specified name as the USER environment variable, so it requires that the remote system support the TELNET ENVIRON option. This option implies the -a option, and may also be used with the open command.|
|-n tracefile||Opens tracefile for recording trace information. See the set tracefile command below.|
|host||Specifies a host to contact over the network.|
|port||Specifies a port number or service name to contact. If not specified, the telnet port (23) is used.|
Once a connection has been opened, telnet will attempt to enable the TELNET LINEMODE option. If this fails, then telnet will revert to one of two input modes: either "character at a time" or "old line by line" depending on what the remote system supports.
When LINEMODE is enabled, character processing is done on the local system, under the control of the remote system. When input editing or character echoing is to be disabled, the remote system will relay that information. The remote system will also relay changes to any special characters that happen on the remote system, so that they can take effect on the local system.
In "character at a time" mode, most text typed is immediately sent to the remote host for processing.
In "old line by line" mode, all text is echoed locally, and (normally) only completed lines are sent to the remote host. The "local echo character" (initially "^E") may be used to turn off and on the local echo (this would mostly be used to enter passwords without the password being echoed).
If the LINEMODE option is enabled, or if the localchars toggle is TRUE (the default for "old line by line"; see below), the user's quit, intr, and flush characters are trapped locally, and sent as TELNET protocol sequences to the remote side. If LINEMODE has ever been enabled, then the user's susp and eof are also sent as TELNET protocol sequences, and quit is sent as a TELNET ABORT instead of BREAK. There are options (see toggle autoflush and toggle autosynch, below) which cause this action to flush subsequent output to the terminal (until the remote host acknowledges the TELNET sequence) and flush previous terminal input (in the case of quit and intr).
The following telnet commands are available. Unique prefixes are understood as abbreviations.
|auth argument ...||The auth command controls the TELNET AUTHENTICATE protocol option. If telnet was compiled without authentication, the auth command will not be supported. Valid arguments are as follows:
|close||Close the connection to the remote host, if any, and return to command mode.|
|display argument ...||Display all, or some, of the set and toggle values (see below).|
|encrypt argument ...||The encrypt command controls the TELNET ENCRYPT protocol option. If telnet was compiled without encryption, the encrypt command will not be supported.
Valid arguments are as follows:
|environ arguments...||The environ command is used to propagate environment variables across the telnet link using the TELNET ENVIRON protocol option. All variables exported from the shell are defined, but only the DISPLAY and PRINTER variables are marked to be sent by default. The USER variable is marked to be sent if the -a or -l command-line options were used.
Valid arguments for the environ command are:
|logout||Send the TELNET LOGOUT protocol option to the remote host. This command is similar to a close command. If the remote host does not support the LOGOUT option, nothing happens. But if it does, this command should cause it to close the connection. If the remote side also supports the concept of suspending a user's session for later reattachment, the logout command indicates that the session should be terminated immediately.|
|mode type||type is one of several options, depending on the state of the session. telnet asks the remote host to go into the requested mode. If the remote host says it can, that mode takes effect. Options for type are as follows:
|open host [[-l] user][- port]||Open a connection to the named host. If no port number is specified, telnet will attempt to contact a telnet daemon at the standard port (23). The host specification may be a host name or IP address. The -l option may be used to specify a user name to be passed to the remote system, like the -l command-line option.
When connecting to ports other than the telnet port, telnet does not attempt telnet protocol negotiations. This makes it possible to connect to services that do not support the telnet protocol without making a mess. Protocol negotiation can be forced by placing a dash before the port number.
After establishing a connection, any commands associated with the remote host in /etc/telnetrc and the user's .telnetrc file are executed, in that order.
The format of the telnetrc files is as follows: Lines beginning with a #, and blank lines, are treated as comments (ignored). The rest of the file should consist of hostnames and sequences of telnet commands to use with that host. Commands should be one per line, indented by whitespace; lines beginning without whitespace are interpreted as hostnames. Lines beginning with the special hostname ‘DEFAULT’ will apply to all hosts. Hostnames including ‘DEFAULT’ may be followed immediately by a colon and a port number or string. If a port is specified it must match exactly with what is specified on the command line. If no port was specified on the command line, then the value ‘telnet’ is used. Upon connecting to a particular host, the commands associated with that host are executed.
|quit||Close any open session and exit telnet. An end of file condition on input, when in command mode, will trigger this operation as well.|
|send arguments||Send one or more special telnet protocol character sequences to the remote host. The following are the codes which may be specified (more than one may be used in one command):
|set argument value, unset argument value||
The set command will set any one of a number of telnet variables to a specific value or to TRUE. The special value off turns off the function associated with the variable. This is equivalent to using the unset command. The unset command will disable or set to FALSE any of the specified variables. The values of variables may be interrogated with the display command. The variables which may be set or unset, but not toggled, are listed here. In addition, any of the variables for the toggle command may be explicitly set or unset.
|slc state||The slc command ("Set Local Characters") is used to set or change the state of the the special characters when the TELNET LINEMODE option has been enabled. Special characters are characters that get mapped to TELNET commands sequences (like ip or quit) or line editing characters (like erase and kill). By default, the local special characters are exported.
state may be one of the following:
|status||Show the current status of telnet. This includes the name of the remote host, if any, as well as the current mode.|
|toggle arguments ...||Toggle (between TRUE and FALSE) various flags that control how telnet responds to events. These flags may be set explicitly to TRUE or FALSE using the set and unset commands. More than one flag may be toggled at once. The state of these flags may be examined with the display command. Valid flags are:
|z||Suspend telnet. This command only works when the user is using the C Shell (csh).|
|! [command]||Execute a single command in a subshell on the local system. If command is omitted, then an interactive subshell is invoked.|
|? [command]||Get help. With no arguments, telnet prints a help summary. If a command is specified, telnet will print the help information for just that command.|
telnet uses at least the HOME, SHELL, DISPLAY, and TERM environment variables. Other environment variables may be propagated to the other side via the TELNET ENVIRON option.
|/etc/telnetrc||global telnet startup values|
|~/.telnetrc||user customized telnet startup values|
Attempts to open a connection to the remote host myhost.com. If a connection is established, the host will prompt for a login name and password.
telnet -l myusername myhost.com:5555
Attempts to open a connection to the remote host myhost.com on port 5555, using the login name myusername. If successful, the host will prompt for myusername's password.
Opens a local telnet> prompt, where you can enter any of the commands listed above. For example, entering the following command at the prompt:
telnet> open myhost.com
...will attempt to open a connection to myhost.com, as in our first example.