关于nat类型分析

时间:2016-09-20 09:07:19

标签: webrtc nat stun turn

我从http://www.stunprotocol.org/下载了stun客户端,并尝试通过命令stunclient找出NAT类型--mode full stun.stunprotocol.org --verbosity 9,我得到了以下响应。

config.fBehaviorTest = true
config.fFilteringTest = true
config.timeoutSeconds = 0
config.uMaxAttempts = 0
config.addrServer = 52.86.10.164:3478
socketconfig.addrLocal = 0.0.0.0:0
Sending message to 52.86.10.164:3478
Got response (68 bytes) from 52.86.10.164:3478 on inter
Other address is 52.201.75.212:3479

Sending message to 52.201.75.212:3478
Got response (68 bytes) from 52.201.75.212:3478 on inte
Sending message to 52.201.75.212:3479
Continuing to wait for response...
Continuing to wait for response...
Continuing to wait for response...
Continuing to wait for response...
Continuing to wait for response...
Sending message to 52.201.75.212:3479
Continuing to wait for response...
Continuing to wait for response...
Continuing to wait for response...
Continuing to wait for response...
Continuing to wait for response...
Sending message to 52.86.10.164:3478
Continuing to wait for response...
Continuing to wait for response...
Continuing to wait for response...
Continuing to wait for response...
Continuing to wait for response...
Sending message to 52.86.10.164:3478
Continuing to wait for response...
Continuing to wait for response...
Continuing to wait for response...
Continuing to wait for response...
Continuing to wait for response...
Sending message to 52.86.10.164:3478
Continuing to wait for response...
Continuing to wait for response...
Continuing to wait for response...
Continuing to wait for response...
Continuing to wait for response...
Sending message to 52.86.10.164:3478
Continuing to wait for response...
Continuing to wait for response...
Continuing to wait for response...
Continuing to wait for response...
Continuing to wait for response...
Binding test: success
Local address: 10.64.60.58:58841
Mapped address: 125.19.34.60:24604
Behavior test: fail
Filtering test: success
Nat filtering: Address and Port Dependent Filtering

我在公司工作,因此出于安全考虑,NAT类型“地址和端口相关过滤”似乎是可行的。

但作为一般现象,在我看来,对于点对点连接,大多数情况下,NAT类型将是“地址和端口相关过滤”,因此任何媒体通信都需要转向服务器。 p>

然而,在google上搜索webrtc,它表明90%的点对点通信是通过stun服务器本身建立的(通过打孔等)。这意味着在这种情况下完全支持NAT类型来建立连接。

专家对于对等通信需要考虑的NAT类型分析有什么看法吗?

2 个答案:

答案 0 :(得分:1)

stunclient程序可以使用更多日志记录来指示它正在做什么。由于我对代码了解不多,这就是我如何解释它。

Stunclient进行两组不同的测试。第一个是“映射行为”测试,这对于了解NAT /防火墙将如何影响P2P连接最为重要。另一组是“过滤测试”,它指示NAT在接收来自其他IP /端口组合的流量时如何“打开”。

您的行为测试“失败”。根据您的日志输出,这可能意味着:

测试1:在这种情况下选择一个随机端口58841。从本地端口,对stun.stunprotocol.org:3478进行基本绑定测试。这是客户端收到响应的位置,其中服务器指示映射的地址(125.19.34.60:24604),并且后续行为和过滤测试的stun备用IP位于52.201.75.212。

测试2:相同的本地端口,58851。向备用IP和主端口发送绑定请求(52.201.75.212:3478)。在您的情况下,似乎回来的响应可能是不同的IP或端口。在这种情况下,需要“测试3”。

测试3:相同的本地端口,58851。向备用IP和备用端口(52.201.75.212:3479)发送绑定请求,以便区分“地址相关”与“地址和端口相关映射”。这是有趣的部分 - 你从来没有得到过回应。尽管能够与端口3478上的两个IP地址进行通信。这就是测试失败的原因。

可能是以下两件事之一:

a)您的NAT /防火墙实际上是为端口3478打开,但不是3479.从命令行执行以检测

 stunclient 52.201.75.212 3479

如果成功获取映射地址,则立即执行此操作:

 stunclient 52.86.10.164 3478

尝试这两个ip地址和端口的其他组合。产生的行为可能意味着以下

b)当删除ip和端口都已更改时,NAT /防火墙会拒绝端口映射。这意味着您的网络环境比“地址和端口相关映射”NAT更具限制性。通常称为对称NAT。

对于过滤测试,请忽略此结果。过滤测试尝试检测您是否可以发送到一个ip:端口,但是从另一个IP或端口接收。 99%的时间NAT不允许这样做。因此,结果几乎总是导致“地址和端口相关过滤”。过滤测试结果并不能说明您的NAT如何在P2P连接中取得成功。

仅仅因为您的企业网络非常严格,并不意味着您无法与其他网络上的对等方进行通信。如果他的端点独立映射具有更好的NAT,那么P2P连接仍然有可能成功。

我最近没有跟上NAT趋势,但仅有STUN成功的80-90%的连接听起来是正确的。其余的将需要一个中继解决方案,如TURN。

答案 1 :(得分:0)

我想,您希望在所有可能的场景(包括对称NAT)中在p2p之间进行通信。 我的建议:尝试使用webRTC并在冰服务器列表中使用stun和turn服务器。这将为您提供一系列ICE候选人,webRTC将负责与最佳候选人联系。 这应该可以帮助您避免NAT类型问题。

相关问题