NAT类型及STUN功能介绍_chrissie_新浪博客

NAT类型:

Full Cone NAT:

 full cone NAT is one where all requests from the same internal IP address and port are 
 mapped to the same external IP address and port. Furthermore, any external host can send 
 packet to the internal host, by sending packet to the mapped external address.

Restricted cone NAT:

restricted cone NAT is one where all requests from the same internal IP address and 
port are mapped to the same external IP address and port. Unlike full cone NAT, an external
host (with IP address X) can send packet to the internal host only if the internal host 
had previously sent packet to IP address X.

Port Restricted cone NAT:

port restricted cone NAT is like restricted cone NAT, but the restriction 
includes port numbers. Specifically, an external host can send packet, with source IP
address and source port P, to the internal host only if the internal host had previously 
sent packet to IP address and port P.

Symmetric NAT:

symmetric NAT is one where all requests from the same internal IP address and port, 
to specific destination IP address and port, are mapped to the same external IP address and
port.  If the same host sends packet with the same source address and port, but to 
different destination, different mapping is used. Furthermore, only the external host that
receives packet can send UDP packet back to the internal host.

 

除以上4中类型之外,客户端主机所在网络还可以为以下类型:

Opened:No NAT, public IP, no firewall.

Blocked:UDP is always blocked.
Symmetric UDP Firewall:No NAT, public IP, but symmetric UDP firewall.

STUN 协议是一个客户机/服务器协议,在公网上存在着大量的STUN服务器,用户可以通过在自己主机上运行STUN客户端远程连接STUN服务器来确认自身的网络状况.

 

测试过程

STUN服务器运行在UDP协议之上,它具有两个固定公网地址,能完成以下几个功能:

1. 告诉STUN客户端经NAT设备映射后的公网地址.

2. 根据STUN客户端的要求,从服务器的其他不同IP或端口向客户端回送包.

如何根据STUN服务器提供的功能来确认网络类型呢? rfc3489给出了如下图过程:

                  +--------+
                        Test  |
                           |
                        +--------+
                             |
                             |
                             V
                            /\              /\
                         N /                     +--------+
          UDP     <-------/Resp\--------->/ IP \------------->|  Test  |
          Blocked         \ ?          \Same/               II   |
                                     \? /               +--------+
                            \/              \/                    |
                                             | N                  |
                                                               V
                                                               /\
                                         +--------+  Sym.      N /  \
                                         Test  UDP    <---/Resp\
                                          II   Firewall   \ ?  /
                                         +--------+              /
                                                               \/
                                                                |Y
                  /\                         /\                    |
   Symmetric       +--------+                    V
      NAT  <--- / IP \<-----|  Test  |<--- /Resp\               Open
                \Same/            \ ?               Internet
                 \? /       +--------+      /
                  \/                         \/
                                           |Y
                                           |
                                           V
                                           Full
                                           Cone
                              /\
              +--------+        \ Y
              Test  |------>/Resp\---->Restricted
               III       \ ?  /
              +--------+        /
                                 \/
                                  |N
                                       Port
                                  +------>Restricted

                 Figure 2: Flow for type discovery process

这个过程可概括如下:

1, STUN客户端向STUN服务器发送请求,要求得到自身经NAT映射后的地址:

a,收不到服务器回复,则认为UDP被防火墙阻断,不能通信,网络类型:Blocked.

b,收到服务器回复,对比本地地址,如果相同,则认为无NAT设备,进入第2步,否则认为有NAT设备,进入3步.

2, (已确认无NAT设备)STUN客户端向STUN服务器发送请求,要求服务器从其他IP和PORT向客户端回复包:

a,收不到服务器从其他IP地址的回复,认为包被前置防火墙阻断,网络类型:Symmetric UDP Firewall.

b,收到则认为客户端处在一个开放的网络上,网络类型:Opened.

3, (已确认存在NAT设备)STUN客户端向STUN服务器发送请求,要求服务器从其他IP和PORT向客户端回复包:

a,收不到服务器从其他IP地址的回复,认为包被前置NAT设备阻断,进入第4步.

b,收到则认为NAT设备类型为Full Cone,即网络类型:Full Cone NAT.

4, STUN客户端向STUN服务器的另外一个IP地址发送请求,要求得到自身经NAT映射后的地址,并对比之:

a,地址不相同,则网络类型:Symmetric NAT.

b,相同则认为是Restricted NAT,进入第5步,进一步确认类型.

5, (已确认Restricted NAT设备)STUN客户端向STUN服务器发送请求,要求服务器从相同IP的其他PORT向客户端回复包:

a,收不到服务器从其他PORT地址的回复,认为包被前置NAT设备阻断,网络类型:Port Restricted cone NAT.

b,收到则认为网络类型: Restricted cone NAT.


郑重声明:资讯 【NAT类型及STUN功能介绍_chrissie_新浪博客】由 发布,版权归原作者及其所在单位,其原创性以及文中陈述文字和内容未经(企业库qiyeku.com)证实,请读者仅作参考,并请自行核实相关内容。若本文有侵犯到您的版权, 请你提供相关证明及申请并与我们联系(qiyeku # qq.com)或【在线投诉】,我们审核后将会尽快处理。
—— 相关资讯 ——