【问题标题】:Regarding nat type analysis关于nat类型分析
【发布时间】:2016-09-20 09:07:18
【问题描述】:

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

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 类型将是“地址和端口相关过滤”,因此任何媒体通信都需要转服务器。

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

专家对点对点通信需要考虑的 NAT 类型分析有什么意见吗?

【问题讨论】:

    标签: webrtc nat stun turn


    【解决方案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:port,但从不同的 ip 或端口接收。 99% 的时间 NAT 不允许这样做。所以结果几乎总是导致“地址和端口相关过滤”。过滤测试结果并不能很好地表明您的 NAT 将如何成功实现 P2P 连接。

    并且仅仅因为您的企业网络非常严格,并不意味着您无法与另一个网络上的对等方进行通信。如果他有一个性能更好的 NAT 和 Endpoint Independent Mapping,那么 P2P 连接仍有可能成功。

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

    【讨论】:

    • 谢谢塞尔比。但是“52.201.75.212” stunserver 是如何从其端口“3479”响应直到监听它的呢?如果其中一种网络 NAT 类型是对称网络,而另一种网络 NAT 类型是 Endpoint Independent Mapping,则仍然可以进行 P2P 连接。这就是您所说的“这并不意味着您无法与另一个网络上的对等方进行通信。如果他的 NAT 具有与端点无关映射的性能更好的 NAT,那么 P2P 连接仍有可能成功” ..
    • STUN 服务器始终监听两个端口(3478 和 3479)和两个 IP 地址。由于对称 NAT(例如您的企业网络)没有可预测的端口映射,因此不确定从 STUN 获得的地址/端口是否可以与尝试连接的对等方的 IP 地址一起使用。对等方的 NAT 不仅必须是 Endpoint Ind,而且过滤可能必须是“地址相关”或更好。
    【解决方案2】:

    我想,您希望在所有可能的情况下(包括对称 NAT)在 p2p 之间进行通信。 我的建议:尝试使用 webRTC 并使用 stun 并在 ice 服务器列表中打开服务器。这将为您提供一系列 ICE 候选人,而 webRTC 将负责连接到最佳候选人。 这应该可以让您摆脱 NAT 类型的顾虑。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-13
      • 1970-01-01
      • 1970-01-01
      • 2012-01-15
      • 1970-01-01
      • 2021-01-19
      • 2015-11-02
      • 1970-01-01
      相关资源
      最近更新 更多