[go: up one dir, main page]

CN113067910A - A NAT traversal method, device, electronic device and storage medium - Google Patents

A NAT traversal method, device, electronic device and storage medium Download PDF

Info

Publication number
CN113067910A
CN113067910A CN202010003261.4A CN202010003261A CN113067910A CN 113067910 A CN113067910 A CN 113067910A CN 202010003261 A CN202010003261 A CN 202010003261A CN 113067910 A CN113067910 A CN 113067910A
Authority
CN
China
Prior art keywords
nat
cpe
address information
type
network address
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202010003261.4A
Other languages
Chinese (zh)
Other versions
CN113067910B (en
Inventor
韩瑞波
李振强
李晗
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Mobile Communications Group Co Ltd
Research Institute of China Mobile Communication Co Ltd
Original Assignee
China Mobile Communications Group Co Ltd
Research Institute of China Mobile Communication Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by China Mobile Communications Group Co Ltd, Research Institute of China Mobile Communication Co Ltd filed Critical China Mobile Communications Group Co Ltd
Priority to CN202010003261.4A priority Critical patent/CN113067910B/en
Publication of CN113067910A publication Critical patent/CN113067910A/en
Application granted granted Critical
Publication of CN113067910B publication Critical patent/CN113067910B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/09Mapping addresses
    • H04L61/25Mapping addresses of the same type
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L63/00Network architectures or network communication protocols for network security
    • H04L63/04Network architectures or network communication protocols for network security for providing a confidential data exchange among entities communicating through data packet networks
    • H04L63/0428Network architectures or network communication protocols for network security for providing a confidential data exchange among entities communicating through data packet networks wherein the data content is protected, e.g. by encrypting or encapsulating the payload
    • H04L63/0485Networking architectures for enhanced packet encryption processing, e.g. offloading of IPsec packet processing or efficient security association look-up

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computing Systems (AREA)
  • Computer Hardware Design (AREA)
  • General Engineering & Computer Science (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)
  • Small-Scale Networks (AREA)

Abstract

The invention discloses a NAT (network Address translation) traversing method, a NAT traversing device, electronic equipment and a storage medium. The method comprises the following steps: determining the type of the first NAT equipment, the type of the second NAT equipment and public network address information corresponding to the second CPE after NAT; the first NAT equipment is connected with the first CPE, and the second NAT equipment is connected with the second CPE; and configuring an IPSEC tunnel and tunnel address information based on the type of the first NAT equipment, the type of the second NAT equipment and the public network address information corresponding to the second CPE and subjected to NAT.

Description

一种NAT穿越方法、装置、电子设备和存储介质A NAT traversal method, device, electronic device and storage medium

技术领域technical field

本发明涉及移动通信技术,尤其涉及一种网络地址转换(NAT,Network AddressTranslation)穿越方法、装置、电子设备和存储介质。The present invention relates to mobile communication technology, in particular to a network address translation (NAT, Network AddressTranslation) traversal method, device, electronic device and storage medium.

背景技术Background technique

互联网安全协议(IPSEC,Internet Protocol Security)隧道用于基于端对端的安全模式,在源地址和目标地址之间建立信任和安全性。运行在公网上的IPSEC隧道,两端必须至少一端具有公网地址,否则IPSEC隧道无法建立。Internet Protocol Security (IPSEC, Internet Protocol Security) tunnels are used in an end-to-end based security model to establish trust and security between source and destination addresses. For an IPSEC tunnel running on the public network, at least one end must have a public network address, otherwise the IPSEC tunnel cannot be established.

发明内容SUMMARY OF THE INVENTION

有鉴于此,本发明的主要目的在于提供一种NAT穿越方法、装置、电子设备和存储介质。In view of this, the main purpose of the present invention is to provide a NAT traversal method, apparatus, electronic device and storage medium.

为达到上述目的,本发明的技术方案是这样实现的:In order to achieve the above object, the technical scheme of the present invention is achieved in this way:

本发明实施例提供了一种NAT穿越方法,所述方法应用于第一客户前置设备(CPE,Customer Premise Equipment),所述方法包括:An embodiment of the present invention provides a NAT traversal method, the method is applied to a first customer premise equipment (CPE, Customer Premise Equipment), and the method includes:

确定第一NAT设备的类型、第二NAT设备的类型和相应于第二CPE的经NAT后的公网地址信息;所述第一NAT设备连接所述第一CPE,所述第二NAT设备连接第二CPE;Determine the type of the first NAT device, the type of the second NAT device, and the NATed public network address information corresponding to the second CPE; the first NAT device is connected to the first CPE, and the second NAT device is connected Second CPE;

基于所述第一NAT设备的类型、所述第二NAT设备的类型和所述相应于第二CPE的经NAT后的公网地址信息,配置IPSEC隧道和隧道地址信息。Based on the type of the first NAT device, the type of the second NAT device, and the NATed public network address information corresponding to the second CPE, configure an IPSEC tunnel and tunnel address information.

上述方案中,所述确定第二NAT设备的类型,包括:In the above scheme, the determining the type of the second NAT device includes:

接收服务器发送的第二NAT设备的类型。The type of the second NAT device sent by the receiving server.

上述方案中,所述方法还包括:In the above scheme, the method also includes:

向服务器发送第一测试报文;所述第一测试报文用于请求所述服务器发送第一结果报文;sending a first test message to the server; the first test message is used to request the server to send a first result message;

接收所述服务器发送的第一结果报文,基于所述第一结果报文确定自身连接的NAT设备的类型,将确定的自身连接的NAT设备的类型发送给所述服务器。Receive the first result message sent by the server, determine the type of the NAT device connected to itself based on the first result message, and send the determined type of the NAT device connected to itself to the server.

上述方案中,在所述第一NAT设备的类型为完全圆锥型NAT,且所述第二NAT设备的类型为基本NAT的情况下;确定相应于第二CPE的经NAT后的公网地址信息,包括:In the above scheme, when the type of the first NAT device is a complete cone NAT, and the type of the second NAT device is a basic NAT; determine the NATed public network address information corresponding to the second CPE ,include:

接收第二CPE发送的报文;receiving the message sent by the second CPE;

基于接收的所述报文确定相应于第二CPE的经NAT后的公网地址信息。The NATed public network address information corresponding to the second CPE is determined based on the received message.

上述方案中,所述方法还包括:In the above scheme, the method also includes:

向服务器发送第二测试报文;所述第二测试报文用于所述服务器确定相应于第一CPE的经NAT后的公网地址信息。Send a second test packet to the server; the second test packet is used by the server to determine the NATed public network address information corresponding to the first CPE.

上述方案中,所述方法还包括:In the above scheme, the method also includes:

基于配置的IPSEC隧道,发送目标地址为任意地址的报文;所述目标地址为任意地址的报文用于在第一NAT设备打洞。Based on the configured IPSEC tunnel, a message whose destination address is any address is sent; the message whose destination address is any address is used to punch holes in the first NAT device.

上述方案中,所述配置IPSEC隧道和隧道地址信息,包括:In the above scheme, the configuration IPSEC tunnel and tunnel address information includes:

配置IPSEC隧道的封装方式为隧道模式,以及配置采用NAT-T模式;Configure the encapsulation mode of the IPSEC tunnel as tunnel mode, and configure the NAT-T mode;

基于所述第一CPE自身的私网地址信息配置所述隧道地址信息中的源地址;Configure the source address in the tunnel address information based on the private network address information of the first CPE itself;

基于所述相应于第二CPE的经NAT后的公网地址信息配置所述隧道地址信息中的目的地址。The destination address in the tunnel address information is configured based on the NATed public network address information corresponding to the second CPE.

上述方案中,在所述第一NAT设备的类型为基本NAT,且所述第二NAT设备的类型为完全圆锥型NAT的情况下;确定相应于第二CPE的经NAT后的公网地址信息,包括:In the above scheme, when the type of the first NAT device is basic NAT, and the type of the second NAT device is a complete cone NAT; determine the NATed public network address information corresponding to the second CPE ,include:

接收服务器发送的相应于第二CPE的经NAT后的公网地址信息。The NATed public network address information corresponding to the second CPE sent by the server is received.

上述方案中,所述方法还包括:In the above scheme, the method also includes:

向第二CPE发送报文;发送的所述报文用于第二CPE确定相应于第一CPE的经NAT后的公网地址信息。Send a message to the second CPE; the sent message is used by the second CPE to determine the NATed public network address information corresponding to the first CPE.

上述方案中,所述配置IPSEC隧道和隧道地址信息,包括:In the above scheme, the configuration IPSEC tunnel and tunnel address information includes:

配置IPSEC隧道的封装方式为隧道模式,以及配置采用NAT-T模式;Configure the encapsulation mode of the IPSEC tunnel as tunnel mode, and configure the NAT-T mode;

基于所述第一CPE自身的私网地址信息配置所述隧道地址信息中的源地址;Configure the source address in the tunnel address information based on the private network address information of the first CPE itself;

基于所述相应于第二CPE的经NAT后的公网地址信息配置所述隧道地址信息中的目的地址。The destination address in the tunnel address information is configured based on the NATed public network address information corresponding to the second CPE.

上述方案中,在所述第一NAT设备的类型为完全圆锥型NAT,且所述第二NAT设备的类型为网络地址端口转换(NAPT,Network Address Port Translation)的情况下,或者,在所述第一NAT设备的类型为NAPT,且所述第二NAT设备的类型为完全圆锥型NAT的情况下;确定相应于第二CPE的经NAT后的公网地址信息,包括:In the above solution, in the case where the type of the first NAT device is a complete cone NAT, and the type of the second NAT device is a network address port translation (NAPT, Network Address Port Translation), or, in the described When the type of the first NAT device is NAPT, and the type of the second NAT device is a complete cone NAT; determine the NATed public network address information corresponding to the second CPE, including:

接收服务器发送的相应于第二CPE的经NAT后的公网地址信息。The NATed public network address information corresponding to the second CPE sent by the server is received.

上述方案中,所述配置IPSEC隧道和隧道地址信息,包括:In the above scheme, the configuration IPSEC tunnel and tunnel address information includes:

配置IPSEC隧道的封装方式为隧道模式,以及配置采用NAT-T模式;Configure the encapsulation mode of the IPSEC tunnel as tunnel mode, and configure the NAT-T mode;

基于所述第一CPE自身的私网地址信息配置所述隧道地址信息中的源地址;Configure the source address in the tunnel address information based on the private network address information of the first CPE itself;

基于所述相应于第二CPE的经NAT后的公网地址信息配置所述隧道地址信息中的目的地址。The destination address in the tunnel address information is configured based on the NATed public network address information corresponding to the second CPE.

上述方案中,所述方法还包括:In the above scheme, the method also includes:

基于配置的IPSEC隧道和隧道地址信息发送报文,发送的报文用于在第一NAT设备打洞。A packet is sent based on the configured IPSEC tunnel and tunnel address information, and the sent packet is used to punch holes in the first NAT device.

上述方案中,所述NAPT,包括以下至少之一:对称型NAT、完全圆锥型NAT、地址限制圆锥型NAT、端口限制圆锥型NAT。In the above solution, the NAPT includes at least one of the following: symmetric NAT, full cone NAT, address restricted cone NAT, and port restricted cone NAT.

上述方案中,所述隧道地址信息,包括以下至少之一:In the above solution, the tunnel address information includes at least one of the following:

第一CPE自身的私网地址信息、相应于第二CPE的经NAT后的公网地址信息。The private network address information of the first CPE itself corresponds to the NATed public network address information of the second CPE.

上述方案中,所述公网地址信息,包括:公网地址和端口号。In the above solution, the public network address information includes: a public network address and a port number.

上述方案中,其特征在于,所述报文包括:网际互连协议(IP,Internet Protocol)头、用户数据报协议(UDP)头、认证部分、封装安全负载(ESP)认证;In the above scheme, it is characterized in that the message includes: an Internet Protocol (IP, Internet Protocol) header, a User Datagram Protocol (UDP) header, an authentication part, and an Encapsulation Security Payload (ESP) authentication;

其中,所述认证部分包括:ESP头和加密部分;所述加密部分包括:原始IP头、传输控制协议(TCP,Transmission Control Protocol)、数据(DATA)、ESP尾。Wherein, the authentication part includes: an ESP header and an encrypted part; the encrypted part includes: an original IP header, a Transmission Control Protocol (TCP, Transmission Control Protocol), a data (DATA), and an ESP tail.

本发明实施例还提供了一种NAT穿越方法,所述方法应用于服务器,所述方法包括:The embodiment of the present invention also provides a NAT traversal method, the method is applied to the server, and the method includes:

确定第一NAT设备的类型和第二NAT设备的类型;所述第一NAT设备连接第一CPE,所述第二NAT设备连接第二CPE;Determine the type of the first NAT device and the type of the second NAT device; the first NAT device is connected to the first CPE, and the second NAT device is connected to the second CPE;

向所述第一CPE发送所述第二NAT设备的类型;向所述第二CPE发送所述第一NAT设备的类型;sending the type of the second NAT device to the first CPE; sending the type of the first NAT device to the second CPE;

在所述第一NAT设备的类型和所述第二NAT的设备满足预设条件的情况下,确定相应于第一CPE的经NAT后的公网地址信息,向第二CPE发送所述相应于第一CPE的经NAT后的公网地址信息;和/或,确定相应于第二CPE的经NAT后的公网地址信息,向第一CPE发送所述相应于第二CPE的经NAT后的公网地址信息;In the case that the type of the first NAT device and the device of the second NAT meet the preset conditions, determine the NATed public network address information corresponding to the first CPE, and send the information corresponding to the first CPE to the second CPE The NATed public network address information of the first CPE; and/or, determining the NATed public network address information corresponding to the second CPE, and sending the NATed public network address information corresponding to the second CPE to the first CPE. public network address information;

其中,所述公网地址信息用于配置IPSEC隧道和隧道地址信息。The public network address information is used to configure IPSEC tunnels and tunnel address information.

上述方案中,在所述第一NAT设备的类型为完全圆锥型NAT,且所述第二NAT设备的类型为基本NAT的情况下,确定相应于第一CPE的经NAT后的公网地址信息,向第二CPE发送所述相应于第一CPE的经NAT后的公网地址信息。In the above solution, when the type of the first NAT device is a complete cone NAT, and the type of the second NAT device is a basic NAT, the NATed public network address information corresponding to the first CPE is determined , and send the NATed public network address information corresponding to the first CPE to the second CPE.

上述方案中,在所述第一NAT设备的类型为基本NAT,且所述第二NAT设备的类型为完全圆锥型NAT的情况下,确定相应于第二CPE的经NAT后的公网地址信息,向第一CPE发送所述相应于第二CPE的经NAT后的公网地址信息。In the above solution, when the type of the first NAT device is a basic NAT, and the type of the second NAT device is a complete cone NAT, the NATed public network address information corresponding to the second CPE is determined , and send the NATed public network address information corresponding to the second CPE to the first CPE.

上述方案中,在所述第一NAT设备的类型为完全圆锥型NAT且所述第二NAT设备的类型为NAPT的情况下,或者,在所述第一NAT设备的类型为NAPT且所述第二NAT设备的类型为完全圆锥型NAT的情况下,确定相应于第一CPE的经NAT后的公网地址信息,向第二CPE发送所述相应于第一CPE的经NAT后的公网地址信息;以及,确定相应于第二CPE的经NAT后的公网地址信息,向第一CPE发送所述相应于第二CPE的经NAT后的公网地址信息。In the above solution, when the type of the first NAT device is a complete cone NAT and the type of the second NAT device is NAPT, or, when the type of the first NAT device is NAPT and the type of the second NAT device is NAPT. When the type of the second NAT device is a complete cone NAT, determine the NATed public network address information corresponding to the first CPE, and send the NATed public network address corresponding to the first CPE to the second CPE and determining the NATed public network address information corresponding to the second CPE, and sending the NATed public network address information corresponding to the second CPE to the first CPE.

上述方案中,所述NAPT,包括以下至少之一:In the above scheme, the NAPT includes at least one of the following:

对称型NAT、完全圆锥型NAT、地址限制圆锥型NAT、端口限制圆锥型NAT。Symmetric NAT, Full Cone NAT, Address Restriction Cone NAT, Port Restriction Cone NAT.

上述方案中,所述公网地址信息,包括:公网地址和端口号。In the above solution, the public network address information includes: a public network address and a port number.

上述方案中,所述确定第一NAT设备的类型和第二NAT设备的类型,包括:In the above scheme, the determining of the type of the first NAT device and the type of the second NAT device includes:

接收第一CPE发送的第一测试报文,基于所述第一测试报文发送第一结果报文;所述第一结果报文用于所述第一CPE确定自身连接的第一NAT设备的类型;接收所述第一CPE发送的自身连接的第一NAT设备的类型;Receive a first test packet sent by the first CPE, and send a first result packet based on the first test packet; the first result packet is used by the first CPE to determine the status of the first NAT device connected to itself. Type; the type of the first NAT device that receives the self-connection sent by the first CPE;

接收第二CPE发送的第三测试报文,基于所述第三测试报文发送第二结果报文;所述第二结果报文用于所述第二CPE确定自身连接的第二NAT设备的类型;接收所述第二CPE发送的自身连接的第二NAT设备的类型。Receive a third test packet sent by the second CPE, and send a second result packet based on the third test packet; the second result packet is used by the second CPE to determine the status of the second NAT device connected to itself. Type: the type of the second NAT device that receives the self-connection sent by the second CPE.

上述方案中,所述确定相应于第一CPE的经NAT后的公网地址信息,包括:In the above solution, the determining of the NATed public network address information corresponding to the first CPE includes:

接收第一CPE发送的第二测试报文;基于所述第一CPE发送的第二测试报文确定相应于第一CPE的经NAT后的公网地址信息;receiving a second test packet sent by the first CPE; determining the NATed public network address information corresponding to the first CPE based on the second test packet sent by the first CPE;

所述确定相应于第二CPE的经NAT后的公网地址信息,包括:The determining of the NATed public network address information corresponding to the second CPE includes:

接收第二CPE发送的第四测试报文;基于所述第二CPE发送的第四测试报文确定相应于第二CPE的经NAT后的公网地址信息。Receive a fourth test packet sent by the second CPE; and determine the NATed public network address information corresponding to the second CPE based on the fourth test packet sent by the second CPE.

本发明实施例还提供了一种NAT穿越装置,所述装置应用于第一CPE,所述装置包括:第一处理模块和第二处理模块;An embodiment of the present invention further provides a NAT traversal device, the device is applied to the first CPE, and the device includes: a first processing module and a second processing module;

所述第一处理模块,用于确定第一NAT设备的类型、第二NAT设备的类型和相应于第二CPE的经NAT后的公网地址信息;所述第一NAT设备连接所述第一CPE,所述第二NAT设备连接第二CPE;The first processing module is used to determine the type of the first NAT device, the type of the second NAT device and the NATed public network address information corresponding to the second CPE; the first NAT device is connected to the first CPE, the second NAT device is connected to the second CPE;

所述第二处理模块,用于基于所述第一NAT设备的类型、所述第二NAT设备的类型和所述相应于第二CPE的经NAT后的公网地址信息,配置IPSEC隧道和隧道地址信息。The second processing module is configured to configure IPSEC tunnels and tunnels based on the type of the first NAT device, the type of the second NAT device, and the NATed public network address information corresponding to the second CPE Address information.

上述方案中,所述第一处理模块,用于接收服务器发送的第二NAT设备的类型。In the above solution, the first processing module is configured to receive the type of the second NAT device sent by the server.

上述方案中,所述第一处理模块,还用于向服务器发送第一测试报文;所述第一测试报文用于请求所述服务器发送第一结果报文;In the above solution, the first processing module is further configured to send a first test message to the server; the first test message is used to request the server to send a first result message;

接收所述服务器发送的第一结果报文,基于所述第一结果报文确定自身连接的NAT设备的类型,将确定的自身连接的NAT设备的类型发送给所述服务器。Receive the first result message sent by the server, determine the type of the NAT device connected to itself based on the first result message, and send the determined type of the NAT device connected to itself to the server.

在一实施例中,在所述第一NAT设备的类型为完全圆锥型NAT,且所述第二NAT设备的类型为基本NAT的情况下;所述第一处理模块,具体用于接收第二CPE发送的报文;In one embodiment, when the type of the first NAT device is a complete cone NAT, and the type of the second NAT device is a basic NAT; the first processing module is specifically configured to receive the second NAT device. The message sent by the CPE;

基于接收的所述报文确定相应于第二CPE的经NAT后的公网地址信息。The NATed public network address information corresponding to the second CPE is determined based on the received message.

上述方案中,所述第一处理模块,还用于向服务器发送第二测试报文;所述第二测试报文用于所述服务器确定相应于第一CPE的经NAT后的公网地址信息。In the above solution, the first processing module is further configured to send a second test message to the server; the second test message is used for the server to determine the NATed public network address information corresponding to the first CPE .

具体地,所述第一处理模块,还用于基于配置的IPSEC隧道,发送目标地址为任意地址的报文;所述目标地址为任意地址的报文用于在第一NAT设备打洞。Specifically, the first processing module is further configured to, based on the configured IPSEC tunnel, send a message with a destination address of any address; the message with an arbitrary address as a destination address is used to punch holes in the first NAT device.

具体地,所述第二处理模块,用于配置IPSEC隧道的封装方式为隧道模式,以及配置采用NAT-T模式;Specifically, the second processing module is used to configure the encapsulation mode of the IPSEC tunnel as tunnel mode, and the configuration adopts NAT-T mode;

基于所述第一CPE自身的私网地址信息配置所述隧道地址信息中的源地址;Configure the source address in the tunnel address information based on the private network address information of the first CPE itself;

基于所述相应于第二CPE的经NAT后的公网地址信息配置所述隧道地址信息中的目的地址。The destination address in the tunnel address information is configured based on the NATed public network address information corresponding to the second CPE.

上述方案中,在所述第一NAT设备的类型为基本NAT,且所述第二NAT设备的类型为完全圆锥型NAT的情况下;所述第一处理模块,具体用于接收服务器发送的相应于第二CPE的经NAT后的公网地址信息。In the above scheme, in the case where the type of the first NAT device is a basic NAT, and the type of the second NAT device is a complete cone NAT; the first processing module is specifically configured to receive the corresponding data sent by the server. The NATed public network address information of the second CPE.

上述方案中,所述第一处理模块,还用于向第二CPE发送报文;发送的所述报文用于第二CPE确定相应于第一CPE的经NAT后的公网地址信息。In the above solution, the first processing module is further configured to send a message to the second CPE; the sent message is used by the second CPE to determine the NATed public network address information corresponding to the first CPE.

所述第二处理模块,用于配置IPSEC隧道的封装方式为隧道模式,以及配置采用NAT-T模式;The second processing module is used for configuring the encapsulation mode of the IPSEC tunnel to be a tunnel mode, and the configuration adopts a NAT-T mode;

基于所述第一CPE自身的私网地址信息配置所述隧道地址信息中的源地址;Configure the source address in the tunnel address information based on the private network address information of the first CPE itself;

基于所述相应于第二CPE的经NAT后的公网地址信息配置所述隧道地址信息中的目的地址。The destination address in the tunnel address information is configured based on the NATed public network address information corresponding to the second CPE.

上述方案中,在所述第一NAT设备的类型为完全圆锥型NAT,且所述第二NAT设备的类型为NAPT的情况下,或者,在所述第一NAT设备的类型为NAPT,且所述第二NAT设备的类型为完全圆锥型NAT的情况下;所述第一处理模块,具体用于接收服务器发送的相应于第二CPE的经NAT后的公网地址信息。In the above solution, when the type of the first NAT device is a complete cone NAT, and the type of the second NAT device is NAPT, or, when the type of the first NAT device is NAPT, and all When the type of the second NAT device is a complete cone NAT; the first processing module is specifically configured to receive the NATed public network address information corresponding to the second CPE sent by the server.

上述方案中,所述第二处理模块,用于配置IPSEC隧道的封装方式为隧道模式,以及配置采用NAT-T模式;In the above scheme, the second processing module is used to configure the encapsulation mode of the IPSEC tunnel as the tunnel mode, and the configuration adopts the NAT-T mode;

基于所述第一CPE自身的私网地址信息配置所述隧道地址信息中的源地址;Configure the source address in the tunnel address information based on the private network address information of the first CPE itself;

基于所述相应于第二CPE的经NAT后的公网地址信息配置所述隧道地址信息中的目的地址。The destination address in the tunnel address information is configured based on the NATed public network address information corresponding to the second CPE.

上述方案中,所述第一处理模块,还用于基于配置的IPSEC隧道和隧道地址信息发送报文,发送的报文用于在第一NAT设备打洞。In the above solution, the first processing module is further configured to send a message based on the configured IPSEC tunnel and tunnel address information, and the sent message is used for punching a hole in the first NAT device.

上述方案中,所述NAPT,包括以下至少之一:对称型NAT、完全圆锥型NAT、地址限制圆锥型NAT、端口限制圆锥型NAT。In the above solution, the NAPT includes at least one of the following: symmetric NAT, full cone NAT, address restricted cone NAT, and port restricted cone NAT.

上述方案中,所述隧道地址信息,包括以下至少之一:In the above solution, the tunnel address information includes at least one of the following:

第一CPE自身的私网地址信息、相应于第二CPE的经NAT后的公网地址信息。The private network address information of the first CPE itself corresponds to the NATed public network address information of the second CPE.

上述方案中,所述公网地址信息,包括:公网地址和端口号。In the above solution, the public network address information includes: a public network address and a port number.

上述方案中,所述报文包括:IP头、UDP头、认证部分、ESP认证;In the above solution, the packet includes: an IP header, a UDP header, an authentication part, and an ESP authentication;

其中,所述认证部分包括:ESP头和加密部分;所述加密部分包括:原始IP头、TCP、DATA、ESP尾。Wherein, the authentication part includes: ESP header and encryption part; and the encryption part includes: original IP header, TCP, DATA, and ESP tail.

本发明实施例还提供了一种NAT穿越装置,所述装置应用于服务器,所述装置包括:第三处理模块、第四处理模块和第五处理模块;其中,An embodiment of the present invention further provides a NAT traversal device, the device is applied to a server, and the device includes: a third processing module, a fourth processing module, and a fifth processing module; wherein,

所述第三处理模块,用于确定第一NAT设备的类型和第二NAT设备的类型;所述第一NAT设备连接第一CPE,所述第二NAT设备连接第二CPE;The third processing module is used to determine the type of the first NAT device and the type of the second NAT device; the first NAT device is connected to the first CPE, and the second NAT device is connected to the second CPE;

所述第四处理模块,用于向所述第一CPE发送所述第二NAT设备的类型;向所述第二CPE发送所述第一NAT设备的类型;The fourth processing module is configured to send the type of the second NAT device to the first CPE; send the type of the first NAT device to the second CPE;

所述第五处理模块,用于在所述第一NAT设备的类型和所述第二NAT的设备满足预设条件的情况下,确定相应于第一CPE的经NAT后的公网地址信息,向第二CPE发送所述相应于第一CPE的经NAT后的公网地址信息;和/或,确定相应于第二CPE的经NAT后的公网地址信息,向第一CPE发送所述相应于第二CPE的经NAT后的公网地址信息;The fifth processing module is configured to determine the NATed public network address information corresponding to the first CPE when the type of the first NAT device and the second NAT device meet preset conditions, Sending the NATed public network address information corresponding to the first CPE to the second CPE; and/or, determining the NATed public network address information corresponding to the second CPE, and sending the corresponding public network address information to the first CPE The NATed public network address information of the second CPE;

其中,所述公网地址信息用于配置IPSEC隧道和隧道地址信息。The public network address information is used to configure IPSEC tunnels and tunnel address information.

上述方案中,所述第五处理模块,用于在所述第一NAT设备的类型为完全圆锥型NAT,且所述第二NAT设备的类型为基本NAT的情况下,确定相应于第一CPE的经NAT后的公网地址信息,向第二CPE发送所述相应于第一CPE的经NAT后的公网地址信息。In the above solution, the fifth processing module is configured to determine the corresponding first CPE when the type of the first NAT device is a complete cone NAT and the type of the second NAT device is a basic NAT and send the NATed public network address information corresponding to the first CPE to the second CPE.

上述方案中,所述第五处理模块,用于在所述第一NAT设备的类型为基本NAT,且所述第二NAT设备的类型为完全圆锥型NAT的情况下,确定相应于第二CPE的经NAT后的公网地址信息,向第一CPE发送所述相应于第二CPE的经NAT后的公网地址信息。In the above solution, the fifth processing module is configured to determine the corresponding second CPE when the type of the first NAT device is a basic NAT and the type of the second NAT device is a complete cone NAT The NATed public network address information, and the NATed public network address information corresponding to the second CPE is sent to the first CPE.

上述方案中,所述第五处理模块,用于在所述第一NAT设备的类型为完全圆锥型NAT且所述第二NAT设备的类型为NAPT的情况下,或者,在所述第一NAT设备的类型为NAPT且所述第二NAT设备的类型为完全圆锥型NAT的情况下,确定相应于第一CPE的经NAT后的公网地址信息,向第二CPE发送所述相应于第一CPE的经NAT后的公网地址信息;以及,确定相应于第二CPE的经NAT后的公网地址信息,向第一CPE发送所述相应于第二CPE的经NAT后的公网地址信息。In the above solution, the fifth processing module is used for the case that the type of the first NAT device is a complete cone NAT and the type of the second NAT device is NAPT, or, in the case of the first NAT When the type of the device is NAPT and the type of the second NAT device is full cone NAT, determine the NATed public network address information corresponding to the first CPE, and send the information corresponding to the first CPE to the second CPE. The NATed public network address information of the CPE; and determining the NATed public network address information corresponding to the second CPE, and sending the NATed public network address information corresponding to the second CPE to the first CPE .

上述方案中,所述NAPT,包括以下至少之一:In the above scheme, the NAPT includes at least one of the following:

对称型NAT、完全圆锥型NAT、地址限制圆锥型NAT、端口限制圆锥型NAT。Symmetric NAT, Full Cone NAT, Address Restriction Cone NAT, Port Restriction Cone NAT.

上述方案中,所述公网地址信息,包括:公网地址和端口号。In the above solution, the public network address information includes: a public network address and a port number.

上述方案中,所述第三处理模块,用于接收第一CPE发送的第一测试报文,基于所述第一测试报文发送第一结果报文;所述第一结果报文用于所述第一CPE确定自身连接的第一NAT设备的类型;接收所述第一CPE发送的自身连接的第一NAT设备的类型;In the above solution, the third processing module is configured to receive a first test packet sent by the first CPE, and send a first result packet based on the first test packet; the first result packet is used for all The first CPE determines the type of the first NAT device that is connected to itself; receives the type of the first NAT device that is connected to itself sent by the first CPE;

接收第二CPE发送的第三测试报文,基于所述第三测试报文发送第二结果报文;所述第二结果报文用于所述第二CPE确定自身连接的第二NAT设备的类型;接收所述第二CPE发送的自身连接的第二NAT设备的类型。Receive a third test packet sent by the second CPE, and send a second result packet based on the third test packet; the second result packet is used by the second CPE to determine the status of the second NAT device connected to itself. Type: the type of the second NAT device that receives the self-connection sent by the second CPE.

上述方案中,所述第三处理模块,还用于接收第一CPE发送的第二测试报文;基于所述第一CPE发送的第二测试报文确定相应于第一CPE的经NAT后的公网地址信息;In the above solution, the third processing module is further configured to receive the second test packet sent by the first CPE; public network address information;

所述第三处理模块,还用于接收第二CPE发送的第四测试报文;基于所述第二CPE发送的第四测试报文确定相应于第二CPE的经NAT后的公网地址信息。The third processing module is further configured to receive a fourth test packet sent by the second CPE; and determine the NATed public network address information corresponding to the second CPE based on the fourth test packet sent by the second CPE .

本发明实施例还提供了一种电子设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,所述处理器执行所述程序时实现以上第一CPE侧任一项所述NAT穿越方法的步骤;或者,An embodiment of the present invention further provides an electronic device, including a memory, a processor, and a computer program stored in the memory and running on the processor, where the processor implements any one of the above first CPE sides when executing the program The steps of the NAT traversal method described in item; Or,

所述处理器执行所述程序时实现以上服务器侧任一项所述NAT穿越方法的步骤。When the processor executes the program, the steps of any one of the above NAT traversal methods on the server side are implemented.

本发明实施例还提供了一种计算机可读存储介质,其上存储有计算机程序,所述计算机程序被处理器执行时以上第一CPE侧任一项所述NAT穿越方法的步骤;或者,An embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of any one of the NAT traversal methods on the first CPE side above are performed; or,

所述处理器执行所述程序时实现以上服务器侧任一项所述NAT穿越方法的步骤。When the processor executes the program, the steps of any one of the above NAT traversal methods on the server side are implemented.

本发明实施例所提供的NAT穿越方法、装置、电子设备和存储介质,确定第一NAT设备的类型、第二NAT设备的类型和相应于第二CPE的经NAT后的公网地址信息;所述第一NAT设备连接所述第一CPE,所述第二NAT设备连接第二CPE;基于所述第一NAT设备的类型、所述第二NAT设备的类型和所述相应于第二CPE的经NAT后的公网地址信息,配置IPSEC隧道和隧道地址信息。采用本发明实施例的技术方案,在两端均连接有NAT设备、即不具有公网地址的场景下,也可建立IPSEC隧道。The NAT traversal method, device, electronic device, and storage medium provided by the embodiments of the present invention determine the type of the first NAT device, the type of the second NAT device, and the NATed public network address information corresponding to the second CPE; The first NAT device is connected to the first CPE, and the second NAT device is connected to the second CPE; based on the type of the first NAT device, the type of the second NAT device and the Configure IPSEC tunnel and tunnel address information based on the public network address information after NAT. With the technical solutions of the embodiments of the present invention, in a scenario where both ends are connected with NAT devices, that is, they do not have public network addresses, an IPSEC tunnel can also be established.

附图说明Description of drawings

图1为现有IPSEC隧道建立的一种架构图;Fig. 1 is a kind of architecture diagram of existing IPSEC tunnel establishment;

图2为现有IPSEC隧道建立的另一种架构图Figure 2 is another architecture diagram of the existing IPSEC tunnel establishment

图3为本发明实施例提供的一种NAT穿越方法的流程示意图;3 is a schematic flowchart of a NAT traversal method according to an embodiment of the present invention;

图4为本发明实施例提供的另一种NAT穿越方法的流程示意图;4 is a schematic flowchart of another NAT traversal method provided by an embodiment of the present invention;

图5为本发明实施例提供的一端穿越NAT的场景示意图;5 is a schematic diagram of a scenario in which one end traverses a NAT provided by an embodiment of the present invention;

图6为本发明实施例提供的再一种NAT穿越方法的流程示意图;6 is a schematic flowchart of still another NAT traversal method provided by an embodiment of the present invention;

图7为本发明实施例提供的一种第二报文的结构示意图;7 is a schematic structural diagram of a second packet according to an embodiment of the present invention;

图8为本发明实施例提供的一种第三报文的结构示意图;FIG. 8 is a schematic structural diagram of a third packet according to an embodiment of the present invention;

图9为本发明实施例提供的一种NAT穿越装置的结构示意图;9 is a schematic structural diagram of a NAT traversal device according to an embodiment of the present invention;

图10为本发明实施例提供的另一种NAT穿越装置的结构示意图;10 is a schematic structural diagram of another NAT traversal device provided by an embodiment of the present invention;

图11为本发明实施例提供的一种电子设备的结构示意图。FIG. 11 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.

具体实施方式Detailed ways

在结合实施例对本发明再作进一步详细的说明之前,先对IPSEC隧道的相关技术进行说明。Before the present invention is further described in detail with reference to the embodiments, the related technology of the IPSEC tunnel will be described first.

运行在公网上的IPSEC隧道,两端必须至少一端具有公网地址,否则IPSEC隧道无法建立。图1为现有IPSEC隧道建立的一种架构图;如图1所示的两种隧道至少一端具有公网地址(未连接有NAT设备),即可以建立IPSEC隧道。For an IPSEC tunnel running on the public network, at least one end must have a public network address, otherwise the IPSEC tunnel cannot be established. Fig. 1 is an architecture diagram of the establishment of an existing IPSEC tunnel; as shown in Fig. 1, at least one end of the two tunnels has a public network address (no NAT device is connected), that is, an IPSEC tunnel can be established.

图2为现有IPSEC隧道建立的另一种架构图,如图2所示,两端均不具有公网地址(均连接有NAT设备),实际无法建立IPSEC隧道。FIG. 2 is another architectural diagram of an existing IPSEC tunnel. As shown in FIG. 2, neither end has a public network address (both are connected to a NAT device), and an IPSEC tunnel cannot be established actually.

下面结合实施例对本发明再作进一步详细的说明。The present invention will be described in further detail below in conjunction with the embodiments.

图3为本发明实施例提供的一种NAT穿越方法的流程示意图;如图3所示,所述NAT穿越方法应用于第一CPE;所述方法包括:3 is a schematic flowchart of a NAT traversal method according to an embodiment of the present invention; as shown in FIG. 3 , the NAT traversal method is applied to the first CPE; the method includes:

步骤301、确定第一NAT设备的类型、第二NAT设备的类型和相应于第二CPE的经NAT后的公网地址信息;所述第一NAT设备连接所述第一CPE,所述第二NAT设备连接第二CPE;Step 301: Determine the type of the first NAT device, the type of the second NAT device, and the NATed public network address information corresponding to the second CPE; the first NAT device is connected to the first CPE, the second The NAT device connects to the second CPE;

步骤302、基于所述第一NAT设备的类型、所述第二NAT设备的类型和所述相应于第二CPE的经NAT后的公网地址信息,配置IPSEC隧道和隧道地址信息。Step 302: Based on the type of the first NAT device, the type of the second NAT device, and the NATed public network address information corresponding to the second CPE, configure an IPSEC tunnel and tunnel address information.

具体地,所述确定第二NAT设备的类型,包括:Specifically, the determining the type of the second NAT device includes:

接收服务器发送的第二NAT设备的类型。The type of the second NAT device sent by the receiving server.

这里,所述第二CPE通过与服务器进行相应的探测NAT设备类型的交互,确定第二CPE连接的NAT设备的类型,将得到的结果发送给服务器,从而服务器可以基于接收的结果向第一CPE发送第二NAT设备的类型。Here, the second CPE determines the type of the NAT device connected to the second CPE by interacting with the server to detect the type of the NAT device, and sends the obtained result to the server, so that the server can report to the first CPE based on the received result. Type of second NAT device sent.

具体地,所述方法还包括:Specifically, the method further includes:

向服务器发送第一测试报文;所述第一测试报文用于请求所述服务器发送第一结果报文;sending a first test message to the server; the first test message is used to request the server to send a first result message;

接收所述服务器发送的第一结果报文,基于所述第一结果报文确定自身连接的NAT设备的类型,将确定的自身连接的NAT设备的类型发送给所述服务器。Receive the first result message sent by the server, determine the type of the NAT device connected to itself based on the first result message, and send the determined type of the NAT device connected to itself to the server.

这里,所述第一CPE通过与服务器进行相应的探测NAT设备类型的交互(包括发送第一测试报文,接收第一结果报文),确定自身连接的NAT设备(即第一NAT设备)的类型。Here, the first CPE determines the NAT device (that is, the first NAT device) to which it is connected by interacting with the server to detect the type of the NAT device (including sending the first test packet and receiving the first result packet). type.

具体地,在所述第一NAT设备的类型为完全圆锥型NAT,且所述第二NAT设备的类型为基本NAT的情况下;确定相应于第二CPE的经NAT后的公网地址信息,包括:Specifically, when the type of the first NAT device is a complete cone NAT, and the type of the second NAT device is a basic NAT; determine the NATed public network address information corresponding to the second CPE, include:

接收第二CPE发送的报文;receiving the message sent by the second CPE;

基于接收的所述报文确定相应于第二CPE的经NAT后的公网地址信息。The NATed public network address information corresponding to the second CPE is determined based on the received message.

这里,接收的所述报文包括或者携带有相应于第二CPE的经NAT后的公网地址信息。Here, the received message includes or carries the NATed public network address information corresponding to the second CPE.

这里,可以理解为第二CPE发送报文,发送的所述报文包括或携带有地址,所述报文经NAT后由第一CPE接收,显示的地址即为相应于第二CPE的经NAT后的公网地址信息,即所述第一CPE基于接收的报文可以确定相应于第二CPE的经NAT后的公网地址信息。Here, it can be understood that the second CPE sends a message, the sent message includes or carries an address, the message is received by the first CPE after NAT, and the displayed address is the NATed address corresponding to the second CPE After the public network address information, that is, the first CPE can determine the NATed public network address information corresponding to the second CPE based on the received message.

具体地,所述方法还包括:Specifically, the method further includes:

向服务器发送第二测试报文;所述第二测试报文用于所述服务器确定相应于第一CPE的经NAT后的公网地址信息。Send a second test packet to the server; the second test packet is used by the server to determine the NATed public network address information corresponding to the first CPE.

这里,可以理解为第一CPE发送报文,发送的报文包括或携带有地址,所述报文经NAT后由服务器接收,显示的地址即为相应于第一CPE的经NAT后的公网地址信息,即所述服务器基于接收的报文可以确定相应于第一CPE的经NAT后的公网地址信息。Here, it can be understood that the first CPE sends a message, the sent message includes or carries an address, the message is received by the server after NAT, and the displayed address is the NATed public network corresponding to the first CPE Address information, that is, the server can determine the NATed public network address information corresponding to the first CPE based on the received message.

具体地,所述方法还包括:Specifically, the method further includes:

基于配置的IPSEC隧道,发送目标地址为任意地址的报文;所述目标地址为任意地址的报文用于在第一NAT设备打洞。Based on the configured IPSEC tunnel, a message whose destination address is any address is sent; the message whose destination address is any address is used to punch holes in the first NAT device.

具体地,所述配置IPSEC隧道和隧道地址信息,包括:Specifically, the configuration of the IPSEC tunnel and the tunnel address information includes:

配置IPSEC隧道的封装方式为隧道模式,以及配置采用NAT-T模式;Configure the encapsulation mode of the IPSEC tunnel as tunnel mode, and configure the NAT-T mode;

基于所述第一CPE自身的私网地址信息配置所述隧道地址信息中的源地址;Configure the source address in the tunnel address information based on the private network address information of the first CPE itself;

基于所述相应于第二CPE的经NAT后的公网地址信息配置所述隧道地址信息中的目的地址。The destination address in the tunnel address information is configured based on the NATed public network address information corresponding to the second CPE.

这里,所述IPSEC隧道的工作模式,包括有隧道(tunnel)模式,即CPE发送的整个IP数据包被用来计算认证头(AH,Authentication Header)或封装安全载荷(ESP,Encapsulating Security Payload)头,这里,所述AH或ESP头以及ESP加密的数据被封装在一个新的IP数据包中。通常,隧道模式应用在两个网关之间的通讯。Here, the working mode of the IPSEC tunnel includes a tunnel mode, that is, the entire IP data packet sent by the CPE is used to calculate the Authentication Header (AH, Authentication Header) or Encapsulating Security Payload (ESP, Encapsulating Security Payload) header. , where the AH or ESP header and ESP-encrypted data are encapsulated in a new IP packet. Typically, tunnel mode is used for communication between two gateways.

NAT-T模式指通过将ESP协议包封装到用户数据报协议(UDP,User DatagramProtocol)包中(在原ESP协议的IP数据包头外添加新的IP头和UDP头),使得NAT对待它就像对待一个普通的UDP包一样,从而支持ESP的传输模式以一对多的形式与NAT共存。NAT-T mode means that by encapsulating ESP protocol packets into User Datagram Protocol (UDP, User Datagram Protocol) packets (adding new IP headers and UDP headers to the IP data packet headers of the original ESP protocol), NAT treats it as if it were Like a normal UDP packet, the transport mode that supports ESP coexists with NAT in a one-to-many manner.

具体地,采用NAT-T模式,发送的报文包括:网际互连协议(IP,InternetProtocol)头、用户数据报协议(UDP)头、认证部分、封装安全负载(ESP)认证;Specifically, the NAT-T mode is adopted, and the sent message includes: Internet Protocol (IP, Internet Protocol) header, User Datagram Protocol (UDP) header, authentication part, and Encapsulating Security Payload (ESP) authentication;

其中,所述认证部分包括:ESP头和加密部分;所述加密部分包括:原始IP头、传输控制协议(TCP,Transmission Control Protocol)、数据(DATA)、ESP尾。Wherein, the authentication part includes: an ESP header and an encrypted part; the encrypted part includes: an original IP header, a Transmission Control Protocol (TCP, Transmission Control Protocol), a data (DATA), and an ESP tail.

具体地,在所述第一NAT设备的类型为基本NAT,且所述第二NAT设备的类型为完全圆锥型NAT的情况下;确定相应于第二CPE的经NAT后的公网地址信息,包括:Specifically, when the type of the first NAT device is a basic NAT, and the type of the second NAT device is a complete cone NAT; determine the NATed public network address information corresponding to the second CPE, include:

接收服务器发送的相应于第二CPE的经NAT后的公网地址信息。The NATed public network address information corresponding to the second CPE sent by the server is received.

这里,所述服务器确定相应于第二CPE的经NAT后的公网地址信息,即可将所述相应于第二CPE的经NAT后的公网地址信息发送给第一CPE。Here, the server determines the NATed public network address information corresponding to the second CPE, and may send the NATed public network address information corresponding to the second CPE to the first CPE.

具体地,所述方法还包括:Specifically, the method further includes:

向第二CPE发送报文;发送的所述报文用于第二CPE确定相应于第一CPE的经NAT后的公网地址信息。Send a message to the second CPE; the sent message is used by the second CPE to determine the NATed public network address information corresponding to the first CPE.

这里,所述第一CPE向第二CPE发送报文,发送的报文携带有相应的地址信息,当所述报文经过NAT后由第二CPE接收,所述第二CPE基于报文确定的地址即为相应于第一CPE的经NAT后的公网地址信息。Here, the first CPE sends a packet to the second CPE, and the sent packet carries the corresponding address information. After the packet is NATed, the second CPE receives the packet, and the second CPE determines based on the packet. The address is the NATed public network address information corresponding to the first CPE.

具体地,所述配置IPSEC隧道和隧道地址信息,包括:Specifically, the configuration of the IPSEC tunnel and the tunnel address information includes:

配置IPSEC隧道的封装方式为隧道模式,以及配置采用NAT-T模式;Configure the encapsulation mode of the IPSEC tunnel as tunnel mode, and configure the NAT-T mode;

基于所述第一CPE自身的私网地址信息配置所述隧道地址信息中的源地址;Configure the source address in the tunnel address information based on the private network address information of the first CPE itself;

基于所述相应于第二CPE的经NAT后的公网地址信息配置所述隧道地址信息中的目的地址。The destination address in the tunnel address information is configured based on the NATed public network address information corresponding to the second CPE.

需要说明的是,在上述第一NAT设备的类型为完全圆锥型NAT,且所述第二NAT设备的类型为基本NAT的情况下的第一CPE,即为在所述第一NAT设备的类型为基本NAT,且所述第二NAT设备的类型为完全圆锥型NAT的情况下的第二CPE;It should be noted that the first CPE in the case where the type of the first NAT device is full cone NAT and the type of the second NAT device is basic NAT is the type of the first NAT device. is a basic NAT, and the type of the second NAT device is the second CPE in the case of a complete cone NAT;

在上述第一NAT设备的类型为完全圆锥型NAT,且所述第二NAT设备的类型为基本NAT的情况下的第二CPE,即为在所述第一NAT设备的类型为基本NAT,且所述第二NAT设备的类型为完全圆锥型NAT的情况下的第一CPE。The second CPE in the case where the type of the first NAT device is full cone NAT and the type of the second NAT device is basic NAT, that is, the type of the first NAT device is basic NAT, and The type of the second NAT device is the first CPE in the case of a full cone NAT.

通过上述针对两种情况的描述,以说明两端CPE分别所做操作。The above descriptions for the two cases illustrate the operations performed by the CPEs at both ends respectively.

具体地,在所述第一NAT设备的类型为完全圆锥型NAT,且所述第二NAT设备的类型为NAPT的情况下,或者,在所述第一NAT设备的类型为NAPT,且所述第二NAT设备的类型为完全圆锥型NAT的情况下;确定相应于第二CPE的经NAT后的公网地址信息,包括:Specifically, in the case where the type of the first NAT device is a full cone NAT and the type of the second NAT device is NAPT, or, in the case where the type of the first NAT device is NAPT, and the When the type of the second NAT device is a complete cone NAT; determine the NATed public network address information corresponding to the second CPE, including:

接收服务器发送的相应于第二CPE的经NAT后的公网地址信息。The NATed public network address information corresponding to the second CPE sent by the server is received.

具体地,所述配置IPSEC隧道和隧道地址信息,包括:Specifically, the configuration of the IPSEC tunnel and the tunnel address information includes:

配置IPSEC隧道的封装方式为隧道模式,以及配置采用NAT-T模式;Configure the encapsulation mode of the IPSEC tunnel as tunnel mode, and configure the NAT-T mode;

基于所述第一CPE自身的私网地址信息配置所述隧道地址信息中的源地址;Configure the source address in the tunnel address information based on the private network address information of the first CPE itself;

基于所述相应于第二CPE的经NAT后的公网地址信息配置所述隧道地址信息中的目的地址。The destination address in the tunnel address information is configured based on the NATed public network address information corresponding to the second CPE.

具体地,所述方法还包括:Specifically, the method further includes:

基于配置的IPSEC隧道和隧道地址信息发送报文,发送的报文用于在第一NAT设备打洞。A packet is sent based on the configured IPSEC tunnel and tunnel address information, and the sent packet is used to punch holes in the first NAT device.

具体地,所述NAPT,包括以下至少之一:对称型NAT、完全圆锥型NAT、地址限制圆锥型NAT、端口限制圆锥型NAT。Specifically, the NAPT includes at least one of the following: symmetric NAT, full cone NAT, address restricted cone NAT, and port restricted cone NAT.

需要说明的是,在所述第一NAT设备的类型为完全圆锥型NAT,且所述第二NAT设备的类型为NAPT的情况下的第一CPE,即为在所述第一NAT设备的类型为NAPT,且所述第二NAT设备的类型为完全圆锥型NAT的情况下的第二CPE;反之,在所述第一NAT设备的类型为完全圆锥型NAT,且所述第二NAT设备的类型为NAPT的情况下的第二CPE,即为在所述第一NAT设备的类型为NAPT,且所述第二NAT设备的类型为完全圆锥型NAT的情况下的第一CPE。It should be noted that when the type of the first NAT device is full cone NAT and the type of the second NAT device is NAPT, the first CPE is the type of the first NAT device is NAPT, and the second CPE in the case where the type of the second NAT device is a complete cone NAT; otherwise, when the type of the first NAT device is a complete cone NAT, and the second NAT device is The second CPE when the type is NAPT is the first CPE when the type of the first NAT device is NAPT and the type of the second NAT device is full cone NAT.

在所述第一NAT设备的类型为完全圆锥型NAT,且所述第二NAT设备的类型为NAPT的情况下,或者,在所述第一NAT设备的类型为NAPT,且所述第二NAT设备的类型为完全圆锥型NAT的情况下,第一CPE和第二CPE所做操作相同。In the case where the type of the first NAT device is full cone NAT and the type of the second NAT device is NAPT, or, in the case where the type of the first NAT device is NAPT, and the second NAT device is of type NAPT When the device type is full cone NAT, the operations performed by the first CPE and the second CPE are the same.

具体地,所述隧道地址信息,包括以下至少之一:Specifically, the tunnel address information includes at least one of the following:

第一CPE自身的私网地址信息、相应于第二CPE的经NAT后的公网地址信息。The private network address information of the first CPE itself corresponds to the NATed public network address information of the second CPE.

具体地,所述公网地址信息,包括:公网地址和端口号。Specifically, the public network address information includes: a public network address and a port number.

具体地,所述报文包括:网际互连协议(IP)头、用户数据报协议(UDP)头、认证部分、封装安全负载(ESP)认证;Specifically, the message includes: an Internet Protocol (IP) header, a User Datagram Protocol (UDP) header, an authentication part, and an Encapsulating Security Payload (ESP) authentication;

其中,所述认证部分包括:ESP头和加密部分;所述加密部分包括:原始IP头、传输控制协议TCP、DATA、ESP尾。Wherein, the authentication part includes: ESP header and encryption part; and the encryption part includes: original IP header, transmission control protocol TCP, DATA, and ESP tail.

图4为本发明实施例提供的一种NAT穿越方法的流程示意图;如图4所示,所述NAT穿越方法应用于服务器,所述方法包括:FIG. 4 is a schematic flowchart of a NAT traversal method provided by an embodiment of the present invention; as shown in FIG. 4 , the NAT traversal method is applied to a server, and the method includes:

步骤401、确定第一NAT设备的类型和第二NAT设备的类型;所述第一NAT设备连接第一CPE,所述第二NAT设备连接第二CPE;Step 401, determine the type of the first NAT device and the type of the second NAT device; the first NAT device is connected to the first CPE, and the second NAT device is connected to the second CPE;

步骤402、向所述第一CPE发送所述第二NAT设备的类型;向所述第二CPE发送所述第一NAT设备的类型;Step 402, sending the type of the second NAT device to the first CPE; sending the type of the first NAT device to the second CPE;

步骤403、在所述第一NAT设备的类型和所述第二NAT的设备满足预设条件的情况下,确定相应于第一CPE的经NAT后的公网地址信息,向第二CPE发送所述相应于第一CPE的经NAT后的公网地址信息;和/或,确定相应于第二CPE的经NAT后的公网地址信息,向第一CPE发送所述相应于第二CPE的经NAT后的公网地址信息;Step 403: Under the condition that the type of the first NAT device and the device of the second NAT meet the preset conditions, determine the NATed public network address information corresponding to the first CPE, and send the information to the second CPE. describe the NATed public network address information corresponding to the first CPE; and/or determine the NATed public network address information corresponding to the second CPE, and send the NATed public network address information corresponding to the second CPE to the first CPE Public network address information after NAT;

其中,所述公网地址信息用于配置IPSEC隧道和隧道地址信息。The public network address information is used to configure IPSEC tunnels and tunnel address information.

具体地,在所述第一NAT设备的类型为完全圆锥型NAT,且所述第二NAT设备的类型为基本NAT的情况下(即在所述第一NAT设备的类型和所述第二NAT的设备满足一种预设条件的情况下),确定相应于第一CPE的经NAT后的公网地址信息,向第二CPE发送所述相应于第一CPE的经NAT后的公网地址信息。Specifically, when the type of the first NAT device is full cone NAT, and the type of the second NAT device is basic NAT (that is, when the type of the first NAT device and the second NAT device are If the device meets a preset condition), determine the NATed public network address information corresponding to the first CPE, and send the NATed public network address information corresponding to the first CPE to the second CPE .

具体地,在所述第一NAT设备的类型为基本NAT,且所述第二NAT设备的类型为完全圆锥型NAT的情况下(即在所述第一NAT设备的类型和所述第二NAT的设备满足另一种预设条件的情况下),确定相应于第二CPE的经NAT后的公网地址信息,向第一CPE发送所述相应于第二CPE的经NAT后的公网地址信息。Specifically, in the case where the type of the first NAT device is basic NAT and the type of the second NAT device is full cone NAT (that is, when the type of the first NAT device and the second NAT device are If the device satisfies another preset condition), determine the NATed public network address information corresponding to the second CPE, and send the NATed public network address corresponding to the second CPE to the first CPE information.

具体地,在所述第一NAT设备的类型为完全圆锥型NAT且所述第二NAT设备的类型为NAPT的情况下,或者,在所述第一NAT设备的类型为NAPT且所述第二NAT设备的类型为完全圆锥型NAT的情况下(即在所述第一NAT设备的类型和所述第二NAT的设备满足再一种预设条件的情况下),确定相应于第一CPE的经NAT后的公网地址信息,向第二CPE发送所述相应于第一CPE的经NAT后的公网地址信息;以及,确定相应于第二CPE的经NAT后的公网地址信息,向第一CPE发送所述相应于第二CPE的经NAT后的公网地址信息。Specifically, when the type of the first NAT device is full cone NAT and the type of the second NAT device is NAPT, or, in the case where the type of the first NAT device is NAPT and the type of the second NAT device is NAPT In the case that the type of the NAT device is a complete cone NAT (that is, in the case that the type of the first NAT device and the device of the second NAT meet another preset condition), determine the NAT device corresponding to the first CPE. After the NATed public network address information, send the NATed public network address information corresponding to the first CPE to the second CPE; The first CPE sends the NATed public network address information corresponding to the second CPE.

具体地,所述NAPT,包括以下至少之一:Specifically, the NAPT includes at least one of the following:

对称型NAT、完全圆锥型NAT、地址限制圆锥型NAT、端口限制圆锥型NAT。Symmetric NAT, Full Cone NAT, Address Restriction Cone NAT, Port Restriction Cone NAT.

具体地,所述公网地址信息,包括:公网地址和端口号。Specifically, the public network address information includes: a public network address and a port number.

具体地,所述确定第一NAT设备的类型和第二NAT设备的类型,包括:Specifically, the determining of the type of the first NAT device and the type of the second NAT device includes:

接收第一CPE发送的第一测试报文,基于所述第一测试报文发送第一结果报文;所述第一结果报文用于所述第一CPE确定自身连接的第一NAT设备的类型;接收所述第一CPE发送的自身连接的第一NAT设备的类型;Receive a first test packet sent by the first CPE, and send a first result packet based on the first test packet; the first result packet is used by the first CPE to determine the status of the first NAT device connected to itself. Type; the type of the first NAT device that receives the self-connection sent by the first CPE;

接收第二CPE发送的第三测试报文,基于所述第三测试报文发送第二结果报文;所述第二结果报文用于所述第二CPE确定自身连接的第二NAT设备的类型;接收所述第二CPE发送的自身连接的第二NAT设备的类型。Receive a third test packet sent by the second CPE, and send a second result packet based on the third test packet; the second result packet is used by the second CPE to determine the status of the second NAT device connected to itself. Type: the type of the second NAT device that receives the self-connection sent by the second CPE.

具体地,所述确定相应CPE经NAT后的公网地址信息,包括:Specifically, the determining of the NATed public network address information of the corresponding CPE includes:

接收第一CPE发送的第二测试报文;基于所述第一CPE发送的第二测试报文确定相应于第一CPE的经NAT后的公网地址信息;receiving a second test packet sent by the first CPE; determining the NATed public network address information corresponding to the first CPE based on the second test packet sent by the first CPE;

所述确定相应于第二CPE的经NAT后的公网地址信息,包括:The determining of the NATed public network address information corresponding to the second CPE includes:

接收第二CPE发送的第四测试报文;基于所述第二CPE发送的第四测试报文确定相应于第二CPE的经NAT后的公网地址信息。Receive a fourth test packet sent by the second CPE; and determine the NATed public network address information corresponding to the second CPE based on the fourth test packet sent by the second CPE.

所述第二测试报文与所述第四测试报文功能相同,针对第一CPE发送的第二测试报文,可以确定相应于第一CPE的经NAT后的公网地址信息;针对第二CPE发送的第四测试报文,可以确定相应于第二CPE的经NAT后的公网地址信息。The second test packet has the same function as the fourth test packet. For the second test packet sent by the first CPE, the NATed public network address information corresponding to the first CPE can be determined; The fourth test packet sent by the CPE may determine the NATed public network address information corresponding to the second CPE.

以下结合上述图3和图4所示方法对两端进行NAT穿越做详细说明。The NAT traversal at both ends will be described in detail below with reference to the methods shown in FIG. 3 and FIG. 4 .

在一实施例中,所述两端包括CPEA和CPEB,所述CPEA连接第一NAT设备、且所述第一NAT设备的类型为完全圆锥型NAT;所述CPEB连接第二NAT设备,所述第二NAT设备的类型为基本NAT;所述两端进行NAT穿越的方法,包括:In one embodiment, the two ends include a CPEA and a CPEB, the CPEA is connected to a first NAT device, and the type of the first NAT device is a full cone NAT; the CPEB is connected to a second NAT device, the The type of the second NAT device is basic NAT; the method for performing NAT traversal at the two ends includes:

步骤01、CPEA与服务器进行交互(具体指发送第一测试报文),以确定第一NAT设备的类型,并发送给服务器;以及,CPEB与服务器进行交互(具体指发送第三测试报文),以确定第二NAT设备的类型,并发送给服务器;Step 01, CPEA interacts with the server (specifically refers to sending the first test message) to determine the type of the first NAT device, and sends it to the server; and, CPEB interacts with the server (specifically refers to sending the third test message) , to determine the type of the second NAT device and send it to the server;

步骤02、服务器向所述CPEA发送所述第二NAT设备的类型;向所述CPEB发送所述第一NAT设备的类型;Step 02, the server sends the type of the second NAT device to the CPEA; sends the type of the first NAT device to the CPEB;

步骤03、所述服务器基于所述第二测试报文,确定相应于CPEA的经NAT后的公网地址信息,向CPEB发送所述相应于CPEA的经NAT后的公网地址信息;Step 03, the server determines the NATed public network address information corresponding to CPEA based on the second test message, and sends the NATed public network address information corresponding to CPEA to CPEB;

步骤04、CPEA配置IPSEC隧道采用隧道模式封装、并开启NAT-T模式,源地址为本端私网地址和因特网密钥交换协议(IKE,Internet Key Exchange)端口号(4500),基于上述配置发送目标地址为任意地址的报文,用于在第一NAT设备打洞;Step 04, CPEA configures the IPSEC tunnel to encapsulate in tunnel mode, and opens NAT-T mode, the source address is the private network address of the end and the Internet Key Exchange Protocol (IKE, Internet Key Exchange) port number (4500), based on the above configuration to send A packet whose destination address is any address is used to punch holes in the first NAT device;

步骤05、CPEB配置IPSEC隧道采用隧道模式封装、并开启NAT-T模式,源地址为本端私网地址和端口号AAA(经过类型为基本NAT的NAT设备后,端口号仍为AAA),基于上述配置向CPEA发送报文包;Step 05. CPEB configures the IPSEC tunnel to be encapsulated in tunnel mode and enables NAT-T mode. The source address is the private network address of the end and the port number AAA (the port number is still AAA after passing through a NAT device whose type is basic NAT). The above configuration sends packets to CPEA;

步骤06、CPEA接收CPEB发送的报文后,确定相应于CPEB的经NAT后的公网地址信息;Step 06, after CPEA receives the message sent by CPEB, determines the public network address information after NAT corresponding to CPEB;

步骤07、CPEA和CPEB间经IPSEC隧道进行常规报文的交互。In step 07, regular packets are exchanged between the CPEA and the CPEB through the IPSEC tunnel.

在另一实施例中,所述两端包括CPEA和CPEB,所述CPEA连接第一NAT设备、且所述第一NAT设备的类型为完全圆锥型NAT;所述CPEB连接第二NAT设备,所述第二NAT设备的类型为NAPT;所述两端进行NAT穿越的方法,包括:In another embodiment, the two ends include CPEA and CPEB, the CPEA is connected to a first NAT device, and the type of the first NAT device is a full cone NAT; the CPEB is connected to the second NAT device, so The type of the second NAT device is NAPT; the method for NAT traversal at the two ends includes:

步骤11、CPEA与服务器进行交互(具体指发送第一测试报文),以确定第一NAT设备的类型,并发送给服务器;以及,CPEB与服务器进行交互(具体指发送第三测试报文),以确定第二NAT设备的类型,并发送给服务器;Step 11, CPEA interacts with the server (specifically refers to sending the first test message) to determine the type of the first NAT device, and sends it to the server; and, CPEB interacts with the server (specifically refers to sending the third test message) , to determine the type of the second NAT device and send it to the server;

步骤12、服务器向所述CPEA发送所述第二NAT设备的类型;向所述CPEB发送所述第一NAT设备的类型;Step 12, the server sends the type of the second NAT device to the CPEA; sends the type of the first NAT device to the CPEB;

步骤13、所述服务器基于所述第二测试报文(也可以直接采用上述第一测试报文),确定相应于CPEA的经NAT后的公网地址信息,向CPEB发送所述相应于CPEA的经NAT后的公网地址信息;Step 13: The server determines the NATed public network address information corresponding to the CPEA based on the second test message (the above-mentioned first test message can also be used directly), and sends the information corresponding to the CPEA to the CPEB. Public network address information after NAT;

步骤14、所述服务器基于所述第四测试报文(也可以直接采用上述第三测试报文),确定相应于CPEA的经NAT后的公网地址信息,向CPEB发送所述相应于CPEA的经NAT后的公网地址信息;Step 14: The server determines the NATed public network address information corresponding to the CPEA based on the fourth test message (the above-mentioned third test message can also be used directly), and sends the information corresponding to the CPEA to the CPEB. Public network address information after NAT;

步骤15、服务器向CPEA发送用于告知CPEB仅NAT转换后的公网地址信息的报文;以及,服务器向CPEB发送用于告知CPEA仅NAT转换后的公网地址信息的报文;Step 15, the server sends to CPEA the message for informing CPEB of only the public network address information after NAT conversion; And, the server sends to CPEB the message for informing CPEA that only the public network address information after NAT conversion;

这里,相应于CPEB的经NAT后的公网地址信息,具体包括:公网地址和端口号BBB(NAT转换前端口号为AAA)。Here, the NATed public network address information corresponding to the CPEB specifically includes: the public network address and the port number BBB (the port number before the NAT conversion is AAA).

这里,相应于CPEA的经NAT后的公网地址信息,具体包括:公网地址和端口号CCC(NAT转换前端口号为IKE端口号4500);Here, the public network address information after NAT corresponding to CPEA specifically includes: public network address and port number CCC (the port number before NAT conversion is IKE port number 4500);

步骤16、CPEA配置IPSEC采用隧道模式封装、并开启NAT-T模式,基于上述配置发送源地址为本端私网地址和IKE端口号4500,目的地址为相应于CPEB的经NAT后的公网地址和端口号BBB的报文,发送的报文用于在CPEA连接的NAT设备打洞;Step 16. CPEA configures IPSEC to encapsulate in tunnel mode and enables NAT-T mode. Based on the above configuration, the sending source address is the private network address of the end and the IKE port number 4500, and the destination address is the NATed public network address corresponding to CPEB. and port number BBB, the sent message is used to punch holes in the NAT device connected to CPEA;

步骤17、CPEB配置IPSEC采用隧道模式封装、并开启NAT-T模式,基于上述配置发送源地址为本端私网地址和端口号AAA,目的地址为相应于CPEA的经NAT后的公网地址和端口CCC(NAT前端口号为IKE端口号4500)的报文,发送的报文用于在CPEB连接的NAT设备打洞;Step 17. CPEB configures IPSEC to encapsulate in tunnel mode and enables NAT-T mode. Based on the above configuration, the sending source address is the private network address and port number AAA of the end, and the destination address is the NATed public network address corresponding to CPEA and the port number AAA. Packet of port CCC (the port number before NAT is IKE port number 4500), the sent packet is used to punch holes in the NAT device connected to CPEB;

步骤18、经过上述配置,CPEA和CPEB间建立IPSEC隧道,CPEA和CPEB间经IPSEC隧道进行常规报文转发。Step 18: After the above configuration, an IPSEC tunnel is established between CPEA and CPEB, and regular packets are forwarded between CPEA and CPEB through the IPSEC tunnel.

这里,针对图3和图4所示方法中的各类NAT分别进行说明。Here, various types of NATs in the methods shown in FIG. 3 and FIG. 4 are described respectively.

NAT主要可以分为两类:基本NAT、NAPT(Network Address Port Translation);其中,NAT can be mainly divided into two categories: basic NAT and NAPT (Network Address Port Translation); among them,

所述基本NAT,一般适用于NAT设备拥有多个公网网际互连协议(IP,InternetProtocol)地址(以下简称公网地址)的情形下,将公网地址与内网主机进行静态绑定,这种类型的NAT设备较少。The basic NAT is generally applicable to statically binding the public network address to the intranet host when the NAT device has multiple public Internet Protocol (IP, Internet Protocol) addresses (hereinafter referred to as public network addresses). There are fewer types of NAT devices.

所述NAPT是常用NAT类型,所述NAPT类型的NAT设备可以将内部地址映射到外部网络中的一个单独IP地址上,同时在该地址上加上一个由NAT设备选定的端口号。根据映射方式不同,NAPT可以分为对称性NAT和圆锥型NAT,其中,圆锥型NAT包括:完全圆锥型NAT、地址限制圆锥型NAT和端口限制圆锥型NAT。The NAPT is a common NAT type, and the NAT device of the NAPT type can map the internal address to a separate IP address in the external network, and at the same time add a port number selected by the NAT device to the address. According to different mapping methods, NAPT can be divided into symmetrical NAT and cone NAT, wherein cone NAT includes: complete cone NAT, address restricted cone NAT, and port restricted cone NAT.

具体来说,NAPT为公网中最常用NAT种类,分为以下四种:Specifically, NAPT is the most commonly used type of NAT in the public network, and is divided into the following four types:

1、对称型NAT(Symmetric NAT)1. Symmetric NAT

所述对称型NAT,将从同一内网地址和端口到相同目的地址和端口的所有请求,都映射到同一个公网地址和端口。如果同一个内网主机,用相同的内网地址和端口向另外一个目的地址发送报文,则会用不同的映射。与端口限制型NAT不同,端口限制型NAT是所有请求映射到相同的公网IP地址和端口,而对称型NAT是不同的请求有不同的映射。In the symmetric NAT, all requests from the same intranet address and port to the same destination address and port are mapped to the same public network address and port. If the same intranet host uses the same intranet address and port to send packets to another destination address, different mappings will be used. Different from port-restricted NAT, port-restricted NAT maps all requests to the same public IP address and port, while symmetric NAT has different mappings for different requests.

2、完全圆锥型NAT(Full Cone NAT)2. Full Cone NAT

所述完全圆锥型NAT,将从一个内部IP地址和端口来的所有请求,都映射到相同的外部IP地址和端口。并且,任何外部主机通过向映射的外部地址发送报文,都可以实现和内部主机进行通信。这是一种比较宽松的策略,只要建立了内部网络的IP地址和端口与公网IP地址和端口的映射关系,所有的Internet上的主机都可以访问该NAT设备之后的主机。The full cone NAT maps all requests from one internal IP address and port to the same external IP address and port. Moreover, any external host can communicate with the internal host by sending a message to the mapped external address. This is a relatively loose policy. As long as the mapping relationship between the IP address and port of the internal network and the IP address and port of the public network is established, all hosts on the Internet can access the host behind the NAT device.

3、地址限制圆锥型NAT(Address Restricted Cone NAT)3. Address Restricted Cone NAT

所述地址限制圆锥型NAT也是将从相同的内部IP地址和端口来的所有请求映射到相同的公网IP地址和端口。但是与完全圆锥型NAT不同,当且仅当内部主机之前已经向公网主机地址发送过报文,此时公网主机地址才能向内网主机发送报文。The address-restricted cone NAT also maps all requests from the same internal IP address and port to the same public IP address and port. However, unlike complete cone NAT, the public network host address can send packets to the internal network host only if and only if the internal host has previously sent packets to the public network host address.

4、端口限制圆锥型NAT(Port Restricted Cone NAT)4. Port Restricted Cone NAT

所述端口限制圆锥型NAT,类似于地址限制圆锥型NAT,但是更严格。所述端口限制圆锥型NAT增加了端口号的限制,仅当内网主机之前已经向公网主机地址和端口号发送了报文,公网主机地址和端口号才能和此内网主机通信。The port-restricted cone NAT is similar to the address-restricted cone NAT, but more restrictive. The port limit cone NAT increases the port number limit. Only when the internal network host has previously sent a message to the public network host address and port number, the public network host address and port number can communicate with the internal network host.

以下针对IPSec隧道的工作模式进行说明,包括两种工作模式:The following describes the working modes of the IPSec tunnel, including two working modes:

1、传输(transport)模式:只是传输层数据被用来计算AH或ESP头,AH或ESP头以及ESP加密的用户数据被放置在原IP包头后面。通常,传输模式应用在两台主机之间的通讯,或一台主机和一个网关之间的通讯。1. Transport mode: Only the transport layer data is used to calculate the AH or ESP header, and the AH or ESP header and the ESP-encrypted user data are placed behind the original IP header. Typically, the transport mode is used for communication between two hosts, or between a host and a gateway.

2、隧道(tunnel)模式:用户的整个IP数据包被用来计算AH或ESP头,AH或ESP头以及ESP加密的用户数据被封装在一个新的IP数据包中。通常,隧道模式应用在两个网关之间的通讯(本文涉及采用的模式)。2. Tunnel mode: The entire IP packet of the user is used to calculate the AH or ESP header, and the AH or ESP header and the ESP-encrypted user data are encapsulated in a new IP packet. Typically, tunnel mode is used for communication between two gateways (the mode used in this article).

ESP的常规隧道模式,由于NAT改动外部的IP而不改动被加密的原始IP,使得只有这种情况下才能与NAT共存,但只能以1对1的形式共存。In the conventional tunnel mode of ESP, since NAT changes the external IP without changing the encrypted original IP, it is only in this case that it can coexist with NAT, but it can only coexist in a 1-to-1 form.

NAT-T通过将ESP协议包封装到UDP包中(在原ESP协议的IP包头外添加新的IP头和UDP头),使得NAT对待它就像对待一个普通的UDP包一样,从而支持ESP的传输模式以1对多的形式与NAT共存。最终数据转发报文格式如图5所示。NAT-T supports the transmission of ESP by encapsulating ESP protocol packets into UDP packets (adding new IP headers and UDP headers to the IP header of the original ESP protocol), so that NAT treats it like a normal UDP packet. Modes coexist with NAT in a 1-to-many fashion. The format of the final data forwarding message is shown in Figure 5.

图6为本发明实施例提供的再一种NAT穿越方法的流程示意图;如图6所示,为实现IPSEC隧道两端穿越NAT,本发明实施例提供的NAT穿越方法,包括:探测NAT设备的类型;确定NAT设备的类型后,根据NAT设备的类型,配置CPE的IPSEC隧道和相关地址信息。FIG. 6 is a schematic flowchart of still another NAT traversal method provided by an embodiment of the present invention; as shown in FIG. 6 , in order to realize NAT traversal at both ends of an IPSEC tunnel, the NAT traversal method provided by an embodiment of the present invention includes: detecting a NAT device Type: After determining the type of the NAT device, configure the IPSEC tunnel and related address information of the CPE according to the type of the NAT device.

所述探测NAT设备的类型,包括:与其他协议(指与NAT探测server交互所需的涉及到的协议,如IP协议等)组合,客户侧网关CPEA和客户侧网关CPEB分别通过用于NAT探测的server(相当于图3、图4所示方法中的服务器,可采用公网免费server或者由控制器兼任)进行报文交互,探测CPEA和CPEB分别需要穿越的NAT设备的类型,即CPEA连接的NAT设备的类型、CPEB连接的NAT设备的类型。The type of the detection NAT device includes: in combination with other protocols (referring to the protocols involved in interacting with the NAT detection server, such as IP protocols, etc.), the client-side gateway CPEA and the client-side gateway CPEB are respectively used for NAT detection. The server (equivalent to the server in the method shown in Figure 3 and Figure 4, can use the public network free server or the controller) to exchange packets, and detect the type of NAT device that CPEA and CPEB need to traverse respectively, that is, CPEA connection Type of NAT device, type of NAT device connected to CPEB.

所述配置IPSEC隧道和相关地址信息,包括:Described configuring IPSEC tunnel and related address information, including:

配置IPSEC采用隧道模式;Configure IPSEC to use tunnel mode;

配置隧道地址信息;针对各CPE来说,所述隧道地址信息包括:本端私网地址,对端NAT后的公网地址。Configure the tunnel address information; for each CPE, the tunnel address information includes: the private network address of the local end and the public network address after the NAT of the opposite end.

以下对采用不同类型的NAT设备,对上述本发明实施例的方法进行说明。The following describes the methods of the above embodiments of the present invention using different types of NAT devices.

实施例一、经过与NAT探测server进行报文交互后,确定CPEA连接的NAT设备的类型为基本NAT,CPEB连接的NAT设备的类型为基本NAT。Embodiment 1: After the packet exchange with the NAT detection server, it is determined that the type of the NAT device connected to CPEA is basic NAT, and the type of the NAT device connected to CPEB is basic NAT.

所述NAT穿越方法,包括:The NAT traversal method includes:

步骤111、所述NAT探测Server向所述CPEB发送第一报文,以告知所述NAT探测Server记录的相应于CPEA的经NAT后的公网地址信息(包括公网地址和端口号CCC,转换前的端口号为IKE端口号4500);Step 111, the NAT detection Server sends a first message to the CPEB to inform the NAT detection Server records corresponding to the NATed public network address information (including the public network address and port number CCC, converted to CPEA) after the NAT. The previous port number is IKE port number 4500);

