Linux's Common network commands _unix Linux

Source: Internet
Author: User
Tags anonymous file copy ftp ftp commands ftp site hash file transfer protocol ftp transfer

The main advantage of computer network is that it can realize the sharing of resources and information, and users can access information remotely. Linux provides a powerful set of network commands to serve users, which can help users log on to remote computers, transfer files, and execute remote commands. Describes the following common commands for network operations:

FTP Transfer files

Telnet Log on to the remote computer

R-Using various remote commands

Netstat view the status of the network

nslookup query domain name and IP address of the corresponding

Finger queries a user for information

Ping to inquire if a machine is working

Remote file transfer using the FTP command

The FTP command is the user interface for a standard file transfer protocol. FTP is a simple and efficient way to transfer files between computers on a TCP/IP network. It allows the user to transfer both ASCII and binary files. During an FTP session, a user can connect to another computer by using an FTP client. From there, users can move up and down the directory, list the contents of the directory, copy the files from the remote machine to the local machine, and transfer the files from the local machine to the remote system.

It should be noted that if the user does not have access to that file, they cannot obtain files from the remote system or transfer files to the remote system. In order to transfer files using FTP, the user must know the legitimate user name and password on the remote computer. This combination of username/password is used to confirm the FTP session and to determine what access the user can make to the file to be transferred. In addition, the user obviously needs to know the name or IP address of the computer on which the FTP session is being made.

The function of the FTP command is to transfer files between the local machine and the remote computer. The general format of the command is as follows:

$ FTP host name/IP

WHERE "hostname/IP" is the host name or IP address of the remote machine to which you want to connect. On the command line, the host name is an option, and if you specify a host name, FTP will attempt to connect to the remote computer's FTP service program, and if no host name is specified, FTP will give a prompt waiting for the user to enter the command: $ ftp ftp > at ftp> Prompt to enter the Open command plus the host name or IP address, you will attempt to connect to the specified host. Whichever method you use, if the connection succeeds, you need to log on to the remote machine. If the user has an account number on the remote machine, he or she can use the account via FTP and need to provide a password.

The read and write permissions on the user account on the remote machine determine what files the user can download on the remote machine and which directory to put the uploaded files in. If you do not have a dedicated logon account for a remote computer, many FTP sites have special accounts that you can use. This account's login name is anonymous (also known as anonymous FTP), when using this account, the request input email address as password. If the remote system provides anonymous FTP services, users can use this service to log on to a special directory for public use.

Generally provides two directories: Pub directory and incoming directory. The pub directory contains all the files that the site is intended for public use, and the incoming directory holds the files uploaded to that site. Once the user logs on at the remote site using FTP, a "ftp>" prompt is obtained. You are now free to use the commands provided by FTP, you can use the help command to obtain a list of available commands, or you can specify a specific command name after the help command to obtain a description of the command.

The most commonly used commands are:

LS lists the current directory of the remote machine

CD changes working directory on remote machine

LCD changes working directory on the Local machine

ASCII setting file transfer mode to ASCII mode

Binary set file transfer mode to binary mode

Close terminates the current FTP session

Hash displays a # number each time the data in the data buffer is transmitted

Get (mget) transfer the specified file from the remote machine to the local machine

Put (mput) transfer the specified file from the local machine to the remote machine

Open Connection Remote FTP site

Quit disconnect from the remote machine and exit FTP

? Display local Help information

! Go to the shell

The following simple FTP commonly used commands as a brief introduction.

Start the FTP session The Open command is used to open a session with a remote host. The general format for this command is:


Open Host name/IP if you want to connect to more than one site during an FTP session, you typically use only FTP commands with no parameters. If you want to connect to only one computer during a session, specify the remote host name or IP address as an argument to the FTP command on the command line.


Terminating the FTP session close, disconnect, quit, and bye commands are used to terminate a session with a remote machine. The close and Disronnect commands turn off the connection to the remote machine, but use the user to stay in the FTP program on the local computer. The Quit and bye commands both shut down the user's connection to the remote machine and then quit the FTP program on the user's computer.


Changing the directory "CD [directory]" command to change the directory on the remote computer during an FTP session, the LCD command changes the local directory, allowing the user to specify where to locate or place the local file. Remote directory list The LS command lists the contents of a remote directory as if it were using the LS command in an interactive shell.

The general format of the LS command is: ls [directory] [local file] If the directory is specified as an argument, then LS lists the contents of the directory. If you give the name of a local file, the directory list is placed on the local computer in the file you specify.

Getting files from the remote system get and Mget commands are used to get files from the remote machine. The general format for the GET command is:

Get file name you can also give a local filename, which is the file name of the file you want to get when it was created on your local machine. If you do not give a local filename, use the original name of the remote file. The mget command gets more than one remote file at a time.

The general format for the Mget command is: The list of mget file names uses a space-delimited or wildcard list of file names to specify the files to get, and for each of these files, the user is required to confirm that they are being routed.

Sending files to a remote system put and Mput commands are used to send files to a remote machine.

The general format of the put command is: Put file name mput command to send multiple local files at a time,

The general format for the Mput command is: The mput file name list uses a space-delimited or wildcard list of file names to specify which files to send. Each of these files requires the user to confirm whether to send them.

Change file transfer mode: By default, FTP transfers files in ASCII mode, and users can specify other modes.

The function of the ASCII and Brinary commands is to set the mode of transmission. Transferring files in ASCII mode is very good for plain text, but in order to avoid the destruction of binary files, users can transfer files in binary mode.

Check transport status: When transferring large files, it may be useful to have FTP provide feedback about the transmission. The hash command causes FTP to print a # character on the screen after each transmission of data in the data buffer. This command can be used when sending and receiving files.

Local commands in FTP when you use FTP, the character "!" Used to send a command to the command shell on the local machine. If the user is in an FTP session, it is useful to have the shell do something. For example, a user would like to create a directory to hold the received file. If you enter!mkdir New_dir, Linux creates a directory named New_dir in the user's current local directory.

The typical dialog process for downloading binary data files from a remote machine Grunthos is as follows:

$ ftp Grunthos Connected to grunthos grunthos FTP server Name (GRUNTHOS:PC): Anonymous 33l Guest login OK, send your C Omplete e-mail address as password. password:230 Guest 1ogin OK, access restrictions apply. Remote system type is UNIX. FTP > CD Pub CWD command successful. FTP > LS PORT command successful. L50 opening ASCII mode data connection for/bin/1s. Total Ll4 rog1 rog2 Transfer comp1ete. FTP > binary type set to I. FTP > HASHED hash mark printing on (1024 bytes/hash mark). FTP > Get rog1 PORT command successfu1. Opening BINARY mode data connection for ROGL (l4684 bytes). 14684 bytes received in 0.0473 secs (3e + kbytes/sec) ftp > Quit 22l Goodbye.

Accessing a remote computer using the Telnet command

The user uses the Telnet command to log on remotely. This command allows users to use the Telnet protocol to communicate between remote computers, and users can log on to a remote computer over the network, as if they were logged on to the local machine to execute commands. In order to log on to a remote computer by Telnet, you must know the legal user name and password on the remote machine. Although some systems do provide logon capabilities for remote users, the ability to use them is limited for security reasons, so there are few features that can be used in this case. When remote users are allowed to log on, the system typically places these users in a restricted shell to prevent the system from being compromised by malicious or careless users. Users can also use Telnet to log on to their computers from remote sites, check e-mail, edit files, and run programs as if they were logged on locally.

However, users can only use a terminal-based environment rather than an X-wndows environment, and Telnet only provides terminal emulation for the common terminal, and does not support graphics environments such as X Wndow.


The general form of the Telnet command is: telnet hostname/IP, where "hostname/IP" is the host name or address of the remote machine to which you want to connect. If this command succeeds, the login: prompt will be obtained from the remote machine.

The procedure for logging in using the Telnet command is as follows: $ telnet host name/IP starts the telnet session. Once Telnet is successfully connected to the remote system, the login information is displayed and the user is prompted to lose the user name and password. If the username and password are entered correctly, you can log on successfully and work on the remote system. You can enter many commands after the Telnet prompt to control the Telnet session process, which is described in detail in the Telnet online Help manual.

The following is an example of a Telnet session on a Linux computer:

$ telnet Server. Somewhere. com trying 127.0.0.1 ... Connected to serve. Somewhere. com. Escape character is \ '?] \'. "Turbolinux Release 4. 0 (Colgate)
Kernel 2.0.18 on a I486
Login:bubba password:last Login:mon Nov L5 20:50:43 for localhost Linux 2. 0.6. (Posix). Server: ~$ server: ~$ logout Connection closed by foreign host $

After the user finishes the remote session, be sure to use the logout command to exit the remote system. Telnet then reports that the remote session was closed and returned to the user's local machine's shell prompt.

R-Series commands can also use the R-Series command to access remote computers and Exchange files on the network, in addition to FTP and Telnet. Using the R-Series commands requires special attention, because if the user is not careful, it can cause serious security vulnerabilities. After the user issues a R-series command, the remote system checks the file named/etc/hosts.equiv to see if the user's host is listed in this file. If it does not find the user's host, check the home directory of the user with the same name on the remote machine named. Rhosts the file to see if the user's host is included. If the user's host is included in any of these two files, the user does not have to provide a password to execute the R-series command.

