Skip to content

通过知识获得解放,通过技术获得自由

Menu
  • 专题目录
  • 液压相关
    • 液压技术
    • 液压相邻技术
    • 液压应用
  • 计算机相关
    • 计算机和软件
    • 网络和网站技术
  • 哲学
  • 关于本站
Menu

NAT内网穿透相关知识[0]

Posted on 2023年11月14日 by

关于NAT,NAT可以分为锥型和对称型,其中锥型又可以分为完全锥型和限制型锥型,限制型锥型又可分为ip限制型锥型和端口限制型锥型,画成图的话大概就是如下的样子。

举例:

假定:

公网server1:ip是1.1.1.1,监听端口是1111

公网server2:ip是2.2.2.2,监听端口是2222

NAT网关:ip是3.3.3.3

NAT内部需要穿透的电脑A:内网ip是:192.168.0.2

此刻,A(192.168.0.2:100)已经通过NAT网关(3.3.3.3:200)和server1(1.1.1.1:1111)建立了链接

1)完全锥型:
如果在NAT网关已经建立了一个NAT映射,那么任何外网的机器都可以通过这个映射来访问内网的电脑,例如此刻server2如果想和A建立通信,那么只需要往3.3.3.3:200发送数据包,NAT网关就会接收数据包并将其转发到内部的192.168.0.2:100上。

    如果A主动使用同样的端口去和不同的服务器或和相同的服务器,不同的端口建立连接时,NAT的映射也会使用同样的端口,例如A若是想用100端口和server2建立连接,NAT网关仍然会把3.3.3.3:200映射到192.168.0.2:100上,而不是重新选择一个端口映射到100,如果这里不能理解,那就先往下看,等到下面介绍对称型NAT时,结合着对称型NAT看即可。

    在所有锥型网络中这一点都是一样的,这也正是锥型网络的特征,下面的两种锥型网络也是一样,虽然在此处声明后,不会在下面重新赘述一遍,但是请读者切记这一点。

2)ip限制型锥型:
如果在NAT网关已经建立了一个NAT映射,那么只有与其建立映射的ip才能通过NAT访问内网的电脑。例如此刻如果server1想通过1112这个端口和A再建立一个连接,那么只需要往3.3.3.3:200发送数据,NAT会正常的将其转发到192.168.0.2:100,但是如果此刻server2想和A建立连接,因为server2在此前并未和A建立连接,所以如果server2给3.3.3.3:200发送数据的话,NAT网关会将来自server2的数据包直接丢弃。

3)端口限制型锥型:
这个类型虽然叫端口限制型,但其实限制的不只是端口,ip也同样限制,可以理解为在ip限制型锥型的基础上,再进行端口的限制,也就是说现在不只对ip有需求,连端口都有需求,如果按照上面的例子,此刻如果server还想通过1112端口和A建立连接就不行了,因为限制了端口,只有从1.1.1.1:1111发来的数据NAT网关才会处理。

4)对称型NAT:
可以看出来,上述的三个类型限制是越来越严格,按照这个思路,对称型NAT的限制会更加严格。首先,对称型NAT和端口限制型锥型是一样的,即对ip和端口都有限制,只有和其建立连接的ip和端口向其发送数据才不会被丢弃。
  • NAT的共同特征
    每个TCP/IP数据包都包含一个源IP地址、源端口、目的IP地址和目的端口。 所有类型的NAT都使用这些值创建NAT映射。

NAT的四种类型
1、全锥型NAT(Full cone NAT),即一对一(one-to-one)NAT

一旦内部地址(iAddr:iPort)映射到外部地址(eAddr:ePort),所有发自 iAddr:iPort 的数据包都经由 eAddr:ePort 向外发送。
任意外部主机都能经由发送数据包给 eAddr:ePort 到达 iAddr:iPort。

2、IP受限锥型NAT((Address-)Restricted cone NAT)

一旦内部地址(iAddr:iPort)映射到外部地址(eAddr:ePort),所有发自 iAddr:iPort 的数据包都经由 eAddr:ePort 向外发送。
仅 iAddr:iPort 曾经发送数据包到外部主机(nAddr:any),外部主机才能经由发送数据包给 eAddr:ePort 到达 iAddr:iPort。(注:any 指外部主机源端口不受限制。)

3、端口受限锥型NAT(Port-Restricted cone NAT)

类似受限锥形NAT(Restricted cone NAT),但是还有端口限制。

一旦内部地址(iAddr:iPort)映射到外部地址(eAddr:ePort),所有发自 iAddr:iPort 的数据包都经由 eAddr:ePort 向外发送。
在受限锥型NAT基础上增加了外部主机源端口必须固定。

4、对称型NAT(Symmetric NAT)

每一个来自相同内部 IP 与端口,到一个特定目的地 IP 和端口的请求,都映射到一个独特的外部 IP和端口。同一内部 IP 与端口发到不同的目的地和端口的信息包,都使用不同的映射。
只有曾经收到过内部主机数据的外部主机,才能够把数据包发回。

  • 不同的NAT的穿透性

 

参考资料:

  1. https://www.bilibili.com/read/cv6189209/
  2. https://blog.51cto.com/20100823/401704
  3. https://pfschina.org/wp/

欢迎回来

希望本站对你有所帮助!

如有疑问请联系info@fanlog.org
2023 年 11 月
一二三四五六日
 12345
6789101112
13141516171819
20212223242526
27282930 
« 6 月    

AI辅助 (17)

© 2025 | Powered by Superbs Personal Blog theme
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT