The main advantage of computer networks is the ability to share resources and information, and users can remotely access information. Linux provides a set of powerful network commands to serve users. These tools can help users log on to a remote computer, transfer files, and execute remote commands. This section describes the following commonly used network operation commands:
Ftp File Transfer
Telnet logon to a remote computer
R-use various remote commands
Netstat
Nslookup
Finger queries information of a user
Ping to check whether a machine is working
Use ftp commands for remote file transmission
The ftp command is the user interface of the standard file transfer protocol. Ftp is a simple and effective method for transferring files between computers on TCP/IP networks. It allows users to transmit ASCII and binary files. During an ftp session, you can use an ftp client program to connect to another computer. From then on, you can move up and down the directory, list the contents of the Directory, copy files from the remote machine to the local machine, and transmit files from the local machine to the remote system.
Note that if you do not have the permission to access the file, you cannot obtain the file from the remote system or transmit the file to the remote system. To use ftp to transfer files, you must know the valid user name and password on the remote computer. This user name/password combination is used to confirm the ftp session and determine the user's access to the file to be transferred. In addition, you obviously need to know the name or IP address of the computer on which the ftp session is performed.
The Ftp command transfers files between a local machine and a remote machine. The general format of this command is as follows:
$ Ftp host name/IP Address
The "host name/IP Address" is the host name or IP address of the remote machine to be connected. In the command line, the host name is an option. If the host name is specified, ftp tries to connect to the ftp service program of the remote machine. If the host name is not specified, ftp will give a prompt, wait for the user to enter the command: $ ftp> at this time, enter the open command and add the host name or IP address after the ftp> prompt to try to connect to the specified host. No matter which method is used, if the connection is successful, You need to log on to the remote machine. If you have an account on a remote machine, you can use this account through ftp and provide a password.
The read and write permissions of the user account on the remote machine determine what files the user can download and the directory to which the uploaded files are stored. If you do not have a dedicated Logon account for a remote machine, many ftp sites have special accounts that can be used. The login name of this account is anonymous (also known as anonymous ftp). When using this account, enter the email address as the password. If the remote system provides the anonymous ftp service, you can use this service to log on to a special directory for public use.
Generally, two directories are provided: pub directory and incoming directory. The pub directory contains all the files on the site for public use. The incoming directory stores the files uploaded to the site. Once the user successfully logs on to the remote site using ftp, the "ftp>" prompt is displayed. Now you can freely use 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 instructions on this command.
The most common commands are:
Ls to list the current directory of the remote machine
Cd changes the working directory on a remote machine
LCD changes the working directory on the local machine
Set the file transmission mode to ascii in ASCII mode.
Set the file transfer mode to binary.
Close to terminate the current ftp session
Each time the hash data is transmitted in the data buffer, A # number is displayed.
Get (mget) transfers specified files from a remote machine to a Local Machine
Put (mput) transfers the specified file from the local machine to the remote machine
Open connection to remote ftp site
Quit disconnects from the remote machine and exits ftp
? Display local help information
! Go to Shell
Below is a brief introduction to common ftp commands.
The open command for starting an ftp session is used to open a session with a remote host. The common format of this command is:
If the open host name/IP address needs to be connected to more than one site during an ftp session, only ftp commands without parameters are used. If you only want to connect to a computer during a session, specify the remote host name or IP address on the command line as the ftp command parameter.
The terminate ftp session close, disconnect, quit, and bye commands are used to terminate the session with the remote machine. Close and disronnect commands close the connection to the remote machine, but leave the user in the ftp program of the local computer. Both the quit and bye commands disable the connection between the user and the remote machine, and then exit the ftp program on the user machine.
The "cd [Directory]" command is used to change the directory on a remote machine during an ftp session. The LCD command changes the local directory so that you can specify the location for searching or storing local files. The remote directory list ls command lists the contents of the remote directory, just like 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 the parameter, ls will list the contents of this directory. If a local file name is provided, the directory list is put into the file you specified on the local machine.
The get and mget commands for obtaining files from the remote system are used to obtain files from the remote machine. The common format of the get command is:
You can also provide a local file name, which is the name of the file to be obtained when you create it on your local machine. If you do not provide a local file name, use the original name of the remote file. The mget command obtains multiple remote files at a time.
The general format of the mget command is: The mget file name list uses a space-separated or list of file names with wildcards to specify the files to be obtained. For each file, you must confirm whether to transfer the files.
Send the put and mput commands to the remote system to send files to the remote machine.
The general format of the Put command is: put file name mput Command sends multiple local files at a time,
The general format of the mput command is: The mput file name list uses a space-separated or wildcard file name list to specify the file to be sent. You are required to confirm whether to send each file.
Change file transmission mode: by default, ftp transfers files in ASCII mode. You can also specify other modes.
The ascii and brinary commands are used to set the transmission mode. Transferring files in ASCII mode is very good for plain text, but to avoid damages to binary files, users can transmit files in binary mode.
Check transfer status: When transferring large files, ftp may find it very useful to provide feedback on Transmission Conditions. The hash command enables ftp to print a # character on the screen after data in the data buffer is transmitted every time. This command can be used to send and receive files.
Local commands in ftp when you use ftp, the character "!" It is used to send a command to the command shell on the local machine. It is useful if a user is in an ftp session and needs shell to do something. For example, you need to create a directory to save the received files. If you enter! Mkdir new_dir, Linux creates a directory named new_dir in the user's local directory.
A typical dialog process for downloading binary data files from grunthos on a remote machine is as follows:
$ Ftp grunthos Connected to grunthos 220 grunthos ftp server Name (grunthos: pc): anonymous 33l Guest login OK, send your complete e-mail address as password. password: 230 Guest 1 ogin OK, access restrictions apply. remote system type is UNIX. ftp> cd pub 250 CWD command successful. ftp> ls 200 PORT command successful. l50 opening ASCII mode data connection for/bin/1 s. total ll4 rog1 rog2 226 Transfer comp1ete. ftp> binary 200 type set to I. ftp> hash Hash mark printing on (1024 bytes/hash mark ). ftp> get rog1 200 PORT command successfu1. 150 opening BINARY mode data connection for rogl (l4684 bytes ). ############ 226 Transfer complete. 14684 bytes encoded ed in 0.0473 secs (3e + 02 Kbytes/sec) ftp> quit 22l Goodbye.
Use telnet commands to access remote computers
Use the telnet command to log on remotely. This command allows you to use the telnet protocol to communicate between remote computers. you can log on to a remote computer over the network, just as you log on to a local machine and execute commands. To log on to the remote computer through telnet, you must know the valid user name and password on the remote computer. Although some systems do provide the logon function for remote users, the Operation permissions of guests must be restricted for security reasons. Therefore, in this case, few functions can be used. When remote users are allowed to log on, the system usually places these users in a restricted shell to prevent the system from being maliciously or accidentally damaged. You can also use telnet to log on from a remote site to your computer, check emails, edit files, and run programs, just like logging on locally.
However, you can only use the terminal-based environment instead of the X Wndows environment. telnet only provides terminal Simulation for common terminals, but does not support X Wndow and other graphical environments.
The telnet command is generally used as follows: telnet host name/IP, where "host name/IP" is the host name or IP address of the remote machine to be connected. If the command is successfully executed, the login: prompt will be obtained from the remote machine.
Use the telnet command to log on: $ telnet host name/IP address to start the telnet session. Once telnet is successfully connected to the remote system, the logon information is displayed and the user's username and password are prompted. If the username and password are entered correctly, you can successfully log on and work on the remote system. You can enter many commands at the end of the telnet prompt to control the telnet session process. These commands are 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 an iworkflow
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, make sure to use the logout command to exit the remote system. Telnet then reports that the remote session is disabled and returns to the Shell prompt of the user's local machine.
In addition to ftp and telnet, the r-series commands can also be used to access remote computers and exchange files on the network. Pay special attention to using the r-series commands, because serious security vulnerabilities may occur if you are not careful. After the user issues an r-series command, the remote system checks the file named/etc/hosts. equiv to check whether the user's host is listed in this file. If the user's host is not found, check the file named. rhosts in the home directory of the user with the same name on the remote machine to see if the user's host is included. If the user's host is included in either of these two files, the user does not need to provide a password when executing the r-series command.
Although it is very convenient for a user to access a remote machine without entering a password, it may also cause serious security problems. We recommend that you carefully consider the hidden security issues of the r-command before creating the/etc/hosts. equiv and. rhosts files.
Rlogin command
Rlogin is short for "remote login. This command is similar to the telnet command, allowing users to start interactive command sessions on the remote system. The general format of rlogin is:
Rlogin [-8 EKLdx] [-e char] [-k realm] [-l username] host
Generally, the most common format is: rlogin host. The meaning of each option in this command is:
-8 this option always allows an 8-bit input data channel. This option allows you to send formatted ANSI characters and other special code. If this option is not used, the parity bit is removed unless the remote termination and start character are not or.
-E stops using any character as an escape character. When used together with the-8 option, it provides a completely transparent connection.
-K to disable all Kerberos validation. This option is used only when it is connected to a host using the Kerberos validation protocol.
-L allows the rlogin session to run in litout mode. For more information, see the tty online help.
-D open the socket debugging of TCP sockets that communicates with the remote host. For more information, see the setsockopt online help.
-E: Set the escape character for the rlogin session. The default escape character is "~". You can specify a text character or an \ nnn octal number.
-K requests rlogin to obtain the Kerberos permission for the remote host in the specified region, instead of obtaining the Kerberos permission for the remote host in the remote host region determined by krb_realmofhost (3.
-X enables DES encryption for all data transmitted through the rlogin session. This affects response time and CPU utilization, but improves security.
Rsh command
Rsh is short for remote shell. This command starts a shell on the specified remote host and executes the command specified by the user in the rsh command line. If the user does not provide the command to be executed, rsh uses the rlogin command to log on to the remote machine.
The general format of the rsh command is:
Rsh [-Kdnx] [-k realm] [-l username] host [command]
The common format is:
Rsh host [command]
Command can be any Linux command from the shell prompt.
The meanings of the options in the rsh command are as follows:
-K to close all of the Maximo validation. This option is used only when it is connected to the host confirmed by using the o.
-D open the socket debugging of TCP sockets that communicates with the remote host. For more information, see the online help of setsockopt.
-K requests rsh to obtain the Kerberos permission for the remote host in the specified region, instead of obtaining the Kerberos permission for the remote host in the remote host region 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. If you specify a remote user name, use Kerberos to confirm, as in the rlogin command.
-N redirects the input from the special device/dev/null.
-X enables DES encryption for all transmitted data. This affects response time and CPU utilization, but improves security.
Linux puts the standard input into the rsh command and copies it to the standard input of the command to be remotely executed. It copies the standard output of remote commands to the standard output of rsh. It also copies remote standard errors to the local standard error file. All exit, stop, and interrupt signals are sent to remote commands. When the remote command is terminated, rsh is terminated.
Rcp command
Rcp stands for "remote file copy" (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. 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
Each file or directory parameter in directory can be either a remote file name or a local file name. The remote file name can be in the following format: rname @ rhost: path. rname indicates the remote user name, rhost indicates the remote computer name, and path indicates the path of the file.
The options of the rcp command are as follows:
-R Recursively copies all the content in the source directory to the target directory. To use this option, the object must be a directory.
-P tries to retain the modification time and mode of the source file, ignoring umask.
-K requests rcp to obtain Kerberos permission for the remote host in the specified region, instead of obtaining Kerberos permission for the remote host in the remote host region determined by krb_relmofhost (3.
-X enables DES encryption for all transmitted data. This affects response time and CPU utilization, but improves security. If the path specified in the file name is not the complete path name, the path is interpreted as the Home Directory of the user with the same name on the remote machine. If no remote user name is provided, the current user name is used. If the path on the remote machine contains special shell characters, it must be enclosed by a backslash (\), double quotation marks ("), or single quotation marks, allow remote interpretation of all shell metacharacters. It must be noted that the rcp does not prompt for a password. It uses the rsh command to execute the copy operation.