步骤112、所述CPEA配置IPSEC采用“隧道模式”封装、并开启NAT-T模式,配置并发送第二报文;所述第二报文的源地址信息包括本端私网地址和IKE端口号4500,目的地址为任意地址;这里,配置目的地址为任意地址的报文用于在CPEA连接的NAT设备打洞;Step 112: The CPEA configures IPSEC to use "tunnel mode" encapsulation and enables NAT-T mode, and configures and sends a second packet; the source address information of the second packet includes the local private network address and the IKE port number 4500, the destination address is any address; here, configure the packet with the destination address as any address to punch holes in the NAT device connected to CPEA;

步骤113、所述CPEB配置IPSEC采用“隧道模式”封装、并开启NAT-T模式,配置第三报文,所述第三报文的源地址信息包括本端私网地址和端口号AAA,目的地址为相应于CPEA的经NAT后的公网地址和端口号CCC(NAT之前的端口号为上述IKE端口号4500);所述CPEB向CPEA发送所述第三报文,以使CPEA接收到所述第三报文后,基于第三报文获得相应于CPEB的经NAT后的公网地址和端口。Step 113: The CPEB configures IPSEC to use "tunnel mode" encapsulation, enables NAT-T mode, and configures a third packet, where the source address information of the third packet includes the local private network address and port number AAA, and the destination The address is the NATed public network address and port number CCC corresponding to CPEA (the port number before NAT is the above-mentioned IKE port number 4500); the CPEB sends the third message to CPEA, so that CPEA receives all After the third message is described, the NATed public network address and port corresponding to the CPEB are obtained based on the third message.

