如何使用IP连接到多个网关后面的另一台机器?

发布于 2024-11-17 05:30:53 字数 303 浏览 3 评论 0原文

我不知道在哪里问这个,所以就在这里。这更多的是一个网络技术问题,但任何指示都会有所帮助。

假设,我想连接到多个网关后面的机器。假设我想从办公室计算机连接到家庭计算机。我的家用计算机位于 ISP 网关后面,然后位于家里的无线路由器后面。假设我知道所有这些的 IP。 (我的 ISP 网关的全局 IP、我的 ISP 网络中的无线路由器的本地 IP 以及我家里机器的本地 IP)。如何启动与我的家用计算机的 TCP 连接?标准的伯克利套接字程序只需要一个IP,因此我只能连接到具有全局IP的机器。

有解决办法吗?我对伯克利套接字的看法正确吗?

谢谢。

I did not know where to ask this so here it is. This is more of a networking technology question, but any pointers will help.

Suppose, I want to connect to a machine behind multiple gateways. Say I want to connect to my home computer from my office computer. My home computer is behind my ISP's gateway and then behind my wireless router at home. Let's say I know the IP's for all of them. (global IP for my ISP's gateway, local IP for my wireless router within my ISP's n/w and my home machine's local IP within my home). How do I initiate a TCP connection with my home computer ? The standard berkeley socket program only takes one IP and so I can only connect to machines that have global IPs.

Is there a solution ? Am I correct about the berkeley sockets ?

Thanks.

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

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

发布评论

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

评论(2

蓝颜夕 2024-11-24 05:30:53

在 ISP 的配合下这是完全可能的。 ISP 提供私人地址这一事实应该促使您转移到另一个地址。

您所追求的概念称为 DNAT 或端口转发

假设您决定访问 PC 上的端口 1234。 PC 的地址是Local2。无线路由器的地址(在具有 ISP 的网络中)是 Local1

  • 无线路由器必须进行转换 Local1:X -> Local2:1234
  • ISP 路由器必须进行转换 Public:1234 -> Local1:X

X 表示可以使用任何端口。

It is entirely possible, with the cooperation of the ISP. The fact that the ISP is giving private addresses should urge you to move to another.

The concept you're after is called DNAT or Port Forwarding.

Let's say you decide on accessing port 1234 on a PC. The address of the PC is Local2. The address of the wireless router (in the network with the ISP) is Local1.

  • The wireless router must do the translation Local1:X -> Local2:1234
  • The ISP router must do the translation Public:1234 -> Local1:X

The X means any port can be used.

淡淡の花香 2024-11-24 05:30:53

您只需要知道从应用程序连接的目标 IP 地址,网关地址用于转发(路由)由操作系统网络堆栈处理的数据包。但是,如果目标位于 NAT 之后,您将只知道目标 NAT 设备的公共 IP 地址。即使在这种情况下,您所拥有的只是一个 IP 地址,而且您并不真正知道是否存在 NAT。

如果您的目的地是固定的,您可以在 NAT 设备上设置端口转发(如果您控制它)。否则,您就会意识到 NAT 是纯粹的邪恶。

在您的情况下,您似乎想要连接到家庭计算机。如果您的无线设备有公共 IP 地址,您可以在其上设置端口转发,以将端口上的所有传入流量转发到家庭计算机上的端口。

You only need to know the destination IP address to connect from an application, the gateway address is for the forwarding (routing) of packets which is handled by the OS network stack. However, if the destination is behind NAT, you'll only know the public IP address of the destination's NAT device. Even in this scenario, all you have would be an IP address and you don't really know if there is NAT going on.

If your destination is fixed, you could set up port forwarding on the NAT device (if you control it). Otherwise, you just realized that NAT is pure evil.

In your situation, it appears you want to connect to your home computer. If your wireless device has a public IP address, you can setup port forwarding on that to forward all incoming traffic on a port to a port on your home computer.

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