Linux Network Administrator's Guide翻译1.2.6~1.2.8
时间:2007-02-06 来源:gadfly0217
1.2.6. The Transmission Control Protocol(TCP)
Sending datagrams from one host to another is not the whole story. If you log in to quark, you want to have a reliable(可靠的) connection between your ssh process on erdos and the shell process on quark. Thus, the information sent to and from must be split into packets by the sender and reassembled into a character stream by the receiver. Trivial as it seems, this involves a number of complicated tasks.
A very important thing to know about IP is that, by intent, it is not reliable. Assume that 10 people on your Ethernet started downloading the latest release of the Mozilla web browser source code from GMU's FTP server. The amount of traffic generated might be too much for the gateway to handle because it's too slow and it's tight on memory. Now if you happen to send a packet to quark, sophus might be out of buffer space for a moment and therefore unable to forward it. IP solves this problem by simply discarding it. The packet is irrevocably lost. It is therefore the responsibility of the communicating hosts to check the integrity and completeness of the data and retransmit it in case of error.
This process is performed by yet another protocol, Transmission Control Protocol (TCP), which builds a reliable service on top of IP. The essential property of TCP is that it uses IP to give you the illusion of a simple connection between the two processes on your host and the remote machine so that you don't have to care about how and along which route your data actually travels. A TCP connection works essentially like a two-way pipe that both processes may write to and read from. Think of it as a telephone conversation.
TCP identifies the end points of such a connection by the IP addresses of the two hosts involved and the number of a port on each host.(TCP通过两台主机的IP地址和端口号来标志链接的结束) Ports may be viewed as attachment points for network connections. (可以把端口看成网络链接的附属点)If we are to strain the telephone example a little more, and you imagine that cities are like hosts(把主机看成城市), one might compare IP addresses to area codes (把IP地址看成城市区号)(where numbers map to cities), and port numbers to local codes (把端口号看成当地号码)(where numbers map to individual people's telephones). An individual host may support many different services, each distinguished by its own port number.(主机支持很多服务,每个服务对应一个端口)
In the ssh example, the client application (ssh) opens a port on erdos and connects to port 22 on quark, to which the sshd server is known to listen. This action establishes a TCP connection. Using this connection, sshd performs the authorization procedure and then spawns the shell. The shell's standard input and output are redirected to the TCP connection so that anything you type to ssh on your machine will be passed through the TCP stream and be given to the shell as standard input.
1.2.7. The User Datagram Protocol
Of course, TCP isn't the only user protocol in TCP/IP networking. Although suitable for applications like ssh, the overhead involved is prohibitive for applications like NFS, which instead uses a sibling(同胞) protocol of TCP called User Datagram Protocol (UDP). Just like TCP, UDP allows an application to contact a service on a certain port of the remote machine, but it doesn't establish a connection for this. Instead, you use it to send single packets to the destination service hence its name.
Assume that you want to request a small amount of data from a database server. It takes at least three datagrams to establish a TCP connection, another three to send and confirm a small amount of data each way, and another three to close the connection. UDP provides us with a means of using only two datagrams to achieve almost the same result. UDP is said to be connectionless(无链接), and it doesn't require us to establish and close a session(建立和关闭会话). We simply put our data into a datagram and send it to the server; the server formulates its reply, puts the data into a datagram addressed back to us, and transmits it back. While this is both faster and more efficient than TCP for simple transactions, UDP was not designed to deal with datagram loss. It is up to the application, a nameserver, for example, to take care of this.
1.2.8. More on Ports
Ports may be viewed as attachment points for network connections. If an application wants to offer a certain service, it attaches itself to a port and waits for clients (this is also called listening on the port(监听端口)). A client who wants to use this service allocates a port on its local host and connects to the server's port on the remote host. The same port may be open on many different machines, but on each machine only one process can open a port at any one time.
An important property of ports is that once a connection has been established between the client and the server, another copy of the server may attach to the server port and listen for more clients. This property permits, for instance, several concurrent remote logins to the same host, all using the same port 513. TCP is able to tell these connections from one another because they all come from different ports or hosts(TCP可以区分这些链接,因为它们来自不同的端口和主机). For example, if you log in twice to quark from erdos, the first ssh client may use the local port 6464, and the second one could use port 4235. Both, however, will connect to the same port 513 on quark. The two connections will be distinguished by use of the port numbers used at erdos.
This example shows the use of ports as rendezvous points, where a client contacts a specific port to obtain a specific service. In order for a client to know the proper port number, an agreement has to be reached between the administrators of both systems on the assignment of these numbers. For services that are widely used, such as ssh, these numbers have to be administered centrally. This is done by the Internet Engineering Task Force (IETF), which regularly releases an RFC titled Assigned Numbers (RFC-1700). It describes, among other things, the port numbers assigned to well-known services. Linux uses a file called /etc/services that maps service names to numbers.
It is worth noting that, although both TCP and UDP connections rely on ports, these numbers do not conflict. This means that TCP port 22, for example, is different from UDP port 22.
Sending datagrams from one host to another is not the whole story. If you log in to quark, you want to have a reliable(可靠的) connection between your ssh process on erdos and the shell process on quark. Thus, the information sent to and from must be split into packets by the sender and reassembled into a character stream by the receiver. Trivial as it seems, this involves a number of complicated tasks.
A very important thing to know about IP is that, by intent, it is not reliable. Assume that 10 people on your Ethernet started downloading the latest release of the Mozilla web browser source code from GMU's FTP server. The amount of traffic generated might be too much for the gateway to handle because it's too slow and it's tight on memory. Now if you happen to send a packet to quark, sophus might be out of buffer space for a moment and therefore unable to forward it. IP solves this problem by simply discarding it. The packet is irrevocably lost. It is therefore the responsibility of the communicating hosts to check the integrity and completeness of the data and retransmit it in case of error.
This process is performed by yet another protocol, Transmission Control Protocol (TCP), which builds a reliable service on top of IP. The essential property of TCP is that it uses IP to give you the illusion of a simple connection between the two processes on your host and the remote machine so that you don't have to care about how and along which route your data actually travels. A TCP connection works essentially like a two-way pipe that both processes may write to and read from. Think of it as a telephone conversation.
TCP identifies the end points of such a connection by the IP addresses of the two hosts involved and the number of a port on each host.(TCP通过两台主机的IP地址和端口号来标志链接的结束) Ports may be viewed as attachment points for network connections. (可以把端口看成网络链接的附属点)If we are to strain the telephone example a little more, and you imagine that cities are like hosts(把主机看成城市), one might compare IP addresses to area codes (把IP地址看成城市区号)(where numbers map to cities), and port numbers to local codes (把端口号看成当地号码)(where numbers map to individual people's telephones). An individual host may support many different services, each distinguished by its own port number.(主机支持很多服务,每个服务对应一个端口)
In the ssh example, the client application (ssh) opens a port on erdos and connects to port 22 on quark, to which the sshd server is known to listen. This action establishes a TCP connection. Using this connection, sshd performs the authorization procedure and then spawns the shell. The shell's standard input and output are redirected to the TCP connection so that anything you type to ssh on your machine will be passed through the TCP stream and be given to the shell as standard input.
1.2.7. The User Datagram Protocol
Of course, TCP isn't the only user protocol in TCP/IP networking. Although suitable for applications like ssh, the overhead involved is prohibitive for applications like NFS, which instead uses a sibling(同胞) protocol of TCP called User Datagram Protocol (UDP). Just like TCP, UDP allows an application to contact a service on a certain port of the remote machine, but it doesn't establish a connection for this. Instead, you use it to send single packets to the destination service hence its name.
Assume that you want to request a small amount of data from a database server. It takes at least three datagrams to establish a TCP connection, another three to send and confirm a small amount of data each way, and another three to close the connection. UDP provides us with a means of using only two datagrams to achieve almost the same result. UDP is said to be connectionless(无链接), and it doesn't require us to establish and close a session(建立和关闭会话). We simply put our data into a datagram and send it to the server; the server formulates its reply, puts the data into a datagram addressed back to us, and transmits it back. While this is both faster and more efficient than TCP for simple transactions, UDP was not designed to deal with datagram loss. It is up to the application, a nameserver, for example, to take care of this.
1.2.8. More on Ports
Ports may be viewed as attachment points for network connections. If an application wants to offer a certain service, it attaches itself to a port and waits for clients (this is also called listening on the port(监听端口)). A client who wants to use this service allocates a port on its local host and connects to the server's port on the remote host. The same port may be open on many different machines, but on each machine only one process can open a port at any one time.
An important property of ports is that once a connection has been established between the client and the server, another copy of the server may attach to the server port and listen for more clients. This property permits, for instance, several concurrent remote logins to the same host, all using the same port 513. TCP is able to tell these connections from one another because they all come from different ports or hosts(TCP可以区分这些链接,因为它们来自不同的端口和主机). For example, if you log in twice to quark from erdos, the first ssh client may use the local port 6464, and the second one could use port 4235. Both, however, will connect to the same port 513 on quark. The two connections will be distinguished by use of the port numbers used at erdos.
This example shows the use of ports as rendezvous points, where a client contacts a specific port to obtain a specific service. In order for a client to know the proper port number, an agreement has to be reached between the administrators of both systems on the assignment of these numbers. For services that are widely used, such as ssh, these numbers have to be administered centrally. This is done by the Internet Engineering Task Force (IETF), which regularly releases an RFC titled Assigned Numbers (RFC-1700). It describes, among other things, the port numbers assigned to well-known services. Linux uses a file called /etc/services that maps service names to numbers.
It is worth noting that, although both TCP and UDP connections rely on ports, these numbers do not conflict. This means that TCP port 22, for example, is different from UDP port 22.
相关阅读 更多 +