步骤114、经过上述配置,CPEA和CPEB间建立IPSEC隧道,CPEA和CPEB间经IPSEC隧道进行常规报文转发。Step 114: After the above configuration, an IPSEC tunnel is established between CPEA and CPEB, and regular packets are forwarded between CPEA and CPEB through the IPSEC tunnel.

实施例二、经过与NAT探测server进行报文交互后,确定CPEA连接的NAT设备的类型为完全圆锥型NAT,CPEB连接的NAT设备的类型为完全圆锥型NAT。所述NAT穿越方法,包括:Embodiment 2: After exchanging packets with the NAT detection server, it is determined that the type of the NAT device connected to CPEA is a complete cone NAT, and the type of the NAT device connected to CPEB is a complete cone NAT. The NAT traversal method includes:

步骤211、NAT探测Server向CPEA发送第一报文,用以告知所述NAT探测Server记录的相应于CPEB的经NAT后的公网地址信息,具体包括:公网地址和端口号BBB(NAT转换前端口号为AAA)。Step 211, the NAT detection server sends a first message to the CPEA, in order to inform the NAT detection server records corresponding to the CPEB's NATed public network address information, specifically including: public network address and port number BBB (NAT translation). The former port number is AAA).

步骤212、NAT探测Server向CPEB发包,用以告知所述NAT探测Server记录的相应于CPEA的经NAT后的公网地址信息,具体包括:公网地址和端口号CCC(NAT转换前端口号为IKE端口号4500);Step 212, the NAT detection Server sends a packet to the CPEB, in order to inform the public network address information after the NAT corresponding to the CPEA recorded by the NAT detection Server, specifically including: the public network address and the port number CCC (the port number before the NAT conversion is IKE) port number 4500);

