关于网络地址转换 (NAT)?

发布于 2024-09-02 18:33:45 字数 240 浏览 6 评论 0原文

只是对 NAT 的特定场景感到好奇。假设我们有 4 台计算机在 NAT 下共享一个全局 IP 地址。据我了解,NAT 盒会保留内部记录,以了解将请求转发到哪台计算机。但假设我正在 2 号计算机上下载一个文件。假设在计算机 #1、#3 和 #4 上,我只是正常浏览网页。当浏览器启动 TCP 连接来获取该文件时,它如何知道将其提供给哪台计算机?我的意思是,四台计算机中的每一台都使用端口 80 来浏览网页,对吧? NAT的记录如何区分哪个“80端口”属于哪台计算机呢?

Just curious about a particular scenario of NAT. Let's suppose we have 4 computers sharing a global IP address under the NAT. I understand that the NAT box keeps an internal record to know which computer to forward requests to. But let's say on computer #2 I'm trying to download a file. And let's say on computer #1, #3, and #4, I'm just browsing the web normally. When the browser initiates a TCP connection to get that file, how does it know which computer to give it to? I mean like, each of the four computers is using port 80 to browse the web right? How does the NAT's record distinguish which "port 80" belongs to which computer?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

伊面 2024-09-09 18:33:45

互联网上每个唯一的 TCP 连接均由四个数字组成 - {源 IP、源端口、目标 IP、目标端口}

NAT 网关 (GW) 将其转换为{GW 公共 IP、GW 映射端口、目标 IP、目标端口},以便外部路由器知道将数据包返回到该特定网关。它还保留这些映射端口到源 IP 和端口号的映射,沿着 {GW-mapped port ->; {源IP,源端口}},这使得它能够确定将响应数据包发送到哪个内部机器。

Each unique TCP connection on the internet is made up of four numbers - {source IP, source port, destination IP, destination port}.

A NAT gateway (GW) translates this to {GW public IP, GW-mapped port, destination IP, destination port} so the outside routers know to return packets to this particular gateway. It also keeps a mapping of these mapped ports back to source IP and port number, along the lines of {GW-mapped port -> {source IP, source port}}, which allows it to figure out what internal machine to send the response packets to.

诗化ㄋ丶相逢 2024-09-09 18:33:45

“http 的端口 80”的概念并不像这些那样工作。当计算机浏览网页时,只有服务器使用80端口,而客户端将使用随机端口号。服务器回复附有客户端提供的目标端口。 80端口只是用来敲Web服务器的门的。

NAT 所做的就是将所有这 4 台计算机向外转换数据包,以便它们的源端口不会重复。当NAT收到数据包时,它会检查所连接的目标端口是否可以转换,如果可以的话将其转换到LAN。

The concept of "port 80 for http" does not work like these. When a computer browse the web, only the server uses port 80, while the client will use a random port number. The server replies with a destination port, provided by the client, attached. Port 80 is just for knocking the web server's door.

What the NAT does do is translating all those 4 computers outward packets such that their source ports does not duplicate. When the NAT receives a packet, it will check if the attached destination port can be translated and translate it to the LAN if possible.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文