两台计算机如何通过NAT连接到同一个外部地址? [英] How do two computers connect to same external address through NAT?

查看:292
本文介绍了两台计算机如何通过NAT连接到同一个外部地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有两台内部计算机通过NAT路由器连接到同一个外部IP地址,那么路由器如何才能将流量传输到正确的内部计算机?据我所知,NAT将传入的数据包转发到最近将传出数据包发送到[传入数据包]发送方IP地址的计算机。由于两台计算机都发送到同一个地址,路由器是否将数据包转发到两者?如果是这种情况,客户端软件是否有责任确定哪些数据包是相关的?

If I have two internal computers connecting to the same external IP address through a NAT router, how is the router able to get the traffic to the correct internal computer? It is my understanding that NAT forwards incoming packets to the computer that recently sent outgoing packets to the [incoming packet's] sender's IP address. Since both computers are sending to the same address, does the router forward the packet to both? If that is the case, is it the responsibility of the client software to determine which packets are relevant?

两台计算机是否都尝试连接到同一端口?

Is it possible if both computers are attempting to connect to the same port?

推荐答案

当您打开套接字时,您需要寻址目标系统的端口并打开一个共轭侦听端口自己的系统接收任何响应。您必须将目标系统发送到您的侦听端口。

When you open a socket, you need to address a port of the destination system and open a conjugate listening port on your own system to receive any response. You have to send the destination system your listening port.

让多个系统使用同一调制解调器

当您启动网络浏览器并访问www.google.com:80时,您的浏览器会从系统中获取/搜索免费的非系统共轭端口以供收听。让我们说,共轭端口是10000.侦听器端口用于从谷歌接收http流。

When you start a web browser, and go to www.google.com:80, your browser obtains/searches for a free non-system conjugate port from the system for listening. Let us say, the conjugate port is 10000. The listener port is for receiving the http stream back from google.

然后你的孩子偶然也会浏览www。 google.com:80和他/她的游戏站或xbox的google会话 - 偶然也会分配共轭端口10000.

Then your kid sitting next to you incidentally also browses www.google.com:80 and his/her google session of the play station or xbox-whatever also incidentally is assigned conjugate port 10000.

你们两个都坐在电缆后面调制解调器,有线调制解调器后面是你的无线路由器。并且你的两个系统都在无线路由器后面 - 所有系统都按照网络拓扑顺序排列。

Both of you are sitting behind a cable modem, and behind the cable modem is your wireless router. And both of your systems are behind the wireless router - All sitting in that sequence, network topology-wise.

防止路由器/调制解调器上的端口地址冲突

让我们说你的有线电视公司DHCP分配你的调制解调器ip4地址72.72.72.72。但是你的无线路由器DHCP将192.168.0.10分配给你的系统,并将192.168.0.11分配给你孩子的系统。

Let us say that your cable company DHCP assigns your modem ip4 adress 72.72.72.72. But your wireless router DHCP assigns 192.168.0.10 to your system and to 192.168.0.11 to your kid's system.

当携带你的监听端口信息的帧通过你的系统时NAT路由器,它将转换一个或两个侦听端口。假设你的页面有15000端口,你孩子的页面有16000端口。

When the frame carrying the information of your listener ports passes thro your NAT router, it would translate either one or both listening- ports. Let's say port 15000 for your page and port 16000 for your kid's page.

你的无线路由器然后将你的请求发送到谷歌服务器来自72.72.72.72:15000和72.72 .72.72:16000。

Your wireless router then sends your requests to google server as coming from 72.72.72.72:15000 and 72.72.72.72:16000.

谷歌服务器然后单独响应72.72.72.72:15000和72.72.72.72:16000当无线路由器遇到响应时,它会进入它存储的映射并将72.72.72.72:15000转换为192.168.0.10:10000以到达您的系统,但将72.72.72.72:16000转换为192.168.0.11:10000以到达您孩子的系统。

The google server then responds individually to 72.72.72.72:15000 and 72.72.72.72:16000 and when you wireless router encounters the response, it reaches into the mapping that it has stored and translates 72.72.72.72:15000 to 192.168.0.10:10000 to reach your system but translates 72.72.72.72:16000 to 192.168.0.11:10000 to reach your kid's system.

运行网络/游戏/ ftp / etc服务器

但是如果你有一台网络服务器或一台ftp服务器怎么办?在你的系统上运行。如果你有两个系统,并且两个系统都有一个Web服务器并且两个Web服务器都在端口80上监听怎么办?

But what if you have a web server or an ftp server running on your system. What if you have two systems and both have a web server and both web servers are listening on port 80?

让我们说一下你的无线注册/分配的本地IP地址第一个Web服务器系统的路由器是192.168.0.30,第二个Web服务器系统是192.168.0.40。

Let us say the local ip addresses registered/assigned with your wireless router of your first web server system is 192.168.0.30 and your second web server system is 192.168.0.40.

无线路由器通常默认配置网页192.168 .0.1:80,除非你改变它。页面上有一个标签,您可以在其中定义/保留应用程序端口映射。

The wireless router would have a configuration web page usually by default 192.168.0.1:80, unless you changed it. There would be a tab to on the page where you could define/reserve application port mappings.

您可以注册无线路由器以保留映射

You could register with your wireless router to reserve the mapping

192.168.0.30:80 => outgoing port 8080
192.168.0.40:80 => outgoing port 8088

因此,您必须给朋友打电话,您的网络/游戏服务器可通过$ b进行寻址$ b 72.72.72.72:8080和72.72.72.72:8088,
,其中无线路由器将其端口8080和8088排除在自己的动态NAT使用之外。

So that you have to phone your friends your web/game servers are addressable through 72.72.72.72:8080 and 72.72.72.72:8088 respectively, where the wireless router would preclude its port 8080 and 8088 from its own dynamic NAT usage.

当然,72.72.72.72与你的ISP DHCP决定更新你的调制解调器的ip4地址之前一样好,比如72.72.90.200。之后你必须给你的朋友打电话/发电子邮件并说
嘿,服务器的地址分别变为72.72.90.200:8080和72.72.90.200:8088。或者您可以订阅动态DNS(ddns)服务以使用命名域,其中ddns服务将需要您在系统上安装简单的心跳实用程序以帮助它们监视地址变化。 DDNS翻译是一个单独的问题/策略。

Of course, 72.72.72.72 is as good as only before your ISP DHCP decide to renew the ip4 address of your modem to say, 72.72.90.200. After which you would have to phone/email your friends and say Hey, the servers' addresses have changed to 72.72.90.200:8080 and 72.72.90.200:8088 respectively. Or you could subscribe to dynamic dns (ddns) service to use a named domain where the ddns service will need you to install a simple heartbeat utility on your system to help them monitor the address variation. DDNS translation is a separate issue/strategy.

NAT调制解调器

较新的ISP合同为您提供具有NAT的调制解调器。如果是这样,您必须关闭调制解调器上的那个或无线路由器上的那个。你不应该同时使用两者 - 两次翻译的重点是什么,因为NAT只是为了防止地址冲突。当您从无线路由器关闭NAT时,它可以作为集线器交换机而不是路由器运行,以便您可以使用其LAN插槽而不是其WAN插槽将其连接到调制解调器。

Newer ISP contracts supply you with a modem that has NAT. If so, you have to switch off either the one on your modem or the one on your wireless router. You should not use both - what's the point in translating twice because NAT is simply to prevent address collision. When you switch off NAT from your wireless router, it can operate as a hub switch and not a router anymore so that you could connect it to the modem using one of its LAN socket instead of thro its WAN socket.

这篇关于两台计算机如何通过NAT连接到同一个外部地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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