如何确定HTTP的源端口? NAT中是否有碰撞? [英] How is source port for HTTP determined? Is there ever collision in NAT?

查看:206
本文介绍了如何确定HTTP的源端口? NAT中是否有碰撞?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,当发出HTTP请求时,数据包从客户端上看似随机的高编号端口(例如4575)发送到服务器上的端口80。然后服务器将回复发送到相同的高编号端口,路由器知道将其路由到客户端计算机,一切都已完成。

I know that when a HTTP request is made, packets are sent from a seemingly-random high-numbered port (e.g. 4575) on the client to port 80 on the server. Then the server sends the reply to the same high-numbered port, the router knows to route that to the client computer, and all is complete.

我的问题是:如何确定返回端口(本例中为4575)?是随机的吗?如果是这样,在什么范围内?对它有任何限制吗?例如,如果LAN中的两台计算机将具有相同源端口的HTTP请求发送到同一网站,会发生什么?路由器如何知道哪台计算机路由到哪台?或者这种情况很少见,没有人愿意为它辩护?

My question is: How is the return port (4575 in this example) determined? Is it random? If so, within what range? Are there any constraints on it? What happens, for example, if two computers in a LAN send HTTP requests with the same source port to the same website? How does the router know which one to route to which computer? Or maybe this situation is rare enough that no-one bothered to defend against it?

推荐答案

NAT将决定/确定NATed连接/会话的出站端口,通过它自己的内部方式。意思是,它会根据NAT的实现而有所不同。这意味着任何回复将返回到同一个出站端口。

The NAT is going to decide/determine the outbound port for a NATed connection/session, via it's own internal means. Meaning, it will vary according to the implementation of the NAT. This means any responses back will come back to that same outbound port.

至于您的问题:


例如,如果LAN中的两台计算机将具有相同源端口的HTTP
请求发送到同一网站,会发生什么情况?

What happens, for example, if two computers in a LAN send HTTP requests with the same source port to the same website?

它将为每个分配不同的出站端口。因此,它可以区分它收到的两个响应。 NAT将创建/维护已转换端口的映射,为新会话创建新的出站端口号。因此,即使有两个不同的内部会话,来自两台不同的机器,在相同的端口号上,它也会映射到传出侧的两个不同的端口号。因此,当数据包重新进入相​​应的端口时,它将知道如何将它们转换回内部LAN上的正确地址/端口。

It will assign different outbound ports for each. Thus, it can distinguish between the two in responses it receives. A NATs would create/maintain a mapping of translated ports, creating new outbound port numbers for new sessions. So even if if there were two different "internal" sessions, from two different machines, on the same port number, it would map to two different port numbers on the outgoing side. Thus, when packets came back in on the respective ports, it would know how to translate them back to the correct address/port on the inside LAN.

图表:

这篇关于如何确定HTTP的源端口? NAT中是否有碰撞?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