Unix 简明教程
Unix / Linux - Network Communication Utilities
在本章中,我们将详细讨论 Unix 中的网络通信实用程序。在分布式环境中工作时,您需要与远程用户通信,还需要访问远程 Unix 计算机。
In this chapter, we will discuss in detail about network communication utilities in Unix. When you work in a distributed environment, you need to communicate with remote users and you also need to access remote Unix machines.
有多种 Unix 实用程序可以帮助用户在联网的分布式环境中进行计算。本章列举了几种实用程序。
There are several Unix utilities that help users compute in a networked, distributed environment. This chapter lists a few of them.
The ping Utility
ping 命令向网络上可用的主机发送回显请求。使用此命令,您可以查看远程主机是否响应良好。
The ping command sends an echo request to a host available on the network. Using this command, you can check if your remote host is responding well or not.
ping 命令对以下内容很有用 −
The ping command is useful for the following −
-
Tracking and isolating hardware and software problems.
-
Determining the status of the network and various foreign hosts.
-
Testing, measuring, and managing networks.
Syntax
以下是使用 ftp 命令的简单语法 −
Following is the simple syntax to use the ftp command −
$ping hostname or ip-address
上述命令在每秒之后开始打印响应。要退出命令,您可以按 CNTRL + C 键来终止命令。
The above command starts printing a response after every second. To come out of the command, you can terminate it by pressing CNTRL + C keys.
Example
以下是一个检查网络上可用的主机是否可用的示例 −
Following is an example to check the availability of a host available on the network −
$ping google.com
PING google.com (74.125.67.100) 56(84) bytes of data.
64 bytes from 74.125.67.100: icmp_seq = 1 ttl = 54 time = 39.4 ms
64 bytes from 74.125.67.100: icmp_seq = 2 ttl = 54 time = 39.9 ms
64 bytes from 74.125.67.100: icmp_seq = 3 ttl = 54 time = 39.3 ms
64 bytes from 74.125.67.100: icmp_seq = 4 ttl = 54 time = 39.1 ms
64 bytes from 74.125.67.100: icmp_seq = 5 ttl = 54 time = 38.8 ms
--- google.com ping statistics ---
22 packets transmitted, 22 received, 0% packet loss, time 21017ms
rtt min/avg/max/mdev = 38.867/39.334/39.900/0.396 ms
$
如果主机不存在,您将收到以下输出 −
If a host does not exist, you will receive the following output −
$ping giiiiiigle.com
ping: unknown host giiiiigle.com
$
The ftp Utility
这里 ftp 代表 文件传输协议。此实用程序可帮助您将文件从一台计算机上载或下载到另一台计算机。
Here, ftp stands for *F*ile *T*ransfer *P*rotocol. This utility helps you upload and download your file from one computer to another computer.
ftp 实用程序有自己的一组类 Unix 命令。这些命令可帮助您执行以下任务 −
The ftp utility has its own set of Unix-like commands. These commands help you perform tasks such as −
-
Connect and login to a remote host.
-
Navigate directories.
-
List directory contents.
-
Put and get files.
-
Transfer files as ascii, ebcdic or binary.
Syntax
以下是使用 ftp 命令的简单语法 −
Following is the simple syntax to use the ftp command −
$ftp hostname or ip-address
上述命令将提示您输入登录 ID 和密码。一旦通过身份验证,您便可以访问登录帐户的主目录,并能够执行多种命令。
The above command would prompt you for the login ID and the password. Once you are authenticated, you can access the home directory of the login account and you would be able to perform various commands.
下表列出了几个重要命令 −
The following tables lists out a few important commands −
Sr.No. |
Command & Description |
1 |
put filename Uploads filename from the local machine to the remote machine. |
2 |
get filename Downloads filename from the remote machine to the local machine. |
3 |
mput file list Uploads more than one file from the local machine to the remote machine. |
4 |
mget file list Downloads more than one file from the remote machine to the local machine. |
5 |
prompt off Turns the prompt off. By default, you will receive a prompt to upload or download files using mput or mget commands. |
6 |
prompt on Turns the prompt on. |
7 |
dir Lists all the files available in the current directory of the remote machine. |
8 |
cd dirname Changes directory to dirname on the remote machine. |
9 |
lcd dirname Changes directory to dirname on the local machine. |
10 |
quit Helps logout from the current login. |
应该注意的是,所有文件都将下载或上传到当前目录或从当前目录下载或上传。如果您想要将文件上传到特定目录,则需要首先切换到该目录,然后再上传所需的文件。
It should be noted that all the files would be downloaded or uploaded to or from the current directories. If you want to upload your files in a particular directory, you need to first change to that directory and then upload the required files.
Example
下面是显示一些命令的工作原理的示例 −
Following is the example to show the working of a few commands −
$ftp amrood.com
Connected to amrood.com.
220 amrood.com FTP server (Ver 4.9 Thu Sep 2 20:35:07 CDT 2009)
Name (amrood.com:amrood): amrood
331 Password required for amrood.
Password:
230 User amrood logged in.
ftp> dir
200 PORT command successful.
150 Opening data connection for /bin/ls.
total 1464
drwxr-sr-x 3 amrood group 1024 Mar 11 20:04 Mail
drwxr-sr-x 2 amrood group 1536 Mar 3 18:07 Misc
drwxr-sr-x 5 amrood group 512 Dec 7 10:59 OldStuff
drwxr-sr-x 2 amrood group 1024 Mar 11 15:24 bin
drwxr-sr-x 5 amrood group 3072 Mar 13 16:10 mpl
-rw-r--r-- 1 amrood group 209671 Mar 15 10:57 myfile.out
drwxr-sr-x 3 amrood group 512 Jan 5 13:32 public
drwxr-sr-x 3 amrood group 512 Feb 10 10:17 pvm3
226 Transfer complete.
ftp> cd mpl
250 CWD command successful.
ftp> dir
200 PORT command successful.
150 Opening data connection for /bin/ls.
total 7320
-rw-r--r-- 1 amrood group 1630 Aug 8 1994 dboard.f
-rw-r----- 1 amrood group 4340 Jul 17 1994 vttest.c
-rwxr-xr-x 1 amrood group 525574 Feb 15 11:52 wave_shift
-rw-r--r-- 1 amrood group 1648 Aug 5 1994 wide.list
-rwxr-xr-x 1 amrood group 4019 Feb 14 16:26 fix.c
226 Transfer complete.
ftp> get wave_shift
200 PORT command successful.
150 Opening data connection for wave_shift (525574 bytes).
226 Transfer complete.
528454 bytes received in 1.296 seconds (398.1 Kbytes/s)
ftp> quit
221 Goodbye.
$
The telnet Utility
有时候我们需要连接到远程 Unix 计算机并在该计算机上远程工作。 Telnet 是一个实用程序,允许某个位置的计算机用户建立连接、登录,然后在另一位置的计算机上工作。
There are times when we are required to connect to a remote Unix machine and work on that machine remotely. Telnet is a utility that allows a computer user at one site to make a connection, login and then conduct work on a computer at another site.
使用 Telnet 登录后,您可以在远程连接的计算机上执行所有活动。以下是 Telnet 会话示例 −
Once you login using Telnet, you can perform all the activities on your remotely connected machine. The following is an example of Telnet session −
C:>telnet amrood.com
Trying...
Connected to amrood.com.
Escape character is '^]'.
login: amrood
amrood's Password:
*****************************************************
* *
* *
* WELCOME TO AMROOD.COM *
* *
* *
*****************************************************
Last unsuccessful login: Fri Mar 3 12:01:09 IST 2009
Last login: Wed Mar 8 18:33:27 IST 2009 on pts/10
{ do your work }
$ logout
Connection closed.
C:>
The finger Utility
finger 命令显示关于指定主机上用户的信息。该主机可以是本地或远程主机。
The finger command displays information about users on a given host. The host can be either local or remote.
由于安全原因,其他系统上的 Finger 命令可能被禁用。
Finger may be disabled on other systems for security reasons.
以下是使用 finger 命令的简单语法 −
Following is the simple syntax to use the finger command −
查看本地计算机上所有已登录的用户 −
Check all the logged-in users on the local machine −
$ finger
Login Name Tty Idle Login Time Office
amrood pts/0 Jun 25 08:03 (62.61.164.115)
获取本地计算机上特定可用用户的详细信息 −
Get information about a specific user available on the local machine −
$ finger amrood
Login: amrood Name: (null)
Directory: /home/amrood Shell: /bin/bash
On since Thu Jun 25 08:03 (MST) on pts/0 from 62.61.164.115
No mail.
No Plan.
查看远程计算机上所有已登录的用户 −
Check all the logged-in users on the remote machine −
$ finger @avtar.com
Login Name Tty Idle Login Time Office
amrood pts/0 Jun 25 08:03 (62.61.164.115)
获取远程计算机上特定可用用户的详细信息 −
Get the information about a specific user available on the remote machine −
$ finger amrood@avtar.com
Login: amrood Name: (null)
Directory: /home/amrood Shell: /bin/bash
On since Thu Jun 25 08:03 (MST) on pts/0 from 62.61.164.115
No mail.
No Plan.