步骤213、CPEA配置IPSEC采用“隧道模式”封装、并开启NAT-T模式,源地址为本端私网地址和IKE端口4500,目的地址为相应于CPEB的经NAT后的公网地址和端口BBB,基于上述配置发送第二报文,所述第二报文用于在CPEA连接的NAT设备打洞;Step 213: The CPEA configures IPSEC to use "tunnel mode" encapsulation and enables NAT-T mode. The source address is the private network address of the end and IKE port 4500, and the destination address is the NATed public network address and port BBB corresponding to CPEB. , send a second packet based on the above configuration, and the second packet is used to punch holes in the NAT device connected to the CPEA;

图7为本发明实施例提供的一种第二报文的结构示意图;如图7所示,所述第二报文的源地址为本端私网地址和IKE端口4500,目的地址为相应于CPEB的经NAT后的公网地址和端口BBB(NAT前端口号为AAA)。FIG. 7 is a schematic structural diagram of a second packet provided by an embodiment of the present invention; as shown in FIG. 7 , the source address of the second packet is the private network address of the end and the IKE port 4500, and the destination address is corresponding to The NATed public network address and port BBB of CPEB (the port number before NAT is AAA).

步骤214、CPEB配置IPSEC采用“隧道模式”封装、并开启NAT-T模式,源地址为本端私网地址和端口号AAA,目的地址为相应于CPEA的经NAT后的公网地址和端口CCC(NAT前端口号为IKE端口号4500),基于上述配置发送第三报文,所述第三报文用于在CPEB连接的NAT设备打洞;Step 214, CPEB configures IPSEC to use "tunnel mode" encapsulation and enables NAT-T mode, the source address is the private network address and port number AAA of the end, and the destination address is the NATed public network address and port CCC corresponding to CPEA (The port number before the NAT is the IKE port number 4500), and based on the above configuration, a third packet is sent, and the third packet is used to punch holes in the NAT device connected to the CPEB;

