linux - 何时使用 TCP 打洞技术以及为什么使用它?

标签 linux networking tcp nat hole-punching

我正在研究TCP hole punching技术,从这篇文章中获得了一些知识:TCP_hole_punching .但我不明白下面的部分:

      Network Drawing
      Peer A ←→ Gateway A ← .. Network .. → Gateway B ←→ Peer B  

      Types of NAT
      The availability of the TCP-hole-punching technique depends 
      on the type ofcomputer port allocation used by the NAT. When 
      two peers, A and B, instantiate TCP   connections by binding 
      to local ports Pa and Pb, respectively, **they need to know 
      the remote  endpoint NAT port in order to make the connection**.

这里有一些问题,谁能帮忙解释一下?任何帮助或建议将不胜感激!!

Q1。假设我们有一个在 NAT1 后面运行的客户端应用程序和一个服务器应用程序 在 NAT2 后面运行。他们将进行消息传递和文件传输通信。 模式将是服务器监听并接受连接 来自客户。 他们是否需要使用 TCP 打洞来保持 tcp 连接正常吗?

Q2。 只有点对点的时候才需要TCP打洞技术吗 通信并且双方正在相互连接(例如,2x CONNECT(),没有 LISTEN()、ACCEPT() 等)?

Q3。在上面的文本中,“他们需要知道远程端点 NAT 端 Eloquent 能建立连接”是什么意思? 为什么他们需要知道远程端点NAT端口?他们不只需要知道对方机器的本地端口吗?

例如,假设这对是 (ClientA, publicIPA, LocalPortA), (ClientB, publicIPB, LocalPortB)。如果 ClientA 想通过 TCP 与 ClientB 通信,它可能会做这样的事情:

         clientBAddr.port = LocalPortB;
         clientBAddr.ip = inet_addr(publicIPB);
         connect(fdA, clientBAddr,...);

为什么它需要知道 NATPortA 和 NATPortB 等信息?如果clientA和clientB不关心NATA和NATB会有什么问题吗?

最佳答案

由于此帖已重开,到现在为止没有人留下答案,我想根据这篇文章自己回答:Peer-to-Peer Communication Across Network Address Translators

关于第一季度,是的。如果没有像打洞这样的机制,一方用来与另一方同步的数据包将被路由器丢弃。

关于第二季度,不完全是。监听套接字不会直接工作。您需要其他技巧。

关于linux - 何时使用 TCP 打洞技术以及为什么使用它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15035881/

相关文章:

azure - 是否可以使用 Databricks 的专用终结点连接到 Azure 存储帐户?

java - RMI 远程对象到 stub

linux - 在查询我的计算机上本地运行的 DNS 服务器时,如何让 dig 使用 localhost 以外的源 IP?

apache - TIME_WAIT 连接过多

c - Linux、OSX 和 Windows 上的基本 TCP 客户端

http - 从 Go HTTP 服务器获取源 IP 地址

linux - 错误 : undefined reference to.。编译 GTK-3.12.2 时的长列表

python - 在python中获取友好的设备名称

linux - 解析大括号中的 block

linux - Bash:检查是否给出了参数(例如是否有参数 "-a"?)