Although it may be convenient for a user to not type a password each time they access a remote machine, it can also cause serious security problems. We recommend that users carefully consider the security implications of the R-command before establishing/ETC/HOSTS.EQUIV and. rhosts files.

Rlogin command

Rlogin is the abbreviation for remote login (remote login). This command is similar to the Telnet command, allowing the user to initiate an interactive command session on a remote system. The general format of the rlogin is:
rlogin [ -8EKLDX] [-e char] [-K realm] [-l username] Host

The most commonly used format is: Rlogin host the options in this command have the meanings:

-8 This option always allows 8-bit input data channels. This option allows you to send formatted ANSI characters and other special code. If you do not use this option, the parity bit is removed unless the end and start characters are not OR.

-e stops treating any character as an escape character. When used with the-8 option, it provides a fully transparent connection.

-K closes all Kerberos confirmations. This option is only used if you are connected to a host that uses the Kerberos acknowledgement protocol.

-L allows the rlogin session to run in Litout mode. For more information, see the TTY online Help.

-D open socket debugging for TCP sockets that communicates with the remote host. For more information, consult the setsockopt online Help.

-E Sets the escape character for the rlogin session, the default escape character is "~", and the user can specify a literal character or a \\nnn form of octal number.

-K requests Rlogin to obtain the Kerberos license of the remote host within the specified zone, instead of obtaining the Kerberos license of the remote host within the remote host zone determined by Krb_realmofhost (3).

-X opens DES encryption for all data transmitted through the Rlogin session. This affects response time and CPU utilization, but can improve security.

RSH command

RSH is the abbreviation for remote shell. This command launches a shell on the specified remote host and executes the command specified by the user on the rsh command line. If the user does not give a command to execute, RSH uses the rlogin command to log the user on to the remote machine.

The general format of the RSH command is:

RSH [-kdnx] [-K realm] [-l username] host [command]

The usual format is:

RSH host [command]

command can be any Linux command that is a key person from the shell prompt.

The options in the RSH command have the following meanings:

-K closes all Kerbero confirmations. This option is only used when connecting with a host that is confirmed with Kerbero.

-D open socket debugging for TCP sockets that communicates with the remote host. For more information, consult the setsockopt online Help.

-K requests Rsh to obtain the Kerberos license of the remote host within the specified zone, instead of obtaining the Kerberos license of the remote host within the remote host zone determined by Krb_relmofhost (3).

-L By default, the remote user name is the same as the local user name. This option allows you to specify a remote user name and, if a remote username is specified, use Kerberos acknowledgement, as in the Rlogin command.

-n redirects input from special device/dev/null.

-X opens DES encryption for all data that is transferred. This affects response time and CPU utilization, but can improve security.

Linux puts the standard input into the RSH command and copies it to the standard input of the command to be executed remotely. It copies the standard output of the remote command to the standard output of the rsh. It also copies the remote standard error to the local standard error file. Any exit, abort, and interrupt signals are sent to the remote command. When the remote command is terminated, the rsh is terminated.

rcp command

RCP represents "Remote file copy". This command is used to copy files between computers.

The RCP command has two formats. The first format is used to copy files to files, and the second format is used to copy files or directories to another directory.

The general format of the RCP command is:

rcp [-px] [k realm] File1 file2 rcp [-px] [-R] [-K Realm] File

Directory each file or directory parameter can be either a remote file name or a local file name. The remote file name has the following form: Rname@rhost:path, where rname is the remote user name, Rhost is the remote computer name, and path is the pathname of the file.

The options for the RCP command have the following meanings:

-R recursively copies all content in the source directory to the destination directory. To use this option, the purpose must be a directory.

-P attempts to preserve the modification time and mode of the source file, ignoring umask.

-K requests RCP to obtain the Kerberos license of a remote host within a specified zone, rather than obtaining the Kerberos license of a remote host within the remote host zone determined by Krb_relmofhost (3).

-X opens DES encryption for all data that is transferred. This affects response time and CPU utilization, but can improve security. If the path specified in the filename is not a full pathname, the path is interpreted as the home directory of the user with the same name on the remote machine. If the remote user name is not given, the current username is used. If the path on the remote machine contains special shell characters, it needs to be surrounded by backslashes (\), double quotes ("), or single quotes (') so that all shell metacharacters can be interpreted remotely. It is important to note that RCP does not prompt for a password, and it performs a copy through the RSH command.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.