图8为本发明实施例提供的一种第三报文的结构示意图;如图8所示,第三报文的源地址为本端私网地址和端口号AAA(NAT转换后端口号为BBB),目的地址的端口号为端口CCC(NAT前端口号为IKE端口号4500)。8 is a schematic structural diagram of a third packet provided by an embodiment of the present invention; as shown in FIG. 8 , the source address of the third packet is the private network address of the end and the port number AAA (the port number after NAT translation is BBB ), the port number of the destination address is port CCC (the port number before NAT is IKE port number 4500).

步骤215、经过上述配置,CPEA和CPEB间建立IPSEC隧道,CPEA和CPEB间经IPSEC隧道进行常规报文转发。Step 215: After the above configuration, an IPSEC tunnel is established between CPEA and CPEB, and regular packets are forwarded between CPEA and CPEB through the IPSEC tunnel.

实施例三、经过与NAT探测server进行报文交互后,确定CPEA连接的NAT设备的类型为完全圆锥型NAT,CPEB连接的NAT设备的类型为地址限制圆锥型NAT。Embodiment 3: After the packet exchange with the NAT detection server, it is determined that the type of the NAT device connected to CPEA is a full cone NAT, and the type of the NAT device connected to CPEB is an address restricted cone NAT.

这里,地址限制圆锥型NAT,同源同端口IP报文NAT映射相同(即将从相同的内部IP地址和端口来的所有请求,映射到相同的公网IP地址和端口);但是与完全圆锥型NAT不同,当且仅当内部主机之前已经向公网主机地址发送过报文,此时公网主机才能向内网主机发送报文。Here, the address-limited cone NAT has the same NAT mapping for IP packets of the same origin and the same port (that is, all requests from the same internal IP address and port are mapped to the same public IP address and port); Unlike NAT, the public network host can send packets to the internal network host only if the internal host has previously sent packets to the public network host address.

针对CPEB连接的NAT设备为地址限制圆锥型NAT的场景,采用与上述实施例二相同的方法进行处理即可。For a scenario in which the NAT device connected to the CPEB is an address-restricted cone NAT, the same method as in the second embodiment above may be used for processing.

实施例四、经过与NAT探测server进行报文交互后,确定CPEA连接的NAT设备的类型为完全圆锥型NAT,CPEB连接的NAT设备的类型为端口限制圆锥型NAT。Embodiment 4: After the packet exchange with the NAT detection server, it is determined that the type of the NAT device connected to CPEA is a full cone NAT, and the type of the NAT device connected to CPEB is a port restricted cone NAT.

这里,端口限制圆锥型NAT,也是同源同端口IP报文NAT映射相同(即将从相同的内部IP地址和端口来的所有请求,映射到相同的公网IP地址和端口),但是,端口受限圆锥型NAT增加了端口号的限制,当且仅当内部主机之前已经向公网主机地址发送过报文,公网主机才能和此内网主机通信。Here, the port-restricted cone NAT is also the same as the NAT mapping of the same-source and same-port IP packets (that is, all requests from the same internal IP address and port are mapped to the same public IP address and port), but the port is limited by Cone-limited NAT increases the port number limit. The public network host can communicate with the internal network host only if the internal host has sent packets to the public network host address before.

针对CPEB连接的NAT设备为端口限制圆锥型NAT的场景,采用与上述实施例二相同的方法进行处理即可。For the scenario in which the NAT device connected to the CPEB is a port-restricted cone NAT, the same method as in the second embodiment above may be used for processing.

实施例五、经过与NAT探测server进行报文交互后,确定CPEA连接的NAT设备的类型为完全圆锥型NAT,CPEB连接的NAT设备的类型为对称型NAT。Embodiment 5: After exchanging packets with the NAT detection server, it is determined that the type of the NAT device connected by CPEA is a complete cone NAT, and the type of the NAT device connected by CPEB is a symmetric NAT.

这里,对称型NAT会将从相同的内部IP地址和端口来的所有请求,映射到相同的公网IP地址和端口。如果同一个内网主机,用相同的内网地址和端口向另外一个目的地址发送报文,则会用不同的映射。Here, symmetric NAT will map all requests from the same internal IP address and port to the same public IP address and port. If the same intranet host uses the same intranet address and port to send packets to another destination address, different mappings will be used.

而CPEA连接的NAT设备的类型为完全圆锥型NAT,是一种比较宽松的策略,只要建立了内部网络的IP地址和端口与公网IP地址和端口的映射关系(即在CPEA连接的NAT设备打洞成功后),所有的Internet上的主机都可以访问该NAT之后的主机(即CPEA);The type of NAT device connected by CPEA is complete cone NAT, which is a relatively loose strategy. As long as the mapping relationship between the IP address and port of the internal network and the IP address and port of the public network is established (that is, the NAT device connected to the CPEA) After the hole is punched successfully), all hosts on the Internet can access the host behind the NAT (ie CPEA);

即CPEB发送的目的地址始终是相应于CPEA的经NAT后的公网地址和端口号CCC。因此,针对CPEB连接的NAT设备为对称型NAT的场景,采用与上述实施例二相同的方法进行处理即可。That is, the destination address sent by CPEB is always the NATed public network address and port number CCC corresponding to CPEA. Therefore, for the scenario in which the NAT device connected to the CPEB is a symmetric NAT, the same method as in the second embodiment above may be used for processing.

以下针对探测NAT设备的类型做进一步说明。The following describes the types of detecting NAT devices.

以CPEA连接的NAT设备为例(CPEB连接的NAT设备的检测方法相同,因此此处仅以其中之一为例进行说明),所述NAT探测server接收CPEA发送的第一测试报文;所述第一测试报文包括CPEA的地址信息(IP地址和端口),所述NAT探测server确定接收到第一测试报文后执行以下步骤。Taking the NAT device connected by CPEA as an example (the detection method of the NAT device connected by CPEB is the same, so only one of them is used as an example for description), the NAT detection server receives the first test message sent by CPEA; the The first test packet includes the address information (IP address and port) of the CPEA, and the NAT detection server performs the following steps after determining that the first test packet is received.

第一步:检测CPE是否位于NAT后;Step 1: Check whether the CPE is behind NAT;

CPEA的客户端建立UDP套接字(socket),用建立的UDP socket向服务器的(IP-1,Port-1)发送数据包(即上述第一测试报文)要求服务器返回CPE的地址信息(IP和Port),客户端发送请求后立即开始接收数据包,可以设定socket Timeout(300ms),防止无限堵塞;重复这个过程若干次。如果每次都超时,无法接受到服务器的回应,则说明CPEA无法进行UDP通信,可能是防火墙或NAT设备阻止UDP通信。The client of CPEA establishes a UDP socket (socket), and uses the established UDP socket to send a data packet (that is, the above-mentioned first test packet) to the server (IP-1, Port-1), requesting the server to return the address information of the CPE ( IP and Port), the client starts to receive data packets immediately after sending the request, and the socket Timeout (300ms) can be set to prevent infinite blockage; repeat this process several times. If it times out every time and cannot receive a response from the server, it means that CPEA cannot carry out UDP communication, possibly because a firewall or NAT device blocks UDP communication.

当CPEA的客户端能够接收到服务器的回应时,需要把服务器返回的(IP,Port)和CPE socket的(LocalIP,LocalPort)比较,如果完全相同,则确定CPEA不在NAT设备后;如果不相同,则确定CPEA在NAT设备后,需进一步检测NAT设备的类型。When the client of CPEA can receive the response from the server, it needs to compare the (IP, Port) returned by the server with the (LocalIP, LocalPort) of the CPE socket. If they are identical, it is determined that the CPEA is not behind the NAT device; if not, Then, after determining that the CPEA is in the NAT device, it is necessary to further detect the type of the NAT device.

第二步:检测NAT是否是完全圆锥型NAT;Step 2: Check whether the NAT is a complete cone NAT;

CPEA的客户端建立UDP socket,用建立的UDP socket向服务器的(IP-1,Port-1)发送数据包要求服务器用另一对(IP-2,Port-2)响应客户端,服务器响应请求返回一个数据包,客户端发送请求后立即开始接收数据包,可以设定socket Timeout(300ms),防止无限堵塞,重复这个过程若干次。如果能够接受到服务器从(IP-2,Port-2)返回的应答UDP包,则说明NAT是一个完全圆锥型NAT;如果每次都超时,无法接受到服务器的回应,则说明CPEA连接的NAT设备不是一个完全圆锥型NAT,具体类型有待下一步检测,进入下一步骤。The client of CPEA establishes a UDP socket, and uses the established UDP socket to send data packets to the server's (IP-1, Port-1) requesting the server to respond to the client with another pair (IP-2, Port-2), and the server responds to the request A data packet is returned, and the client starts to receive the data packet immediately after sending the request. You can set the socket Timeout (300ms) to prevent infinite blockage, and repeat this process several times. If it can receive the response UDP packet returned by the server from (IP-2, Port-2), it means that the NAT is a complete cone NAT; if it times out every time and cannot receive the response from the server, it means that the NAT connected by CPEA The device is not a complete cone NAT, the specific type needs to be detected in the next step, and the next step is entered.

第三步:检测NAT设备是否为对称型NAT;Step 3: Check whether the NAT device is a symmetric NAT;

CPEA的客户端建立UDP socket,用建立的UDP socket向服务器的(IP-1,Port-1)发送数据包,要求服务器返回客户端的IP和Port,客户端发送请求后立即开始接收数据包,可以设定socket Timeout(300ms),防止无限堵塞;重复这个过程直到收到回应;The client of CPEA establishes a UDP socket, and uses the established UDP socket to send data packets to the server (IP-1, Port-1), and requires the server to return the IP and Port of the client. Set socket Timeout (300ms) to prevent infinite blockage; repeat this process until a response is received;

用同样的方法用另一个socket向服务器的(IP-2,Port-2)发送数据包要求服务器返回IP和Port。In the same way, use another socket to send data packets to the server's (IP-2, Port-2) and ask the server to return the IP and Port.

比较上面两个过程从服务器返回的(IP,Port),如果两个过程返回的(IP,Port)有一对不同则说明为对称型NAT,否则是限制圆锥型NAT,具体是否为端口限制圆锥型NAT进入下一步检测;Compare the (IP, Port) returned by the above two processes from the server. If there is a pair of different (IP, Port) returned by the two processes, it is a symmetric NAT, otherwise it is a restricted cone NAT, specifically whether it is a port restricted cone NAT enters the next step of detection;

第四步:检测NAT为地址限制圆锥型NAT或端口限制圆锥型NAT;Step 4: Detect that the NAT is an address-restricted cone NAT or a port-restricted cone NAT;

CPEA的客户端建立UDP socket,用建立的UDP socket向服务器的(IP-1,Port-1)发送数据包,要求服务器用IP-1和一个不同于Port-1的端口发送一个UDP数据包进行响应,客户端发送请求后立即开始接收数据包,设定socket Timeout(300ms),防止无限堵塞;重复这个过程若干次。如果每次都超时,无法接受到服务器的回应,则说明是一个端口限制圆锥型NAT,如果能够收到服务器的响应则说明是一个地址限制圆锥型NAT。The client of CPEA establishes a UDP socket, and uses the established UDP socket to send data packets to the server's (IP-1, Port-1), requiring the server to send a UDP data packet with IP-1 and a port different from Port-1. In response, the client starts receiving data packets immediately after sending the request, and sets the socket Timeout (300ms) to prevent infinite blockage; repeat this process several times. If it times out every time and cannot receive a response from the server, it means that it is a port-restricted cone NAT; if it can receive a response from the server, it means that it is an address-restricted cone NAT.

以上所述的CEPA的客户端发送的数据包,即可以为图3和图4中的第一测试报文,相应的,所述服务器发送的数据包即为反馈的第一结果报文。The data packet sent by the above-mentioned CEPA client can be the first test message in FIG. 3 and FIG. 4 , and correspondingly, the data packet sent by the server is the first result message fed back.

本发明实施例中的所述NAT穿越方法应用于的服务器,可以采用公网免费服务器或者由公网控制器兼任,即对公网免费服务器或者由公网控制器进行功能扩展,以实现上述方案即可。The server to which the NAT traversal method in the embodiment of the present invention is applied may be a public network free server or a public network controller concurrently, that is, the function of the public network free server or the public network controller is extended to realize the above solution. That's it.

需要说明的是,上述检测NAT设备的类型的方法仅仅是一种实施例,本发明实施例中还可以采用其他方式进行检测,检测后确定连接的NAT设备类型后,将结果发送给服务器,通过服务器发送给对端CPE。例如:CPEA通过与服务器进行交互确定连接的NAT设备的类型后,将结果发送给所述服务器,所述服务器可以将结果发送给CPEB;反之相同。It should be noted that the above-mentioned method for detecting the type of NAT device is only an embodiment, and other methods may also be used for detection in this embodiment of the present invention. After detection, the type of connected NAT device is determined, and the result is sent to the server. The server sends it to the peer CPE. For example, after the CPEA determines the type of the connected NAT device by interacting with the server, it sends the result to the server, and the server can send the result to the CPEB; and vice versa.

图9为本发明实施例提供的一种NAT穿越装置的结构示意图;如图9所示,所述NAT穿越装置,应用于第一CPE,所述装置包括:第一处理模块和第二处理模块;FIG. 9 is a schematic structural diagram of a NAT traversal device according to an embodiment of the present invention; as shown in FIG. 9 , the NAT traversal device is applied to the first CPE, and the device includes: a first processing module and a second processing module ;

所述第一处理模块,用于确定第一NAT设备的类型、第二NAT设备的类型和相应于第二CPE的经NAT后的公网地址信息;所述第一NAT设备连接所述第一CPE,所述第二NAT设备连接第二CPE;The first processing module is used to determine the type of the first NAT device, the type of the second NAT device and the NATed public network address information corresponding to the second CPE; the first NAT device is connected to the first CPE, the second NAT device is connected to the second CPE;

所述第二处理模块,用于基于所述第一NAT设备的类型、所述第二NAT设备的类型和所述相应于第二CPE的经NAT后的公网地址信息,配置IPSEC隧道和隧道地址信息。The second processing module is configured to configure IPSEC tunnels and tunnels based on the type of the first NAT device, the type of the second NAT device, and the NATed public network address information corresponding to the second CPE Address information.

具体地,所述第一处理模块,用于接收服务器发送的第二NAT设备的类型。Specifically, the first processing module is configured to receive the type of the second NAT device sent by the server.

具体地,所述第一处理模块,还用于向服务器发送第一测试报文;所述第一测试报文用于请求所述服务器发送第一结果报文;Specifically, the first processing module is further configured to send a first test message to the server; the first test message is used to request the server to send a first result message;

接收所述服务器发送的第一结果报文,基于所述第一结果报文确定自身连接的NAT设备的类型,将确定的自身连接的NAT设备的类型发送给所述服务器。Receive the first result message sent by the server, determine the type of the NAT device connected to itself based on the first result message, and send the determined type of the NAT device connected to itself to the server.

在一实施例中,在所述第一NAT设备的类型为完全圆锥型NAT,且所述第二NAT设备的类型为基本NAT的情况下;所述第一处理模块,具体用于接收第二CPE发送的报文;In one embodiment, when the type of the first NAT device is a complete cone NAT, and the type of the second NAT device is a basic NAT; the first processing module is specifically configured to receive the second NAT device. The message sent by the CPE;

基于接收的所述报文确定相应于第二CPE的经NAT后的公网地址信息。The NATed public network address information corresponding to the second CPE is determined based on the received message.

具体地,所述第一处理模块,还用于向服务器发送第二测试报文;所述第二测试报文用于所述服务器确定相应于第一CPE的经NAT后的公网地址信息。Specifically, the first processing module is further configured to send a second test packet to the server; the second test packet is used by the server to determine the NATed public network address information corresponding to the first CPE.

具体地,所述第一处理模块,还用于基于配置的IPSEC隧道,发送目标地址为任意地址的报文;所述目标地址为任意地址的报文用于在第一NAT设备打洞。Specifically, the first processing module is further configured to, based on the configured IPSEC tunnel, send a message with a destination address of any address; the message with an arbitrary address as a destination address is used to punch holes in the first NAT device.

具体地,所述第二处理模块,用于配置IPSEC隧道的封装方式为隧道模式,以及配置采用NAT-T模式;Specifically, the second processing module is used to configure the encapsulation mode of the IPSEC tunnel as tunnel mode, and the configuration adopts NAT-T mode;

基于所述第一CPE自身的私网地址信息配置所述隧道地址信息中的源地址;Configure the source address in the tunnel address information based on the private network address information of the first CPE itself;

基于所述相应于第二CPE的经NAT后的公网地址信息配置所述隧道地址信息中的目的地址。The destination address in the tunnel address information is configured based on the NATed public network address information corresponding to the second CPE.

在一实施例中,在所述第一NAT设备的类型为基本NAT,且所述第二NAT设备的类型为完全圆锥型NAT的情况下;所述第一处理模块,具体用于接收服务器发送的相应于第二CPE的经NAT后的公网地址信息。In one embodiment, when the type of the first NAT device is a basic NAT, and the type of the second NAT device is a complete cone NAT; the first processing module is specifically configured to receive the data sent by the server. corresponding to the NATed public network address information of the second CPE.

具体地,所述第一处理模块,还用于向第二CPE发送报文;发送的所述报文用于第二CPE确定相应于第一CPE的经NAT后的公网地址信息。Specifically, the first processing module is further configured to send a message to the second CPE; the sent message is used by the second CPE to determine the NATed public network address information corresponding to the first CPE.

所述第二处理模块,用于配置IPSEC隧道的封装方式为隧道模式,以及配置采用NAT-T模式;The second processing module is used for configuring the encapsulation mode of the IPSEC tunnel to be a tunnel mode, and the configuration adopts a NAT-T mode;

基于所述第一CPE自身的私网地址信息配置所述隧道地址信息中的源地址;Configure the source address in the tunnel address information based on the private network address information of the first CPE itself;

基于所述相应于第二CPE的经NAT后的公网地址信息配置所述隧道地址信息中的目的地址。The destination address in the tunnel address information is configured based on the NATed public network address information corresponding to the second CPE.

在一实施例中,在所述第一NAT设备的类型为完全圆锥型NAT,且所述第二NAT设备的类型为NAPT的情况下,或者,在所述第一NAT设备的类型为NAPT,且所述第二NAT设备的类型为完全圆锥型NAT的情况下;所述第一处理模块,具体用于接收服务器发送的相应于第二CPE的经NAT后的公网地址信息。In one embodiment, when the type of the first NAT device is a complete cone NAT, and the type of the second NAT device is NAPT, or, when the type of the first NAT device is NAPT, And when the type of the second NAT device is a complete cone NAT; the first processing module is specifically configured to receive the NATed public network address information corresponding to the second CPE sent by the server.

所述第二处理模块,用于配置IPSEC隧道的封装方式为隧道模式,以及配置采用NAT-T模式;The second processing module is used for configuring the encapsulation mode of the IPSEC tunnel to be a tunnel mode, and the configuration adopts a NAT-T mode;

基于所述第一CPE自身的私网地址信息配置所述隧道地址信息中的源地址;Configure the source address in the tunnel address information based on the private network address information of the first CPE itself;

基于所述相应于第二CPE的经NAT后的公网地址信息配置所述隧道地址信息中的目的地址。The destination address in the tunnel address information is configured based on the NATed public network address information corresponding to the second CPE.

所述第一处理模块,还用于基于配置的IPSEC隧道和隧道地址信息发送报文,发送的报文用于在第一NAT设备打洞。The first processing module is further configured to send a message based on the configured IPSEC tunnel and tunnel address information, and the sent message is used for punching a hole in the first NAT device.

具体地,所述NAPT,包括以下至少之一:对称型NAT、完全圆锥型NAT、地址限制圆锥型NAT、端口限制圆锥型NAT。Specifically, the NAPT includes at least one of the following: symmetric NAT, full cone NAT, address restricted cone NAT, and port restricted cone NAT.

所述隧道地址信息,包括以下至少之一:The tunnel address information includes at least one of the following:

第一CPE自身的私网地址信息、相应于第二CPE的经NAT后的公网地址信息。The private network address information of the first CPE itself corresponds to the NATed public network address information of the second CPE.

所述公网地址信息,包括:公网地址和端口号。The public network address information includes: public network address and port number.

所述报文包括:IP头、UDP头、认证部分、ESP认证;The message includes: IP header, UDP header, authentication part, and ESP authentication;

其中,所述认证部分包括:ESP头和加密部分;所述加密部分包括:原始IP头、TCP、DATA、ESP尾。Wherein, the authentication part includes: ESP header and encryption part; and the encryption part includes: original IP header, TCP, DATA, and ESP tail.

