NAT 后面到 NAT 后面的连接 [英] Behind NAT to behind NAT connection

查看:27
本文介绍了NAT 后面到 NAT 后面的连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个有趣的问题.基本上我有 2 部手机都在 NAT 之后.我想使用 UDP 在两台设备之间直接通信.

I've come across an interesting problem. Basically I have 2 mobile phones that are both behind NATs. I want to communicate directly between the 2 devices using UDP.

我知道如果我发起了从手机到服务器的连接,那么我可以将数据通过该连接推回手机(即从接收消息的相同端口将其发送回相同的 IP 和端口从......收到).因此,通过将两部手机连接到服务器,我可以轻松地在两部设备之间进行通信.然后将数据发送到服务器并将其重新路由回手机.这绕过了我可能遇到的任何 NAT 穿越问题.

I know if I initiate a connection from the phones to a server then I can push data back down that connection to the phone (ie send it back from the same port that received the message to the same ip and port that it was received from). So I can easily communicate between the 2 devices by connecting both phones to the server. Then sending data to the server and having it re-routed back to the phones. This bypasses any NAT traversal issues I may come up against.

但是我宁愿只使用服务器将 2 个设备相互指向,然后让它们直接通信.我该怎么做呢?不使用 uPnP 之类的东西可以吗?

However I would rather just use the server to point the 2 devices at each other and then let them communicate directly. How would I go about doing this? Is it possible without using something like uPnP?

非常感谢任何帮助!

编辑:我找到了这个文档 http://www.brynosaurus.com/pub/net/p2pnat/ 看起来像发夹式翻译是我所追求的,但它看起来并没有得到广泛支持.我想知道移动 ISP 对 UPnP 的支持有多好?

Edit: I found this document http://www.brynosaurus.com/pub/net/p2pnat/ It looks like hairpin translation is what I'm after but it doesn't look to be widely supported. I wonder how good mobile ISP's support for UPnP is?

推荐答案

您正在寻找的是 UDP 打孔,参见例如http://en.wikipedia.org/wiki/UDP_hole_punching

What you're looking for is UDP hole punching, see e.g. http://en.wikipedia.org/wiki/UDP_hole_punching

基本思想很简单,您告诉每个端点要使用的端口,然后它们开始发送 udp 数据包.NAT'ing 设备在看到第一个传出数据包时会设置遍历规则,然后另一端的下一次尝试将匹配此遍历规则.

The basic idea is simple, you tell each endpoint the ports to use, and they start sending udp packets. The NAT'ing devices will set up a traversal rule when they see the first outgoing packet, and then the next attempt from the other end will match this traversal rule.

这篇关于NAT 后面到 NAT 后面的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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