Symetric NAT和Restricted Cone NAT

2024-03-10 12:08
文章标签 nat restricted cone symetric

本文主要是介绍Symetric NAT和Restricted Cone NAT,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

The diffierence between Symetric NAT and Restricted Cone NAT

A symmetric NAT applies restrictions exactly the same way as a port restricted cone NAT but handles the NAT translation differently. All types of NAT discussed so far(锥形NAT、受限锥形NAT、端口受限型NAT) don’t change the source port when NATing connections. For example when a client accesses the Internet using IP 192.168.0.1 and source port 56723 NAT changes the source IP to say 56.35.67.35 but keeps the port number the same; this is known as port preservation. A symmetric NAT NATs ports to new randomly generated ones. This even applies to connections from the same client to different destinations.

Example – Expanding on the example from the port restricted cone NAT my PC makes two outbound connections to website IP 217.87.69.8 and 56.76.87.98. My PC uses source IP192.168.0.1 with source port 56723 for both connections. On all types of NAT so far both these connections would be NATed to change the source IP address only and keep the source port the same. This time however instead of leaving the source port as 56723 a symmetric NAT changes it to 45765 for one connection and 53132 for the other connection (random). This has created unique mappings for each connection and traffic from those destinations must come in on the respective ports. So 217.87.69.8 must send packets to destination port 45765 and 56.76.87.98 must send packets to port 53132 in addition to the requirements of a port restricted cone NAT.


Why You Are Reading This

Has your Xbox or PS3 reported that your NAT is strict or symmetric NAT? Has your PC application, VoIP or other program reported your NAT as symmetric NAT? I suspect the answer to this is yes because symmetric NATs are the only types of NAT that cause connection problems with other devices also behind NATs.

The first part in understanding why this is an issue is to realise that PC’s, xboxes, PS3s and their associated games and applications DON’T know that they are being NATed. As far as you xbox is concerned it’s IP address is 192.168.0.1. Any devices that communicate with it on the Internet however use the public IP address of your router of say 5.45.4.21. NAT takes care of translating the IP addresses from the public IP to the internal IP when needed. So why is this a problem you ask? Well with any connection attempt the destination IP address and port must be known. In all the examples above you will see that the website IP address was known as well as the port, these are fixed and never change. Some programs however use a range of dynamic ports. When hosting computer games your console will choose a random port to host the game on. Because other consoles don’t know your IP address or port they must learn it somehow before connecting. Your console sends it’s IP address and port for the hosted game to xbox live or the PS3 network where other parties retrieve it and can now connect to you directly. The problem is that it sends it’s internal IP address of 192.168.0.1 and port of say 54324 rather than the Nated public ones. What it should send is (for example) the public IP address of 5.45.4.21 and port 54324. When using a symmetric NAT the port is also changed so it must send the NATed port of say 54254 rather than the internal port of the console itself (54324). This has been a problem with NAT long before gaming came along. So how does the console learn that it is behind a NAT and tell other consoles to send data to the NATted IP address and port rather than it’s own internal IP address and port?

STUN

There are several different protocols/solutions to the NAT problem but STUN is the most common one in use. Stun stands for ** Simple Traversal of User Datagram Protocol (UDP) through Network Address Translators** and as you may have guessed by it’s name it is a collection of utilities to aid in the traversal of a NAT devices. Simply put STUN allows your console/PC or internal device to learn what it’s public NATed IP address and port is. Once this is achieved your device can now send out the correct details to other devices that want to connect to you. But…(and there is always a but) it doesn’t work with Symmetric NATs. With a symmetric NAT your console can learn it’s public IP address but it is impossible to learn it’s public port.


STUN is quite simple in how it works. You connect to a server running the STUN protocol (xbox live servers) and it reads the source IP address and source port from the incoming packets. These of course will be the NATed ones (which are the ones we need). STUN then sends this information back to the client and it’s job is now done. Your console now knows it’s NATed IP and port and will send this onto other devices. If you remember, with the exception of a symmetric NAT all other types of NAT don’t change the source port. What this means is that when my console creates a NAT mapping it will use it for ALL connections of this type; it uses the same ONE mapping when sending and receiving packets to several devices on the Internet therefore it uses the same public IP address and port. In the case of a symmetric NAT however every single connection has a different mapping with a different (randomly generated) port(这句话意思是说,任何一个单独的连接,都会对应一个端口号,这些端口号不会重复,言下之意,发送的数据包,只要源端口号、目的ip、目的端口号,三者中的任何一个发生变化,那么就会映射到一个重新的端口号); the connection to the STUN server will have it’s own unique mapping as will every other console…which means different ports for each mapping. In this case the port that the STUN detected is now useless as this mapping is exclusive to the STUN server. Whatever port is used in the mapping to other devices is unknown and there is no way for STUN to detect it. Since your console can’t learn the public NATed port for each mapping to each console it can’t pass this information on therefore nothing can connect to your hosted game. This is the reason symmetric NATs cause so many gaming issues.

Step By Step Example Using A Port Restricted NAT

Explaining how and why symmetric NAT has problems is always easier with a step by step example. Here is the difference between a port restricted NAT and a symmetric NAT.

Port Restricted NAT

  • My console with IP address 192.168.0.1 hosts a game using port 57433. It connects to xbox live to advertise this information.
  • Xbox live (using STUN) detects my public IP address of 56.45.32.5 and public port of 57433 and informs my console of this.
  • My console updates this information and advertises these details on xbox live.
  • Another person browses xbox live for my game. Once he clicks “join” his console retrieves my public IP address and port and attempts to connect directly. It tries to connect on 56.45.32.5 with port 57433.
  • The initial connection will be blocked by a port restricted NAT because I haven’t yet sent any data to that console. My console now sends data to the remote console (IP and port learnt through xbox live) using source port 57433 with source IP 5.45.32.5.
  • All subsequent packets sent from the remote console to 56.45.32.5 using port 57433 will now be accepted by my port restricted NAT as I have now sent packets to it and he connects to me successfully.

注意:如果在同一个NAT下的不同机器都使用相同的端口号访问网络时,NAT会改变其中一个机器的端口号。

Symmetric NAT

  • My console with IP address 192.168.0.1 hosts a game using port 57433. It connects to xbox live to advertise this information.
  • Xbox live (using STUN) detects my public IP address of 56.45.32.5 and public port of 57433 and informs my console of this.
  • My console updates this information and advertises these details on xbox live.
  • Another person browses xbox live for my game. Once he clicks “join” his console retrieves my public IP address and port and attempts to connect directly. It tries to connect on 56.45.32.5 with port 57433.
  • Like a port restricted NAT the initial connection will be blocked because I haven’t yet sent any data to that console. My console now sends data to the remote console (IP and port learnt through xbox live) but a new mapping is used using port 45654 with source IP 56.45.32.5.
  • The information the remote console received from xbox live was that the game is hosted on 57433 but the symmetric NAT opened up the port 45654 for this connection and not 57433. The remote console fails to connect.

这篇关于Symetric NAT和Restricted Cone NAT的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/794201

相关文章

网络学习-eNSP配置NAT

NAT实现内网和外网互通 #给路由器接口设置IP地址模拟实验环境<Huawei>system-viewEnter system view, return user view with Ctrl+Z.[Huawei]undo info-center enableInfo: Information center is disabled.[Huawei]interface gigabit

综合DHCP、ACL、NAT、Telnet和PPPoE进行网络设计练习

描述:企业内网和运营商网络如上图所示。 公网IP段:12.1.1.0/24。 内网IP段:192.168.1.0/24。 公网口PPPOE 拨号采用CHAP认证,用户名:admin 密码:Admin@123 财务PC 配置静态IP:192.168.1.8 R1使用模拟器中的AR201型号,作为交换路由一体机,下图的WAN口为E0/0/8口,可以在该接口下配置IP地址。 可以通过

经验笔记:NAT穿越技术

NAT穿越技术经验笔记 随着互联网的普及和技术的发展,P2P(Peer to Peer,点对点)通信成为许多应用的核心功能之一。然而,网络地址转换(NAT)设备的存在常常成为实现P2P通信的一个障碍。本文旨在总结NAT穿越技术的基本原理及其配置方法,并探讨如何保障NAT穿越的安全性。 1. NAT穿越技术概述 NAT穿越技术是一种使位于不同NAT网络中的主机能够直接通信的技术。NAT(Net

NAT与NAT穿透

5. NAT穿透 5.1 转发      最可靠但又是最低效的点对点通信方法,莫过于将p2p网络通信看作一个C/S结构,通过服务器来转发信息.如下图,两个客户端A和B,均与服务器S初始化了一个TCP或UDP连接,服务器S具有公网固定IP地址,两个客户端分布在不同的私网中,这样,他们各自的NAT代理服务器将不允许他们进行直连.

NAT技术-将多个内部网络设备映射到一个公共IP地址

问题: 今天上课的时候老师让我们在VMware填同一个子网ip 192.168.196.0,然后给我们的linux镜像都是同一个压缩包,结果我们的静态ip地址都是同一个。 192.168.196.0下面有256个ip地址,范围是192.168.196.0到192.168.196.255。我们几十个人的ip地址怎么会是同一个 linux镜像的ip地址被老师写死了, 1.难道内网的ip可以随便定

代理服务器介绍,正向代理(校园网,vpn,http隧道技术),反向代理(公司服务器,frp服务),NAT和代理服务器的相同/不同点

目录 代理服务器 介绍 类型  正向代理 引入 介绍  vpn http隧道技术 反向代理 引入 隧道技术 介绍 frp服务 NAT和代理服务器 相同点 不同点 NAT 代理服务器 代理服务器 介绍 一种中间服务器,充当客户端(如个人计算机或移动设备)与目标服务器(如网站服务器)之间的中介 它接受客户端的请求,然后将这些请求转发给目标服务器,再把

NAT技术介绍+缺陷(内网穿透+工具),NAPT(介绍,替换过程,原理,NAT转换表)

目录 NAT技术 介绍 NAT转换表 引入 介绍 NAPT技术介绍  NAPT替换过程 NAPT原理 注意点 NAT缺陷 无法直接访问其他内网主机 内网穿透 工具 其他  NAT技术 介绍 NAT 是一种网络技术,它允许在一个公共 IP 地址和多个私有 IP 地址(入口路由器的wan口地址 和 私网内的私有ip)之间进行转换 目前解决ip地址不足的最主要

Netfilter学习之NAT类型动态配置(八)nf_nat_proto_common.c代码解析

nf_nat_proto_common.c实现了对称型的端口改变,在此我决定对其代码进行分析,以便实现对对称型NAT的随意改动。    具体代码如下: #include <linux/types.h>#include <linux/random.h>#include <linux/netfilter.h>#include <linux/export.h>#include <net/n

Netfilter学习之NAT类型动态配置(七)全锥型NAT内核空间实现

本文主要实现全锥型NAT的内核空间iptables命令行扩展对应的钩子函数及其功能的实现。实现思路见上文。 1.关键部分实现代码 (1)建立ipt_FULLCONE.c以激活钩子函数,关键在于保持和用户空间libipt的一致性。 static struct xt_target fullcone_tg_reg __read_mostly = {.name = "FULLCONE",.fam

Netfilter学习之NAT类型动态配置(六)全锥型NAT用户空间iptables命令行实现

本文主要实现全锥型NAT的用户空间iptables命令行扩展的实现,实现思路见上文,具体可以模仿MASQUERADE的源码进行改写。 1.关键部分实现代码   由于fullcone类型并不需要输入参数,因此parse可以为空,print和save也很简单,只需要help和结构注册两部分保证正确即可。   help如下: static void FULLCONE_help(void){