图10为本发明实施例提供的另一种NAT穿越装置的结构示意图;如图10所示,所述NAT穿越装置应用于服务器,所述装置包括:第三处理模块、第四处理模块和第五处理模块;其中,FIG. 10 is a schematic structural diagram of another NAT traversal device provided by an embodiment of the present invention; as shown in FIG. 10 , the NAT traversal device is applied to a server, and the device includes: a third processing module, a fourth processing module, and a third processing module. Five processing modules; of which,

所述第三处理模块,用于确定第一NAT设备的类型和第二NAT设备的类型;所述第一NAT设备连接第一CPE,所述第二NAT设备连接第二CPE;The third processing module is used to determine the type of the first NAT device and the type of the second NAT device; the first NAT device is connected to the first CPE, and the second NAT device is connected to the second CPE;

所述第四处理模块,用于向所述第一CPE发送所述第二NAT设备的类型;向所述第二CPE发送所述第一NAT设备的类型;The fourth processing module is configured to send the type of the second NAT device to the first CPE; send the type of the first NAT device to the second CPE;

所述第五处理模块,用于在所述第一NAT设备的类型和所述第二NAT的设备满足预设条件的情况下,确定相应于第一CPE的经NAT后的公网地址信息,向第二CPE发送所述相应于第一CPE的经NAT后的公网地址信息;和/或,确定相应于第二CPE的经NAT后的公网地址信息,向第一CPE发送所述相应于第二CPE的经NAT后的公网地址信息;The fifth processing module is configured to determine the NATed public network address information corresponding to the first CPE when the type of the first NAT device and the device of the second NAT meet a preset condition, Sending the NATed public network address information corresponding to the first CPE to the second CPE; and/or, determining the NATed public network address information corresponding to the second CPE, and sending the corresponding public network address information to the first CPE NATed public network address information of the second CPE;

其中,所述公网地址信息用于配置IPSEC隧道和隧道地址信息。The public network address information is used to configure IPSEC tunnels and tunnel address information.

具体地,所述所述第五处理模块,具体用于在所述第一NAT设备的类型为完全圆锥型NAT,且所述第二NAT设备的类型为基本NAT的情况下,确定相应于第一CPE的经NAT后的公网地址信息,向第二CPE发送所述相应于第一CPE的经NAT后的公网地址信息。Specifically, the fifth processing module is specifically configured to, in the case that the type of the first NAT device is a full cone NAT, and the type of the second NAT device is a basic NAT, determine whether the The NATed public network address information of a CPE, and the NATed public network address information corresponding to the first CPE is sent to the second CPE.

具体地,所述所述第五处理模块,具体用于在所述第一NAT设备的类型为基本NAT,且所述第二NAT设备的类型为完全圆锥型NAT的情况下,确定相应于第二CPE的经NAT后的公网地址信息,向第一CPE发送所述相应于第二CPE的经NAT后的公网地址信息。Specifically, the fifth processing module is specifically configured to, in the case that the type of the first NAT device is a basic NAT, and the type of the second NAT device is a full cone NAT, determine whether the The NATed public network address information of the second CPE, and the NATed public network address information corresponding to the second CPE is sent to the first CPE.

具体地,所述所述第五处理模块,具体用于在所述第一NAT设备的类型为完全圆锥型NAT且所述第二NAT设备的类型为NAPT的情况下,或者,在所述第一NAT设备的类型为NAPT且所述第二NAT设备的类型为完全圆锥型NAT的情况下,确定相应于第一CPE的经NAT后的公网地址信息,向第二CPE发送所述相应于第一CPE的经NAT后的公网地址信息;以及,确定相应于第二CPE的经NAT后的公网地址信息,向第一CPE发送所述相应于第二CPE的经NAT后的公网地址信息。Specifically, the fifth processing module is specifically configured to be used in the case that the type of the first NAT device is a full cone NAT and the type of the second NAT device is NAPT, or, in the case that the type of the first NAT device is NAPT When the type of a NAT device is NAPT and the type of the second NAT device is a complete cone NAT, determine the NATed public network address information corresponding to the first CPE, and send the corresponding information to the second CPE. NATed public network address information of the first CPE; and determining the NATed public network address information corresponding to the second CPE, and sending the NATed public network corresponding to the second CPE to the first CPE Address information.

具体地,所述NAPT,包括以下至少之一:Specifically, the NAPT includes at least one of the following:

对称型NAT、完全圆锥型NAT、地址限制圆锥型NAT、端口限制圆锥型NAT。Symmetric NAT, Full Cone NAT, Address Restriction Cone NAT, Port Restriction Cone NAT.

具体地,所述公网地址信息,包括:公网地址和端口号。Specifically, the public network address information includes: a public network address and a port number.

具体地,所述第三处理模块,用于接收第一CPE发送的第一测试报文,基于所述第一测试报文发送第一结果报文;所述第一结果报文用于所述第一CPE确定自身连接的第一NAT设备的类型;接收所述第一CPE发送的自身连接的第一NAT设备的类型;Specifically, the third processing module is configured to receive a first test packet sent by the first CPE, and send a first result packet based on the first test packet; the first result packet is used for the The first CPE determines the type of the first NAT device connected to itself; receives the type of the first NAT device connected to itself sent by the first CPE;

接收第二CPE发送的第三测试报文,基于所述第三测试报文发送第二结果报文;所述第二结果报文用于所述第二CPE确定自身连接的第二NAT设备的类型;接收所述第二CPE发送的自身连接的第二NAT设备的类型。Receive a third test packet sent by the second CPE, and send a second result packet based on the third test packet; the second result packet is used by the second CPE to determine the status of the second NAT device connected to itself. Type: the type of the second NAT device that receives the self-connection sent by the second CPE.

具体地,所述第三处理模块,还用于接收第一CPE发送的第二测试报文;基于所述第一CPE发送的第二测试报文确定相应于第一CPE的经NAT后的公网地址信息;Specifically, the third processing module is further configured to receive a second test packet sent by the first CPE; and determine, based on the second test packet sent by the first CPE, a NATed public address corresponding to the first CPE web address information;

所述第三处理模块,还用于接收第二CPE发送的第四测试报文;基于所述第二CPE发送的第四测试报文确定相应于第二CPE的经NAT后的公网地址信息。The third processing module is further configured to receive a fourth test packet sent by the second CPE; and determine the NATed public network address information corresponding to the second CPE based on the fourth test packet sent by the second CPE .

图11为本发明实施例提供的一种电子设备的结构示意图;如图11所示,所述装置110包括:处理器1101和用于存储能够在所述处理器上运行的计算机程序的存储器1102;其中,所述电子设备应用于第一CPE时,所述处理器1101用于运行所述计算机程序时,执行:FIG. 11 is a schematic structural diagram of an electronic device according to an embodiment of the present invention; as shown in FIG. 11 , the apparatus 110 includes: a processor 1101 and a memory 1102 for storing a computer program that can run on the processor ; wherein, when the electronic device is applied to the first CPE, when the processor 1101 is configured to run the computer program, execute:

在一实施例中,所述处理器1101还用于运行所述计算机程序时,执行:确定第一NAT设备的类型、第二NAT设备的类型和相应于第二CPE的经NAT后的公网地址信息;所述第一NAT设备连接所述第一CPE,所述第二NAT设备连接第二CPE;In one embodiment, the processor 1101 is further configured to, when running the computer program, execute: determining the type of the first NAT device, the type of the second NAT device, and the NATed public network corresponding to the second CPE address information; the first NAT device is connected to the first CPE, and the second NAT device is connected to the second CPE;

基于所述第一NAT设备的类型、所述第二NAT设备的类型和所述相应于第二CPE的经NAT后的公网地址信息,配置IPSEC隧道和隧道地址信息。Based on the type of the first NAT device, the type of the second NAT device, and the NATed public network address information corresponding to the second CPE, configure an IPSEC tunnel and tunnel address information.

具体来说,所述电子设备执行如图3所示的方法,与图3所示的NAT穿越方法实施例属于同一构思,其具体实现过程详见方法实施例,这里不再赘述。Specifically, the electronic device performs the method shown in FIG. 3 , which belongs to the same concept as the NAT traversal method embodiment shown in FIG. 3 , and the specific implementation process is detailed in the method embodiment, which will not be repeated here.

作为另一种实施例,所述电子设备应用于服务器时,所述处理器1101用于运行所述计算机程序时,执行:确定第一NAT设备的类型和第二NAT设备的类型;所述第一NAT设备连接第一CPE,所述第二NAT设备连接第二CPE;As another embodiment, when the electronic device is applied to a server, when the processor 1101 is configured to run the computer program, execute: determine the type of the first NAT device and the type of the second NAT device; A NAT device is connected to the first CPE, and the second NAT device is connected to the second CPE;

向所述第一CPE发送所述第二NAT设备的类型;向所述第二CPE发送所述第一NAT设备的类型;sending the type of the second NAT device to the first CPE; sending the type of the first NAT device to the second CPE;

在所述第一NAT设备的类型和所述第二NAT的设备满足预设条件的情况下,确定相应于第一CPE的经NAT后的公网地址信息,向第二CPE发送所述相应于第一CPE的经NAT后的公网地址信息;和/或,确定相应于第二CPE的经NAT后的公网地址信息,向第一CPE发送所述相应于第二CPE的经NAT后的公网地址信息;In the case that the type of the first NAT device and the device of the second NAT meet the preset conditions, determine the NATed public network address information corresponding to the first CPE, and send the information corresponding to the first CPE to the second CPE The NATed public network address information of the first CPE; and/or, determining the NATed public network address information corresponding to the second CPE, and sending the NATed public network address information corresponding to the second CPE to the first CPE. public network address information;

其中,所述公网地址信息用于配置IPSEC隧道和隧道地址信息。The public network address information is used to configure IPSEC tunnels and tunnel address information.

具体来说,所述电子设备执行如图4所示的方法,与图4所示的NAT穿越方法实施例属于同一构思,其具体实现过程详见方法实施例,这里不再赘述。Specifically, the electronic device performs the method shown in FIG. 4, which belongs to the same concept as the NAT traversal method embodiment shown in FIG.

实际应用时,所述装置110还可以包括:至少一个网络接口1103。电子设备110中的各个组件通过总线系统1104耦合在一起。可理解,总线系统1104用于实现这些组件之间的连接通信。总线系统1104除包括数据总线之外,还包括电源总线、控制总线和状态信号总线。但是为了清楚说明起见,在图11中将各种总线都标为总线系统1104。其中,所述处理器1101的个数可以为至少一个。网络接口1103用于电子设备110与其他设备之间有线或无线方式的通信。In practical application, the apparatus 110 may further include: at least one network interface 1103 . The various components in electronic device 110 are coupled together by bus system 1104 . It will be appreciated that the bus system 1104 is used to implement the connection communication between these components. In addition to the data bus, the bus system 1104 also includes a power bus, a control bus, and a status signal bus. However, for clarity of illustration, the various buses are labeled as bus system 1104 in FIG. 11 . The number of the processors 1101 may be at least one. The network interface 1103 is used for wired or wireless communication between the electronic device 110 and other devices.

本发明实施例中的存储器1102用于存储各种类型的数据以支持电子设备110的操作。The memory 1102 in the embodiment of the present invention is used to store various types of data to support the operation of the electronic device 110 .

上述本发明实施例揭示的方法可以应用于处理器1101中,或者由处理器1101实现。处理器1101可能是一种集成电路芯片,具有信号的处理能力。在实现过程中,上述方法的各步骤可以通过处理器1101中的硬件的集成逻辑电路或者软件形式的指令完成。上述的处理器1101可以是通用处理器、数字信号处理器(DSP,DiGital Signal Processor),或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。处理器1101可以实现或者执行本发明实施例中的公开的各方法、步骤及逻辑框图。通用处理器可以是微处理器或者任何常规的处理器等。结合本发明实施例所公开的方法的步骤,可以直接体现为硬件译码处理器执行完成,或者用译码处理器中的硬件及软件模块组合执行完成。软件模块可以位于存储介质中,该存储介质位于存储器1102,处理器1101读取存储器1102中的信息,结合其硬件完成前述方法的步骤。The methods disclosed in the above embodiments of the present invention may be applied to the processor 1101 or implemented by the processor 1101 . The processor 1101 may be an integrated circuit chip with signal processing capability. In the implementation process, each step of the above-mentioned method may be completed by an integrated logic circuit of hardware in the processor 1101 or an instruction in the form of software. The above-mentioned processor 1101 may be a general-purpose processor, a digital signal processor (DSP, DiGital Signal Processor), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, and the like. The processor 1101 may implement or execute the methods, steps, and logical block diagrams disclosed in the embodiments of the present invention. A general purpose processor may be a microprocessor or any conventional processor or the like. The steps of the method disclosed in combination with the embodiments of the present invention can be directly embodied as being executed by a hardware decoding processor, or executed by a combination of hardware and software modules in the decoding processor. The software module may be located in a storage medium, and the storage medium is located in the memory 1102, and the processor 1101 reads the information in the memory 1102, and completes the steps of the foregoing method in combination with its hardware.

在示例性实施例中,电子设备110可以被一个或多个应用专用集成电路(ASIC,Application Specific Integrated Circuit)、DSP、可编程逻辑器件(PLD,ProgrammableLogic Device)、复杂可编程逻辑器件(CPLD,Complex Programmable Logic Device)、现场可编程门阵列(FPGA,Field-Programmable Gate Array)、通用处理器、控制器、微控制器(MCU,Micro Controller Unit)、微处理器(Microprocessor)、或其他电子元件实现,用于执行前述方法。In an exemplary embodiment, the electronic device 110 may be implemented by one or more Application Specific Integrated Circuit (ASIC, Application Specific Integrated Circuit), DSP, Programmable Logic Device (PLD, Programmable Logic Device), Complex Programmable Logic Device (CPLD, Complex Programmable Logic Device), Field-Programmable Gate Array (FPGA, Field-Programmable Gate Array), general-purpose processor, controller, microcontroller (MCU, Micro Controller Unit), microprocessor (Microprocessor), or other electronic components implementation for performing the aforementioned method.

本发明实施例还提供了一种计算机可读存储介质,其上存储有计算机程序,所述计算机程序被处理器运行时,执行:确定第一NAT设备的类型、第二NAT设备的类型和相应于第二CPE的经NAT后的公网地址信息;所述第一NAT设备连接所述第一CPE,所述第二NAT设备连接第二CPE;Embodiments of the present invention also provide a computer-readable storage medium, on which a computer program is stored, and when the computer program is run by the processor, executes: determining the type of the first NAT device, the type of the second NAT device and corresponding The NATed public network address information of the second CPE; the first NAT device is connected to the first CPE, and the second NAT device is connected to the second CPE;

基于所述第一NAT设备的类型、所述第二NAT设备的类型和所述相应于第二CPE的经NAT后的公网地址信息,配置IPSEC隧道和隧道地址信息。具体来说,所述计算机程序被处理器运行时,执行如图3所示的方法,与图3所示的NAT穿越方法实施例属于同一构思,其具体实现过程详见方法实施例,这里不再赘述。Based on the type of the first NAT device, the type of the second NAT device, and the NATed public network address information corresponding to the second CPE, configure an IPSEC tunnel and tunnel address information. Specifically, when the computer program is run by the processor, the method shown in FIG. 3 is executed, which belongs to the same concept as the embodiment of the NAT traversal method shown in FIG. Repeat.

本发明实施例提供的一种计算机可读存储介质,其上存储有计算机程序,作为另一种实施方式,所述计算机程序被处理器运行时,执行:确定第一NAT设备的类型和第二NAT设备的类型;所述第一NAT设备连接第一CPE,所述第二NAT设备连接第二CPE;An embodiment of the present invention provides a computer-readable storage medium, on which a computer program is stored. As another implementation manner, when the computer program is run by a processor, execute: determine the type of the first NAT device and the second type of the second NAT device. The type of NAT device; the first NAT device is connected to the first CPE, and the second NAT device is connected to the second CPE;

向所述第一CPE发送所述第二NAT设备的类型;向所述第二CPE发送所述第一NAT设备的类型;sending the type of the second NAT device to the first CPE; sending the type of the first NAT device to the second CPE;

在所述第一NAT设备的类型和所述第二NAT的设备满足预设条件的情况下,确定相应于第一CPE的经NAT后的公网地址信息,向第二CPE发送所述相应于第一CPE的经NAT后的公网地址信息;和/或,确定相应于第二CPE的经NAT后的公网地址信息,向第一CPE发送所述相应于第二CPE的经NAT后的公网地址信息;In the case that the type of the first NAT device and the device of the second NAT meet the preset conditions, determine the NATed public network address information corresponding to the first CPE, and send the information corresponding to the first CPE to the second CPE The NATed public network address information of the first CPE; and/or, determining the NATed public network address information corresponding to the second CPE, and sending the NATed public network address information corresponding to the second CPE to the first CPE. public network address information;

其中,所述公网地址信息用于配置IPSEC隧道和隧道地址信息。The public network address information is used to configure IPSEC tunnels and tunnel address information.

具体来说,所述计算机程序被处理器运行时,可以执行如图4所示的方法,与图4所示的NAT穿越方法实施例属于同一构思,其具体实现过程详见方法实施例,这里不再赘述。Specifically, when the computer program is run by the processor, the method shown in FIG. 4 can be executed, which belongs to the same concept as the embodiment of the NAT traversal method shown in FIG. No longer.

