客户端使用高端口号
为什么客户端会结束连接 使用高端口号(临时端口),而应用程序 监听通常较小的端口号?
谢谢你的优点, 卡蒂克·巴拉古鲁
Why does the client end of a connection
use high port number(ephemeral ports) whereas the applications
listen on typically small port numbers ?
Thx in advans,
Karthik Balaguru
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
服务器侦听固定端口号,以便客户端知道连接到哪里。客户端不需要使用固定端口号,因为没有人发起与它们的连接,事实上,如果同一台机器上运行多个客户端(例如网络浏览器),它们就无法使用固定端口号连接到同一服务器。 IANA 已指定 0..49151 范围内的端口作为特定服务的固定端口号, 49152..65535 范围内的端口作为动态(临时)端口,未分配给任何服务,可以在不需要固定端口号时使用。
端口范围 0..49151 进一步分为众所周知范围 0..1023,只有特权进程才能绑定到该范围(至少在 Unix/Linux 上),以及注册的范围 1024..49151。 1024..49151 范围内的端口可供以非特权用户身份运行的服务器进程使用,如果服务器未使用这些端口,客户端也可以使用该范围内的端口(例如 Linux 上的动态端口) Solaris 默认从 32768 开始,而不是 49152)。
Servers listen on a fixed port number so that clients will know where to connect. Clients do not need to use a fixed port number, since no one is initiating a connection to them, and in fact they cannot use a fixed port number if there may be more than one client running on the same machine (e.g. a web browser) connecting to the same server. IANA has designated ports in the range 0..49151 as fixed port numbers for specific services, and ports in the range 49152..65535 as dynamic (ephemeral) ports which are not assigned to any service and can be used when a fixed port number is not required.
The port range 0..49151 is further divided into the well known range 0..1023, which only a privileged process can bind to (at least on Unix/Linux), and the registered range 1024..49151. Ports in the range 1024..49151 can be used by server processes that may run as an unprivlieged user, and it is also possible for clients to use ports in this range if they are not being used by a server (e.g. dynamic ports on Linux and Solaris start at 32768 by default, rather than 49152).
1024 以下的端口号称为“已注册”,而高于 65,535 的端口号称为“未注册”。所有这两个术语的意思是 1024 以下的端口具有与其关联的标准服务。 IE:53 用于 DNS、80 用于 HTTP、25 用于 SMTP 等。请注意,它们是关联的 - 没有什么可以阻止您将应用程序设置为使用端口 53、25 等,但不建议这样做,因为其他服务将尝试连接和/或在这些端口上操作,因此可能会导致问题。
未注册的端口区域由客户端应用程序动态使用。 IE:您在连接到 StackOverflow.com 网络服务器的端口 80 时正在阅读此答案,但您的浏览器正在使用未注册的端口来发起该请求。
Ports numbers under 1024 are called "registered", while those above (limit of 65,535) are called "unregistered". All these two terms mean is that ports under 1024 have standard services associated with them. IE: 53 for DNS, 80 for HTTP, 25 for SMTP, etc. Note they are associated - there is nothing to stop you from setting your application to use port 53, 25, etc but it's not recommended because other services will attempt to connect and or operate on these ports so it could cause problems.
The unregistered port region is dynamically used by client applications. IE: You are reading this answer while connecting to port 80 of the StackOverflow.com webserver(s), but your browser is using an unregistered port to initiate that request.
因为服务器端口通常是众所周知的端口。在 Unix 机器上,您将在
/etc/services
文件中看到它们的分配。另一方面,客户端端口通常由 TCP/IP 堆栈从特定的高范围中选取。因此,服务器知道要侦听哪些端口,客户端知道要连接到哪个端口,并且没有人关心连接是从哪个端口建立的。Because server ports are usually well known ports. On a Unix box you will see their assignment in
/etc/services
file. The client ports, on the other hand, are usually picked by TCP/IP stack from the specific high range. So servers know what ports to listen on, clients know what port to connect to, and nobody cares what port the connection is made from.较低的端口号(<1024)保留给特权进程。此外,其中许多端口均由互联网号码分配机构分配给特定服务。客户端与侦听这些已知端口的服务器建立连接,但根据可用的端口在较高范围内使用动态分配的端口号。
Lower port numbers (< 1024) are reserved to privileged processes. In addition, many of these ports are assigned to specific services by the Internet Assigned Number Authority. Clients establish connections to servers listening on these well-known ports, but use dynamically assigned port numbers in the higher ranges according to the ports that are available to them.
较低的端口号通常为常见应用程序保留。更短=更容易记住。
Lower port numbers are typically reserved for common applications. Shorter = easier to remember.