在本申请所提供的几个实施例中,应该理解到,所揭露的装置和方法,可以通过其它的方式实现。以上所描述的设备实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,如:多个单元或组件可以结合,或可以集成到另一个系统,或一些特征可以忽略,或不执行。另外,所显示或讨论的各组成部分相互之间的耦合、或直接耦合、或通信连接可以是通过一些接口,设备或单元的间接耦合或通信连接,可以是电性的、机械的或其它形式的。In the several embodiments provided in this application, it should be understood that the disclosed apparatus and method may be implemented in other manners. The device embodiments described above are only illustrative. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components may be combined, or Can be integrated into another system, or some features can be ignored, or not implemented. In addition, the coupling, or direct coupling, or communication connection between the components shown or discussed may be through some interfaces, and the indirect coupling or communication connection of devices or units may be electrical, mechanical or other forms. of.

上述作为分离部件说明的单元可以是、或也可以不是物理上分开的,作为单元显示的部件可以是、或也可以不是物理单元,即可以位于一个地方,也可以分布到多个网络单元上;可以根据实际的需要选择其中的部分或全部单元来实现本实施例方案的目的。The unit described above as a separate component may or may not be physically separated, and the component displayed as a unit may or may not be a physical unit, that is, it may be located in one place or distributed to multiple network units; Some or all of the units may be selected according to actual needs to achieve the purpose of the solution in this embodiment.

另外,在本发明各实施例中的各功能单元可以全部集成在一个处理单元中,也可以是各单元分别单独作为一个单元,也可以两个或两个以上单元集成在一个单元中;上述集成的单元既可以采用硬件的形式实现,也可以采用硬件加软件功能单元的形式实现。In addition, each functional unit in each embodiment of the present invention may all be integrated into one processing unit, or each unit may be separately used as a unit, or two or more units may be integrated into one unit; the above-mentioned integration The unit can be implemented either in the form of hardware or in the form of hardware plus software functional units.

本领域普通技术人员可以理解:实现上述方法实施例的全部或部分步骤可以通过程序指令相关的硬件来完成,前述的程序可以存储于一计算机可读取存储介质中,该程序在执行时,执行包括上述方法实施例的步骤;而前述的存储介质包括:移动存储设备、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、磁碟或者光盘等各种可以存储程序代码的介质。Those of ordinary skill in the art can understand that all or part of the steps of implementing the above method embodiments may be completed by program instructions related to hardware, the aforementioned program may be stored in a computer-readable storage medium, and when the program is executed, execute Including the steps of the above-mentioned method embodiment; and the aforementioned storage medium includes: a mobile storage device, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk or an optical disk and other various A medium on which program code can be stored.

或者,本发明上述集成的单元如果以软件功能模块的形式实现并作为独立的产品销售或使用时,也可以存储在一个计算机可读取存储介质中。基于这样的理解,本发明实施例的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机、服务器、或者网络设备等)执行本发明各个实施例所述方法的全部或部分。而前述的存储介质包括:移动存储设备、ROM、RAM、磁碟或者光盘等各种可以存储程序代码的介质。Alternatively, if the above-mentioned integrated unit of the present invention is implemented in the form of a software function module and sold or used as an independent product, it may also be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the embodiments of the present invention may be embodied in the form of software products in essence or the parts that make contributions to the prior art. The computer software products are stored in a storage medium and include several instructions for A computer device (which may be a personal computer, a server, or a network device, etc.) is caused to execute all or part of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes: a removable storage device, a ROM, a RAM, a magnetic disk or an optical disk and other mediums that can store program codes.

以上所述,仅为本发明的具体实施方式,但本发明的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本发明揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本发明的保护范围之内。因此,本发明的保护范围应以所述权利要求的保护范围为准。The above are only specific embodiments of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention. should be included within the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.

Claims (29)

1. A Network Address Translation (NAT) traversal method is applied to a first Customer Premises Equipment (CPE), and is characterized by comprising the following steps:
determining the type of the first NAT equipment, the type of the second NAT equipment and public network address information corresponding to the second CPE after NAT; the first NAT equipment is connected with the first CPE, and the second NAT equipment is connected with the second CPE;
and configuring an internet security protocol (IPSEC) tunnel and tunnel address information based on the type of the first NAT equipment, the type of the second NAT equipment and the public network address information corresponding to the second CPE after NAT.
2. The method of claim 1, wherein the determining the type of the second NAT device comprises:
and receiving the type of the second NAT equipment sent by the server.
3. The method of claim 2, further comprising:
sending a first test message to a server; the first test message is used for requesting the server to send a first result message;
and receiving a first result message sent by the server, determining the type of the NAT equipment connected with the server based on the first result message, and sending the determined type of the NAT equipment connected with the server to the server.
4. The method of claim 1, wherein if the first NAT device is of a full cone type NAT and the second NAT device is of a basic type NAT; determining the NAT-enabled public network address information corresponding to the second CPE, comprising:
receiving a message sent by a second CPE;
and determining public network address information corresponding to the second CPE after NAT based on the received message.
5. The method of claim 4, further comprising:
sending a second test message to the server; and the second test message is used for the server to determine the public network address information corresponding to the first CPE after NAT.
6. The method of claim 4, further comprising:
based on the configured IPSEC tunnel, sending a message with a target address as an arbitrary address; and the message with the target address as any address is used for punching a hole in the first NAT equipment.
7. The method of claim 4, wherein the configuring IPSEC tunnels and tunnel address information comprises:
configuring an IPSEC tunnel in a tunnel mode and configuring an NAT-T mode;
configuring a source address in the tunnel address information based on the private network address information of the first CPE;
and configuring a destination address in the tunnel address information based on the NAT-passed public network address information corresponding to the second CPE.
8. A method according to any one of claims 1 to 3, characterized in that in the case where the type of the first NAT device is basic NAT and the type of the second NAT device is full cone NAT; determining the NAT-enabled public network address information corresponding to the second CPE, comprising:
and receiving the public network address information which is sent by the server and corresponds to the second CPE after NAT.
9. The method of claim 8, further comprising:
sending a message to a second CPE; the sent message is used for the second CPE to determine the public network address information which corresponds to the first CPE and is subject to NAT.
10. The method of claim 7 or 8, wherein the configuring IPSEC tunnels and tunnel address information comprises:
configuring an IPSEC tunnel in a tunnel mode and configuring an NAT-T mode;
configuring a source address in the tunnel address information based on the private network address information of the first CPE;
and configuring a destination address in the tunnel address information based on the NAT-passed public network address information corresponding to the second CPE.
11. The method according to any of claims 1 to 3, characterized in that, in case the type of the first NAT device is a full cone type NAT and the type of the second NAT device is a network address port translation NAPT, or in case the type of the first NAT device is NAPT and the type of the second NAT device is a full cone type NAT; determining the NAT-enabled public network address information corresponding to the second CPE, comprising:
and receiving the public network address information which is sent by the server and corresponds to the second CPE after NAT.
12. The method of claim 11, wherein the configuring IPSEC tunnel and tunnel address information comprises:
configuring an IPSEC tunnel in a tunnel mode and configuring an NAT-T mode;
configuring a source address in the tunnel address information based on the private network address information of the first CPE;
and configuring a destination address in the tunnel address information based on the NAT-passed public network address information corresponding to the second CPE.
13. The method of claim 12, further comprising:
and sending a message based on the configured IPSEC tunnel and the tunnel address information, wherein the sent message is used for punching a hole in the first NAT equipment.
14. The method of claim 11, wherein the NAPT comprises at least one of: symmetric NAT, perfect cone NAT, address restricted cone NAT, port restricted cone NAT.
15. The method of claim 1, wherein the tunnel address information comprises at least one of:
the private network address information of the first CPE is corresponding to the public network address information of the second CPE after NAT.
16. The method of claim 15, wherein the public network address information comprises: public network address and port number.
17. The method according to claim 4, 9 or 13, wherein the message comprises: an Internet Protocol (IP) header, a User Datagram Protocol (UDP) header, an authentication part and an encapsulated security load (ESP) authentication;
wherein the authentication section includes: an ESP header and an encryption section; the encryption part includes: original IP header, transmission control protocol TCP, DATA, ESP trailer.
18. A NAT traversal method is applied to a server, and is characterized by comprising the following steps:
determining the type of a first NAT device and the type of a second NAT device; the first NAT equipment is connected with a first CPE, and the second NAT equipment is connected with a second CPE;
sending the type of the second NAT device to the first CPE; sending the type of the first NAT device to the second CPE;
under the condition that the type of the first NAT equipment and the second NAT equipment meet preset conditions, determining public network address information corresponding to the first CPE after NAT, and sending the public network address information corresponding to the first CPE after NAT to the second CPE; and/or determining public network address information corresponding to the second CPE after NAT, and sending the public network address information corresponding to the second CPE after NAT to the first CPE;
the public network address information is used for configuring an IPSEC tunnel and tunnel address information.
19. The method of claim 18, wherein if the first NAT device is of a full cone NAT type and the second NAT device is of a basic NAT type, determining NAT-enabled public network address information corresponding to the first CPE, and sending the NAT-enabled public network address information corresponding to the first CPE to the second CPE.
20. The method of claim 18, wherein when the first NAT device is of a basic NAT type and the second NAT device is of a full cone NAT type, determining NAT-enabled public network address information corresponding to the second CPE, and sending the NAT-enabled public network address information corresponding to the second CPE to the first CPE.
21. The method according to claim 18, wherein in a case where the type of the first NAT device is full cone NAT and the type of the second NAT device is NAPT, or in a case where the type of the first NAT device is NAPT and the type of the second NAT device is full cone NAT, determining NAT-passed public network address information corresponding to the first CPE, and sending the NAT-passed public network address information corresponding to the first CPE to the second CPE; and determining the public network address information corresponding to the second CPE after the NAT, and sending the public network address information corresponding to the second CPE after the NAT to the first CPE.
22. The method of claim 21, wherein the NAPT comprises at least one of:
symmetric NAT, perfect cone NAT, address restricted cone NAT, port restricted cone NAT.
23. The method of claim 18, wherein the public network address information comprises: public network address and port number.
24. The method of claim 18, wherein determining the type of the first NAT device and the type of the second NAT device comprises:
receiving a first test message sent by a first CPE, and sending a first result message based on the first test message; the first result message is used for the first CPE to determine the type of a first NAT device connected with the first CPE; receiving the type of a first NAT device connected with the first CPE and sent by the first CPE;
receiving a third test message sent by a second CPE, and sending a second result message based on the third test message; the second result message is used for the second CPE to determine the type of a second NAT device connected with the second CPE; and receiving the type of the self-connected second NAT equipment sent by the second CPE.
25. The method of claim 18, wherein determining the NAT-enabled public network address information corresponding to the first CPE comprises:
receiving a second test message sent by the first CPE; determining public network address information corresponding to the first CPE after NAT based on a second test message sent by the first CPE;
the determining the public network address information corresponding to the second CPE after NAT includes:
receiving a fourth test message sent by the second CPE; and determining the public network address information corresponding to the second CPE after NAT based on the fourth test message sent by the second CPE.
26. An apparatus for NAT traversal, the apparatus being applied to a first CPE, the apparatus comprising: a first processing module and a second processing module;
the first processing module is used for determining the type of the first NAT equipment, the type of the second NAT equipment and public network address information corresponding to the second CPE after NAT; the first NAT equipment is connected with the first CPE, and the second NAT equipment is connected with the second CPE;
the second processing module is configured to configure an IPSEC tunnel and tunnel address information based on the type of the first NAT device, the type of the second NAT device, and the public network address information corresponding to the second CPE after NAT.
27. An apparatus for NAT traversal, the apparatus being applied to a server, the apparatus comprising: the device comprises a third processing module, a fourth processing module and a fifth processing module; wherein,
the third processing module is used for determining the type of the first NAT equipment and the type of the second NAT equipment; the first NAT equipment is connected with a first CPE, and the second NAT equipment is connected with a second CPE;
the fourth processing module is configured to send the type of the second NAT device to the first CPE; sending the type of the first NAT device to the second CPE;
the fifth processing module is configured to determine public network address information after NAT processing corresponding to the first CPE when the type of the first NAT device and the device of the second NAT device meet a preset condition, and send the public network address information after NAT processing corresponding to the first CPE to the second CPE; and/or determining public network address information corresponding to the second CPE after NAT, and sending the public network address information corresponding to the second CPE after NAT to the first CPE;
the public network address information is used for configuring an IPSEC tunnel and tunnel address information.
28. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the steps of the method of any one of claims 1 to 17 are implemented when the program is executed by the processor; or,
the processor, when executing the program, performs the steps of the method of any one of claims 18 to 25.
29. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the method according to any one of claims 1 to 17; or,
the processor, when executing the program, performs the steps of the method of any one of claims 18 to 25.
CN202010003261.4A 2020-01-02 2020-01-02 A kind of NAT traversal method, device, electronic equipment and storage medium Active CN113067910B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010003261.4A CN113067910B (en) 2020-01-02 2020-01-02 A kind of NAT traversal method, device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010003261.4A CN113067910B (en) 2020-01-02 2020-01-02 A kind of NAT traversal method, device, electronic equipment and storage medium

Publications (2)

Publication Number Publication Date
CN113067910A true CN113067910A (en) 2021-07-02
CN113067910B CN113067910B (en) 2023-05-09

Family

ID=76558391

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010003261.4A Active CN113067910B (en) 2020-01-02 2020-01-02 A kind of NAT traversal method, device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN113067910B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114640663A (en) * 2022-03-03 2022-06-17 上海联虹技术有限公司 Method for remotely controlling CPE (customer premises equipment) and remote control system
CN115695577A (en) * 2021-07-31 2023-02-03 花瓣云科技有限公司 UDP data transmission method and related equipment

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101800781A (en) * 2009-02-11 2010-08-11 中国科学院计算机网络信息中心 Tunnel transition method and system for passing through NAT
WO2012171379A1 (en) * 2011-06-15 2012-12-20 中兴通讯股份有限公司 Method, device and system for nat traversal of ipsec in ah mode
CN105933198A (en) * 2016-04-21 2016-09-07 浙江宇视科技有限公司 Device for establishing direct connection VPN tunnel
CN109819067A (en) * 2019-03-12 2019-05-28 赛特斯信息科技股份有限公司 The method for realizing the NAT penetration management based on VXLAN tunneling technique using Simple Traversal of UDP Through Network Address Translators

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101800781A (en) * 2009-02-11 2010-08-11 中国科学院计算机网络信息中心 Tunnel transition method and system for passing through NAT
WO2012171379A1 (en) * 2011-06-15 2012-12-20 中兴通讯股份有限公司 Method, device and system for nat traversal of ipsec in ah mode
CN105933198A (en) * 2016-04-21 2016-09-07 浙江宇视科技有限公司 Device for establishing direct connection VPN tunnel
CN109819067A (en) * 2019-03-12 2019-05-28 赛特斯信息科技股份有限公司 The method for realizing the NAT penetration management based on VXLAN tunneling technique using Simple Traversal of UDP Through Network Address Translators

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115695577A (en) * 2021-07-31 2023-02-03 花瓣云科技有限公司 UDP data transmission method and related equipment
CN114640663A (en) * 2022-03-03 2022-06-17 上海联虹技术有限公司 Method for remotely controlling CPE (customer premises equipment) and remote control system

Also Published As

Publication number Publication date
CN113067910B (en) 2023-05-09

Similar Documents

Publication Publication Date Title
CN104270379B (en) HTTPS agency retransmission methods and device based on transmission control protocol
TWI441493B (en) System and method for connection of hosts behind nats
US11888818B2 (en) Multi-access interface for internet protocol security
CN110086798B (en) Method and device for communication based on public virtual interface
CN115189920A (en) Cross-network domain communication method and related device
CN100464540C (en) A method of cross-gateway communication
CN113067910B (en) A kind of NAT traversal method, device, electronic equipment and storage medium
CN102223353A (en) Host identification protocol (HIP) safe channel multiplexing method and device thereof
JP6990647B2 (en) Systems and methods that provide a ReNAT communication environment
CN104506666A (en) Proxy method and system for crossing of massive TCP (Transmission Control Protocol) through symmetrical NAT (Network Address Translation)
CN117439815B (en) Intranet penetration system and method based on reverse transparent bridging
CN100479457C (en) Implementation method for transferring data in virtual private network
CN102984167B (en) Traversal method for universal firewall based on Socks5 protocol
CN105430066A (en) A P2P technology-based interconnection method for tax control equipment
WO2011044810A1 (en) Method, device and system for implementing multiparty communication
CN113067908B (en) NAT (network Address translation) traversing method and device, electronic equipment and storage medium
CN100505754C (en) A Method for Realizing Dynamic 4-in-6 Tunnel Establishment
CN112751816B (en) Tunnel establishment method, device, equipment and computer readable storage medium
CN113067911A (en) A NAT traversal method, device, electronic device and storage medium
CN103167022B (en) A kind of data pack transmission method, relevant device and system
CN112751946B (en) Tunnel establishment method, device, equipment and computer readable storage medium
CN114726824B (en) Wireless broadband router, message processing and domain name resolution method and device
WO2023274146A1 (en) Remote access method, electronic device, and storage medium
CN114584528A (en) Tunnel establishment method, device and equipment
CN101359998A (en) Method and device for establishing network element routing

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant