CN100525251C - A method for network address translation - Google Patents
A method for network address translation Download PDFInfo
- Publication number
- CN100525251C CN100525251C CNB2006101442480A CN200610144248A CN100525251C CN 100525251 C CN100525251 C CN 100525251C CN B2006101442480 A CNB2006101442480 A CN B2006101442480A CN 200610144248 A CN200610144248 A CN 200610144248A CN 100525251 C CN100525251 C CN 100525251C
- Authority
- CN
- China
- Prior art keywords
- address
- data frame
- network
- port number
- control block
- 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.)
- Active
Links
- 238000012545 processing Methods 0.000 claims abstract description 69
- 238000000034 method Methods 0.000 claims abstract description 43
- 238000006243 chemical reaction Methods 0.000 claims abstract description 16
- 238000013519 translation Methods 0.000 claims description 44
- 230000008859 change Effects 0.000 claims description 10
- 230000008569 process Effects 0.000 claims description 10
- 238000005516 engineering process Methods 0.000 description 6
- 238000005406 washing Methods 0.000 description 3
- 230000003993 interaction Effects 0.000 description 2
- 230000007774 longterm Effects 0.000 description 2
- 230000007246 mechanism Effects 0.000 description 2
- 238000012544 monitoring process Methods 0.000 description 2
- 230000006855 networking Effects 0.000 description 2
- WQZGKKKJIJFFOK-GASJEMHNSA-N Glucose Natural products OC[C@H]1OC(O)[C@H](O)[C@@H](O)[C@@H]1O WQZGKKKJIJFFOK-GASJEMHNSA-N 0.000 description 1
- 230000036772 blood pressure Effects 0.000 description 1
- 238000004891 communication Methods 0.000 description 1
- 230000007547 defect Effects 0.000 description 1
- 238000010586 diagram Methods 0.000 description 1
- 239000003814 drug Substances 0.000 description 1
- 229940079593 drug Drugs 0.000 description 1
- 239000008103 glucose Substances 0.000 description 1
- 230000036541 health Effects 0.000 description 1
- 238000005259 measurement Methods 0.000 description 1
- 230000008520 organization Effects 0.000 description 1
- 230000035515 penetration Effects 0.000 description 1
- 239000000779 smoke Substances 0.000 description 1
Images
Landscapes
- Data Exchanges In Wide-Area Networks (AREA)
- Small-Scale Networks (AREA)
Abstract
本发明公开了一种网络地址转换方法,实现公网与私网间网络地址的转换,在网络地址转换时采用了处理控制块,网络地址转换方法包括私网IP地址转换到公网IP地址,以及公网IP地址转换到私网IP地址;私网IP地址转换到公网IP地址时,在家庭网关中建立处理控制块,并修改所发送数据帧的端口号和源IP地址后,将数据帧发送到公网;公网IP地址转换到私网IP地址时,为所接收到的数据帧在家庭网关中查找对应的处理控制块,根据处理控制块中的信息修改数据帧的目的IP地址和目的端口号。
The invention discloses a network address conversion method, which realizes network address conversion between a public network and a private network, and adopts a processing control block during network address conversion. The network address conversion method includes converting a private network IP address to a public network IP address, And the public network IP address is converted to the private network IP address; when the private network IP address is converted to the public network IP address, a processing control block is set up in the home gateway, and after modifying the port number and the source IP address of the sent data frame, the data The frame is sent to the public network; when the public network IP address is converted to the private network IP address, the corresponding processing control block is searched in the home gateway for the received data frame, and the destination IP address of the data frame is modified according to the information in the processing control block and destination port number.
Description
技术领域 technical field
本发明涉及计算机网络技术,特别涉及到网络地址转换的实现。The invention relates to computer network technology, in particular to the realization of network address translation.
背景技术 Background technique
随着宽带技术的成熟,家庭网络化将成为了整个社会信息化的一个重要部分,为了适应这种持续激增的宽带业务需求,提出了“数字家庭”这一新的概念。“数字家庭”类的业务可以分为四种类型:With the maturity of broadband technology, home networking will become an important part of the entire society's informatization. In order to meet the continuously increasing demand for broadband services, a new concept of "digital home" is proposed. Businesses in the "Digital Home" category can be divided into four types:
1、家庭娱乐和通信类:通过机顶盒提供数字电视、视音频点播、时移电视、网络游戏,视频电话,以及远程教育等业务;1. Home entertainment and communication: provide services such as digital TV, video and audio on demand, time-shift TV, online games, video telephony, and distance education through set-top boxes;
2、家庭安全类:为家庭提供监控和告警,例如,闯入警报、户外警报、烟雾/溢水监测和告警等;2. Home security category: provide monitoring and alarms for families, such as intrusion alarms, outdoor alarms, smoke/overflow monitoring and alarms, etc.;
3、家庭自动控制类:利用网络进行家电控制,照明控制,门窗控制等;3. Home automatic control: use the network to control home appliances, lighting control, door and window control, etc.;
4、家庭医疗保健类:作为一个远期方案,家庭医疗业务能够对家庭成员进行远程日常健康检查,心电图/血压/血糖/体重/肺量测量、实施药疗计划、视频会诊等。4. Family medical care: As a long-term plan, the family medical business can conduct remote daily health checks, ECG/blood pressure/glucose/weight/spirometer measurements, implement drug treatment plans, and video consultations for family members.
“数字家庭”在实现时的一个技术障碍是现有的计算机网络已经不能很好的支持数字化网络向家庭内部设备的渗透,其中IP地址的紧缺就是其中所遇到的一个重要问题。现在普遍使用的IPv4是于20世纪70年代末期设计的IP协议,IPv4的IP地址只有32位,随着全球计算机用户的增加,以及早期IP地址的分类及分配方法的不足,IP地址的紧缺现象十分严重。虽然新提出的IPv6将IP地址从32位扩展为128位,可以从根本上解决IP地址紧缺的问题,但对已经成熟运行的现有网络体系结构(包括网络硬件设备和运行的网络协议软件等)影响较大,很难在短期内取代IPv4。One of the technical obstacles in the realization of "Digital Home" is that the existing computer network can no longer support the penetration of digital networks into home devices, and the shortage of IP addresses is an important problem encountered. IPv4, which is widely used now, is an IP protocol designed in the late 1970s. The IP address of IPv4 is only 32 bits. With the increase of global computer users, and the lack of early IP address classification and allocation methods, there is a shortage of IP addresses. Very serious. Although the newly proposed IPv6 expands the IP address from 32 bits to 128 bits, which can fundamentally solve the problem of the shortage of IP addresses, but the existing network architecture (including network hardware devices and running network protocol software, etc.) ) has a greater impact, and it is difficult to replace IPv4 in the short term.
解决IP地址短缺的一种方法是采用网络地址转换(NAT)技术,只要在专用网和因特网连接的路由设备上运行一个NAT程序,就能以很小的代价解决IPv4地址紧缺的问题。在“数字家庭”中也可以用网络地址转换技术解决IP地址的短缺,使得现在成熟的计算机网络技术的价值链得到延伸,且不改变现有的计算机网络的体系结构。One way to solve the shortage of IP addresses is to use Network Address Translation (NAT) technology. As long as a NAT program is run on the routing equipment connected to the private network and the Internet, the problem of shortage of IPv4 addresses can be solved at a small cost. In the "digital home", the network address translation technology can also be used to solve the shortage of IP addresses, so that the value chain of the current mature computer network technology can be extended without changing the existing computer network architecture.
在数字家庭中,实现网络地址转换的相应NAT程序安装在家庭网关上。家庭网关是连接公网和家庭私网的喉舌,它既负责家庭私网内部对公网的访问和交互,又负责用户从公网上对于家庭网络的访问和控制,另外还需要负责家庭私网内部设备的互联,互控等操作。一个具备实用价值的家庭网关应当具备宽带接入、业务识别、控制信息转发等功能。In a digital home, the corresponding NAT program that implements network address translation is installed on the home gateway. The home gateway is the mouthpiece connecting the public network and the home private network. It is not only responsible for the access and interaction of the home private network to the public network, but also responsible for the user's access and control of the home network from the public network. Device interconnection, mutual control and other operations. A home gateway with practical value should have functions such as broadband access, business identification, and control information forwarding.
现有NAT技术为了适应广泛的适用性,必须对硬件层的差异进行很好的屏蔽,这就意味着要增加上层软件的复杂性。然而,对于数字家庭中的家庭网关来说,由于应用环境比较固定,也比较单一,所以并不需要具备很强的灵活性,而是需要实现简单和较高效率。因此,为家庭网关提供一种简单、高效的网络地址转换方法对数字家庭的实现具有重大的意义。In order to adapt to a wide range of applicability, the existing NAT technology must well shield the differences of the hardware layer, which means increasing the complexity of the upper layer software. However, for the home gateway in the digital home, because the application environment is relatively fixed and relatively simple, it does not need to have strong flexibility, but needs to achieve simplicity and high efficiency. Therefore, providing a simple and efficient network address translation method for the home gateway is of great significance to the realization of the digital home.
发明内容 Contents of the invention
本发明的目的是克服现有的路由设备的上层软件过于复杂,网络地址转换效率较低的缺陷,从而提供一种简单、高效的网络地址转换方法。The purpose of the present invention is to overcome the defects that the upper layer software of the existing routing equipment is too complicated and the network address translation efficiency is low, thereby providing a simple and efficient network address translation method.
为了实现上述目的,本发明提供了一种网络地址转换方法,在网络地址转换时采用处理控制块,所述处理控制块包括6个子块,分别为路由设备上某个内部网络接口的IP地址、内部网络接口的端口号、私网中与内部网络接口相连的内部终端设备的IP地址、用于组织数据结构的信息、全局唯一的端口号以及超时信息;In order to achieve the above object, the present invention provides a network address translation method, which uses a processing control block during network address translation, and the processing control block includes 6 sub-blocks, which are respectively the IP address of a certain internal network interface on the routing device, The port number of the internal network interface, the IP address of the internal terminal device connected to the internal network interface in the private network, the information used to organize the data structure, the globally unique port number and timeout information;
所述的网络地址转换方法用于实现私网IP地址到公网IP地址的转换,具体包含以下步骤:The described network address translation method is used to realize the conversion from the private network IP address to the public network IP address, and specifically includes the following steps:
步骤11)、路由设备的内部网络接口接收私网发来的数据帧;Step 11), the internal network interface of routing device receives the data frame that private network sends;
步骤12)、判断数据帧接收是否正确,若正确,执行下一步,否则删除所接收到的数据帧,然后执行步骤18);Step 12), judge whether the data frame reception is correct, if correct, perform the next step, otherwise delete the received data frame, then perform step 18);
步骤13)、根据数据帧的目的IP地址,判断数据帧是否发往外部的公网,若发往外部的公网,则执行下一步,否则,执行步骤18);Step 13), according to the purpose IP address of data frame, judge whether data frame sends to external public network, if send to external public network, then carry out next step, otherwise, carry out step 18);
步骤14)、将数据帧的源地址与路由设备中所保存的关于处理控制块的表进行比较,若源地址与某一处理控制块所记录的内部终端设备的IP地址相同,则本次数据转发已建立过连接,执行步骤16),否则执行下一步;Step 14), comparing the source address of the data frame with the table about the processing control block stored in the routing device, if the source address is the same as the IP address of the internal terminal device recorded in a certain processing control block, the current data Forward the connection has been established, go to step 16), otherwise go to the next step;
步骤15)、在路由设备所保存的关于处理控制块的表中建立新的处理控制块;Step 15), create a new processing control block in the table about the processing control block saved by the routing device;
步骤16)、将数据帧中的内部网络接口的端口号修改为全局唯一的端口号,将数据帧的源IP地址修改为路由设备的外部网络接口的IP地址,同时修改校验和;Step 16), modify the port number of the internal network interface in the data frame to a globally unique port number, modify the source IP address of the data frame to the IP address of the external network interface of the routing device, and modify the checksum simultaneously;
步骤17)、调用外部网络接口的驱动程序的发送处理进程发送数据帧;Step 17), calling the sending processing process of the driver program of the external network interface to send the data frame;
步骤18)、结束本次发送操作。Step 18), end this sending operation.
本发明还提供了一种网络地址转换方法,在网络地址转换时采用处理控制块,所述处理控制块包括6个子块,分别为路由设备上某个内部网络接口的IP地址、内部网络接口的端口号、私网中与内部网络接口相连的内部终端设备的IP地址、用于组织数据结构的信息、全局唯一的端口号以及超时信息;The present invention also provides a network address translation method, which uses a processing control block during network address translation, and the processing control block includes 6 sub-blocks, which are respectively the IP address of a certain internal network interface on the routing device, and the IP address of the internal network interface. Port number, IP address of the internal terminal device connected to the internal network interface in the private network, information for organizing data structure, globally unique port number and timeout information;
所述的网络地址转换方法用于实现公网IP地址到私网IP地址的转换,具体包含以下步骤:The described network address translation method is used to realize the conversion from the public network IP address to the private network IP address, and specifically includes the following steps:
步骤21)、路由设备的外部网络接口接收外部网络发来的数据帧;Step 21), the external network interface of routing device receives the data frame that external network sends;
步骤22)、判断数据帧接收是否正确,若正确,执行下一步,否则删除所接收到的数据帧,然后执行步骤27);Step 22), judge whether the data frame reception is correct, if correct, perform the next step, otherwise delete the received data frame, then perform step 27);
步骤23)、根据数据帧中的目的端口号,判断该数据帧是否发往私网,若目的端口号与保存在路由设备中的处理控制块中的全局唯一端口号相同,则该数据帧发往私网,执行下一步;否则执行步骤27);Step 23), according to the purpose port number in the data frame, judge whether this data frame is sent to private network, if the purpose port number is identical with the global unique port number in the processing control block that is stored in the routing equipment, then this data frame sends To the private network, go to the next step; otherwise go to step 27);
步骤24)、根据查找到的与目的端口号相同的全局唯一端口号,找到该全局唯一端口号所在处理控制块;Step 24), find the processing control block where the globally unique port number is located according to the globally unique port number found that is identical to the destination port number;
步骤25)、利用步骤24)中所查找到的处理控制块中的内部终端设备的IP地址修改数据帧中的目的IP地址,利用处理控制块中的内部网络接口的端口号修改数据帧中的目的端口号,同时还更改数据帧中的校验和;Step 25), utilize the IP address of the internal terminal equipment in the processing control block found in step 24) to modify the destination IP address in the data frame, utilize the port number of the internal network interface in the processing control block to modify the IP address in the data frame Destination port number, and also change the checksum in the data frame;
步骤26)、利用步骤24)中所查找到的处理控制块中内部网络接口的IP地址,调用该接口的驱动程序的发送处理进程转发该数据帧;Step 26), utilize the IP address of the internal network interface in the processing control block found in step 24), call the sending process of the driver of the interface to forward the data frame;
步骤27)、结束操作。Step 27), end operation.
上述技术方案中,所述的网络地址转换方法实现公网IP地址到私网IP地址的转换前,对所述处理控制块作配置操作,为所述处理控制块的6个子块添加相应的信息。In the above technical solution, before the network address translation method realizes the conversion from the public network IP address to the private network IP address, the configuration operation is performed on the processing control block, and corresponding information is added to the 6 sub-blocks of the processing control block .
本发明又提供了一种网络地址转换方法,在网络地址转换时采用处理控制块,所述处理控制块包括6个子块,分别为路由设备上某个内部网络接口的IP地址、内部网络接口的端口号、私网中与内部网络接口相连的内部终端设备的IP地址、用于组织数据结构的信息、全局唯一的端口号以及超时信息;The present invention also provides a network address translation method. A processing control block is used during network address translation. The processing control block includes 6 sub-blocks, which are respectively the IP address of a certain internal network interface on the routing device, the IP address of the internal network interface, and the IP address of the internal network interface. Port number, IP address of the internal terminal device connected to the internal network interface in the private network, information for organizing data structure, globally unique port number and timeout information;
所述网络地址转换方法包括私网IP地址转换到公网IP地址,以及公网IP地址转换到私网IP地址;The network address translation method includes converting a private network IP address to a public network IP address, and converting a public network IP address to a private network IP address;
其中,所述的私网IP地址转换到公网IP地址具体包括以下步骤:Wherein, the conversion of the private network IP address to the public network IP address specifically includes the following steps:
步骤11)、路由设备的内部网络接口接收私网发来的数据帧;Step 11), the internal network interface of routing device receives the data frame that private network sends;
步骤12)、判断数据帧接收是否正确,若正确,执行下一步,否则删除所接收到的数据帧,然后执行步骤18);Step 12), judge whether the data frame reception is correct, if correct, perform the next step, otherwise delete the received data frame, then perform step 18);
步骤13)、根据数据帧的目的IP地址,判断数据帧是否发往外部的公网,若发往外部的公网,则执行下一步,否则,执行步骤18);Step 13), according to the purpose IP address of data frame, judge whether data frame sends to external public network, if send to external public network, then carry out next step, otherwise, carry out step 18);
步骤14)、将数据帧的源地址与路由设备中所保存的关于处理控制块的表进行比较,若源地址与某一处理控制块所记录的内部终端设备的IP地址相同,则本次数据转发已建立过连接,执行步骤16),否则执行下一步;Step 14), comparing the source address of the data frame with the table about the processing control block stored in the routing device, if the source address is the same as the IP address of the internal terminal device recorded in a certain processing control block, the current data Forward the connection has been established, go to step 16), otherwise go to the next step;
步骤15)、在路由设备所保存的关于处理控制块的表中建立新的处理控制块;Step 15), create a new processing control block in the table about the processing control block saved by the routing device;
步骤16)、将数据帧中的内部网络接口的端口号修改为全局唯一的端口号,将数据帧的源IP地址修改为路由设备的外部网络接口的IP地址,同时修改校验和;Step 16), modify the port number of the internal network interface in the data frame to a globally unique port number, modify the source IP address of the data frame to the IP address of the external network interface of the routing device, and modify the checksum simultaneously;
步骤17)、调用外部网络接口的驱动程序的发送处理进程发送数据帧;Step 17), calling the sending processing process of the driver program of the external network interface to send the data frame;
步骤18)、结束本次发送操作;Step 18), end this sending operation;
其中,所述的公网IP地址转换到私网IP地址具体包含以下步骤:Wherein, the described public network IP address conversion to the private network IP address specifically includes the following steps:
步骤21)、路由设备的外部网络接口接收外部网络发来的数据帧;Step 21), the external network interface of routing device receives the data frame that external network sends;
步骤22)、判断数据帧接收是否正确,若正确,执行下一步,否则删除所接收到的数据帧,然后执行步骤27);Step 22), judge whether the data frame reception is correct, if correct, perform the next step, otherwise delete the received data frame, then perform step 27);
步骤23)、根据数据帧中的目的端口号,判断该数据帧是否发往私网,若目的端口号与保存在路由设备中的处理控制块中的全局唯一端口号相同,则该数据帧发往私网,执行下一步;否则执行步骤27);Step 23), according to the purpose port number in the data frame, judge whether this data frame is sent to private network, if the purpose port number is identical with the global unique port number in the processing control block that is stored in the routing equipment, then this data frame sends To the private network, go to the next step; otherwise go to step 27);
步骤24)、根据查找到的与目的端口号相同的全局唯一端口号,找到该全局唯一端口号所在处理控制块;Step 24), find the processing control block where the globally unique port number is located according to the globally unique port number found that is identical to the destination port number;
步骤25)、利用步骤24)中所查找到的处理控制块中的内部终端设备的IP地址修改数据帧中的目的IP地址,利用处理控制块中的内部网络接口的端口号修改数据帧中的目的端口号,同时还更改数据帧中的校验和;Step 25), utilize the IP address of the internal terminal equipment in the processing control block found in step 24) to modify the destination IP address in the data frame, utilize the port number of the internal network interface in the processing control block to modify the IP address in the data frame Destination port number, and also change the checksum in the data frame;
步骤26)、利用步骤24)中所查找到的处理控制块中内部网络接口的IP地址,调用该接口的驱动程序的发送处理进程转发该数据帧;Step 26), utilize the IP address of the internal network interface in the processing control block found in step 24), call the sending process of the driver of the interface to forward the data frame;
步骤27)、结束操作。Step 27), end operation.
上述技术方案中,在所述的步骤15)中,在建立新的处理控制块时,将发送数据帧的内部终端的IP地址作为所述的私网中与内部网络接口相连的内部终端设备的IP地址;将与发送数据帧的内部终端相连的内部网络接口的IP地址作为所述的路由设备上某个内部网络接口的IP地址;将与发送数据帧的内部终端相连的内部网络接口的端口号作为所述的内部网络接口的端口号;分配一个只属于所述发送数据帧的内部终端的端口号作为所述的全局唯一的端口号。In the above technical solution, in the step 15), when setting up a new processing control block, the IP address of the internal terminal that sends the data frame is used as the IP address of the internal terminal device connected to the internal network interface in the private network. IP address; the IP address of the internal network interface connected to the internal terminal sending the data frame is used as the IP address of a certain internal network interface on the routing device; the port of the internal network interface connected to the internal terminal sending the data frame number as the port number of the internal network interface; assign a port number that only belongs to the internal terminal that sends the data frame as the globally unique port number.
上述技术方案中,在所述的步骤17)中,在发送数据帧时,在数据链路层上实现数据帧的转发。In the above technical solution, in the step 17), when the data frame is sent, the forwarding of the data frame is realized on the data link layer.
本发明的优点在于:The advantages of the present invention are:
1、本发明的网络地址转换方法针对家庭网关的特定应用,原理简单,地址转换效率高。1. The network address translation method of the present invention is aimed at the specific application of the home gateway, and has a simple principle and high address translation efficiency.
2、本发明的网络地址转换方法在链路层做数据转发操作,简化了IP层代码的实现复杂度,并提高了数据的转发效率。2. The network address translation method of the present invention performs data forwarding operations at the link layer, which simplifies the implementation complexity of the IP layer code and improves the data forwarding efficiency.
附图说明 Description of drawings
图1为本发明的网络地址转换方法中的处理控制块的数据结构图;Fig. 1 is the data structure diagram of the processing control block in the network address translation method of the present invention;
图2为本发明的网络地址转换方法中数据流在网络协议中所处的位置;Fig. 2 is the position of data flow in the network protocol in the network address translation method of the present invention;
图3为本发明的网络地址转换方法中私网IP地址转换到公网IP地址的流程图;Fig. 3 is the flow chart that private network IP address is converted to public network IP address in the network address translation method of the present invention;
图4为本发明的网络地址转换方法中公网IP地址转换到私网IP地址的流程图。FIG. 4 is a flow chart of converting a public network IP address to a private network IP address in the network address translation method of the present invention.
具体实施方式 Detailed ways
下面结合附图和具体实施方式对本发明作进一步的说明。The present invention will be further described below in conjunction with the accompanying drawings and specific embodiments.
实施例1:Example 1:
以一个家庭局域网为例,对本发明的方法进行说明。在一个家庭局域网中,多台带有网络接口的家用电器与一个家庭网关的内部网络接口相连,连接在该家庭网关上的所有家用电器形成家庭局域网。在家庭网关上还有一个外部网络接口,家庭网关通过该外部网络接口连接到互联网上,从而实现家庭局域网与互联网间的连接。假设在本实施例中的家庭局域网中,家用电器包括一个空调、一台洗衣机、一台家用电脑。这些电器都和家庭网关上的内部网络接口连接。Taking a home local area network as an example, the method of the present invention is described. In a home local area network, multiple household appliances with network interfaces are connected to an internal network interface of a home gateway, and all the home appliances connected to the home gateway form a home local area network. There is also an external network interface on the home gateway, through which the home gateway is connected to the Internet, thereby realizing the connection between the home local area network and the Internet. Assume that in the home LAN in this embodiment, household appliances include an air conditioner, a washing machine, and a home computer. These appliances are all connected to the internal network interface on the home gateway.
家庭局域网中的家用电器要与互联网中的某台外部主机进行交互需要实现网络地址的转换。本发明构造了一种新的数据结构“处理控制块”(Processing ControlBlock,以下可简称PCB)来实现网络地址的转换。如图1所示,处理控制块可以分成六个子块,其中,①表示路由设备上某个内部网络接口的IP地址;②表示内部网络接口的端口号;③表示内部网络中与①所表示的内部网络接口相连的内部终端设备的IP地址;④表示用于组织数据结构的信息,该项用于将记录项连⑤接成一个链表,以便管理;⑤表示全局唯一的端口号,家庭局域网中的不同电器有不同的端口号⑤,对同一个电器在不同时间有同样的端口号⑤;⑥表示超时信息,用于将长时间没有用到的某个PCB数据结构删除,以便动态维护整个地址转换所需的信息。The home appliances in the home LAN need to implement network address translation to interact with an external host in the Internet. The present invention constructs a new data structure "Processing Control Block" (Processing Control Block, hereinafter referred to as PCB) to realize network address conversion. As shown in Figure 1, the processing control block can be divided into six sub-blocks, wherein, ① represents the IP address of a certain internal network interface on the routing device; ② represents the port number of the internal network interface; ③ represents the internal network and ① represented The IP address of the internal terminal device connected to the internal network interface; ④ indicates the information used to organize the data structure, and this item is used to connect the
下面假设家庭局域网中的一台电脑与外部一台主机进行交互,对本发明的网络地址转换方法作进一步的说明。家庭局域网中的电脑与外部主机交互可以分成两大部分,即内部网络发出对外部网络的访问请求,外部网络回应内部网络的访问请求,下面分别进行说明:Next, assuming that a computer in the home local area network interacts with an external host, the network address translation method of the present invention will be further described. The interaction between the computer in the home LAN and the external host can be divided into two parts, that is, the internal network sends access requests to the external network, and the external network responds to the internal network access requests, which are explained below:
一、内部网络提出对外部网络的访问请求,如图3所示,包含以下步骤。1. The internal network makes an access request to the external network, as shown in FIG. 3 , including the following steps.
步骤11、家庭网关的内部网络接口接收内部网络发来的数据帧;Step 11, the internal network interface of the home gateway receives the data frame sent by the internal network;
步骤12、判断数据帧接收是否正确,若正确,执行下一步,否则删除所接收到的数据帧;Step 12, judging whether the received data frame is correct, if correct, execute the next step, otherwise delete the received data frame;
步骤13、解析数据帧的结构,根据IP地址所距数据帧开始位置的偏移量取出目的IP地址,判断该帧数据是不是发往外部网络;如果目的IP地址是本内部网络的某台终端的IP,则数据帧不是发往外部网络的,转步骤18;否则认为是发往外部网络,执行下一步;Step 13, analyze the structure of the data frame, take out the destination IP address according to the offset of the IP address from the start position of the data frame, and judge whether the frame data is sent to the external network; if the destination IP address is a certain terminal of the internal network IP, then the data frame is not sent to the external network, go to step 18; otherwise it is considered to be sent to the external network, go to the next step;
例如,当家庭网关接收到家庭局域网中的电脑所发送来的数据帧以后,判断数据帧中的目的IP地址,若该目的IP地址是家庭局域网中的洗衣机的IP地址或标识,就把该数据帧发送到洗衣机上,否则通过家庭网关将该数据帧发送到互联网上。For example, after the home gateway receives the data frame sent by the computer in the home LAN, it judges the destination IP address in the data frame, and if the destination IP address is the IP address or identification of the washing machine in the home LAN, the data The frame is sent to the washing machine, otherwise the data frame is sent to the Internet through the home gateway.
步骤14、将数据帧的源地址与PCB表项的③域作比较,查找PCB表,看是否有符合的PCB表项可用,即检查本次数据转发是否已经建立过连接,如果有匹配的表项可用,则执行步骤16,否则执行下一步;Step 14. Compare the source address of the data frame with the ③ field of the PCB entry, search the PCB table to see if there is a matching PCB entry available, that is, check whether a connection has been established for this data forwarding, and if there is a matching table If the item is available, go to step 16, otherwise go to the next step;
步骤15、建立新的PCB表项,然后执行下一步;Step 15, create a new PCB entry, and then execute the next step;
例如,假设家庭局域网中的电脑的网络标识为private_ip,该电脑与家庭网关相连接的内部网络接口的网络标识为local_ip,该家庭网关与互联网相连的外部网络接口的IP地址为external_ip,该IP地址是一个合法的IP地址。当电脑通过local_ip将数据发送给家庭网关时分配了一个端口号,记为local_port。假设家庭网关的全局唯一端口号为Ass_port,设定超时时间tmr(在这里超时机制的运用与网络地址转换的机制没有关系,为了突出重点和简单起见,下面将不予考虑),最后给组织数据结构的数据项赋一个有效的指针next,用于将有效的PCB数据结构组织成一个链表。家庭局域网中的电脑第一次向外发送数据时,所建立的PCB数据表如表1所示:For example, suppose the network identifier of the computer in the home LAN is private_ip, the network identifier of the internal network interface connected to the home gateway of the computer is local_ip, and the IP address of the external network interface of the home gateway connected to the Internet is external_ip, the IP address is a valid IP address. When the computer sends data to the home gateway through local_ip, a port number is assigned, which is recorded as local_port. Assume that the globally unique port number of the home gateway is Ass_port, set the timeout period tmr (the use of the timeout mechanism here has nothing to do with the network address translation mechanism, in order to highlight the key points and keep it simple, it will not be considered below), and finally give the organization data The data item of the structure is assigned an effective pointer next, which is used to organize the effective PCB data structure into a linked list. When the computer in the home LAN sends data out for the first time, the PCB data table created is shown in Table 1:
表1Table 1
建立PCB数据表以后,根据数据表中的相关内容,修改数据帧。例如,当家庭局域网中的电脑要将数据发送到互联网上时,将数据帧中的源IP修改为external_ip;将Local_port修改为ass_port,并修改校验和。After the PCB data table is established, modify the data frame according to the relevant content in the data table. For example, when a computer in the home LAN wants to send data to the Internet, change the source IP in the data frame to external_ip; change Local_port to ass_port, and modify the checksum.
步骤16、将数据帧的源IP地址段改为外部网络接口的IP地址,将原端口号改为全局唯一端口号⑤,Step 16, change the source IP address segment of the data frame into the IP address of the external network interface, change the original port number into the globally
步骤17、调用外部网络接口的驱动程序的发送处理进程发送数据帧;在转发数据帧时,如图2所示,数据帧在数据链路层上实现转发。数据之所以在链路层转发,是因为本发明的网络地址转换的实现是嵌入在网络接口的硬件驱动程序里的,可以看成是硬件驱动的一部分,而不是通过硬件驱动的接口调用驱动层提供的服务,这也就意味着不需要修改IP层,提高了数据转发的效率。Step 17, calling the sending processing process of the driver of the external network interface to send the data frame; when forwarding the data frame, as shown in Figure 2, the data frame is forwarded on the data link layer. The reason why data is forwarded at the link layer is because the realization of network address translation of the present invention is embedded in the hardware driver of the network interface, and can be regarded as a part of the hardware driver, rather than calling the driver layer through the interface of the hardware driver The service provided, which means that there is no need to modify the IP layer, which improves the efficiency of data forwarding.
步骤18、结束本次发送操作。Step 18, end this sending operation.
二、外部网络回应内部网络的访问请求,如图4所示,包含以下步骤。2. The external network responds to the access request of the internal network, as shown in FIG. 4 , including the following steps.
步骤21、家庭网关的外部网络接口接收外部网络发来的数据帧;Step 21, the external network interface of the home gateway receives the data frame sent by the external network;
步骤22、判断数据帧接收是否正确,若正确,执行下一步,否则删除所接收到的数据帧;Step 22, judging whether the received data frame is correct, if correct, execute the next step, otherwise delete the received data frame;
步骤23、解析数据帧的结构,根据目的端口号所处位置距数据帧开始位置的偏移量取出目的端口号,根据目的端口号判断该帧数据是不是发往该内部网络的;用目的端口号与PCB表中的表项中的⑤逐个匹配,如果不存在匹配的PCB表项,则数据帧不是发往内部网络,执行步骤27;否则是发往该内部网络,执行下一步;Step 23, parse the structure of the data frame, take out the destination port number according to the offset between the location of the destination port number and the start position of the data frame, judge whether the frame data is sent to the internal network according to the destination port number; use the destination port The number is matched with ⑤ in the entries in the PCB table one by one. If there is no matching PCB entry, the data frame is not sent to the internal network, go to step 27; otherwise, it is sent to the internal network, go to the next step;
步骤24、根据查找到的与目的端口号相同的全局唯一端口号,找到该全局唯一端口号所在PCB;Step 24. Find the PCB where the globally unique port number is located according to the found globally unique port number identical to the destination port number;
步骤25、根据PCB表项中的③域更改数据帧中的目的IP地址,利用②域更改数据帧中的目的端口号,并修改相应的校验位;Step 25, change the destination IP address in the data frame according to the ③ field in the PCB entry,
例如,当互联网中的终端向家庭局域网中的电脑发送数据帧时,该数据帧中的目的端口号应为ass_port,通过对PCB表的查找,家庭网关可知该数据帧是发送到它所连接的家庭局域网中的,根据PCB表项中所填写的内容,将数据帧中的目的地址由external_ip修改为private_ip,将数据帧中的目的端口号由ass_port修改为local_port。For example, when a terminal in the Internet sends a data frame to a computer in the home LAN, the destination port number in the data frame should be ass_port. By looking up the PCB table, the home gateway can know that the data frame is sent to the computer it is connected to. In the home LAN, according to the content filled in the PCB entry, modify the destination address in the data frame from external_ip to private_ip, and modify the destination port number in the data frame from ass_port to local_port.
步骤26、根据匹配PCB表项的①找出相应的内部网络接口,调用该接口的驱动程序的发送处理进程转发该数据帧;Step 26, find out the corresponding internal network interface according to 1. of the matching PCB entry, and call the sending process of the driver of the interface to forward the data frame;
由于在PCB表项中,与电脑相连的内部网络接口的网络标识为local_ip,调用其驱动程序将数据帧发送到电脑上。Since in the PCB entry, the network identifier of the internal network interface connected to the computer is local_ip, its driver is called to send the data frame to the computer.
步骤27、结束操作。Step 27, end the operation.
实施例2:Example 2:
在一些私网中,某些内部终端不会主动提出访问网络的请求,例如在“数字家庭”一台具有联网功能的空调并不能访问公网中的终端。但用户需要对其进行远程控制,因此需要对其进行配置操作。In some private networks, some internal terminals will not take the initiative to request access to the network. For example, in a "digital home", an air conditioner with networking function cannot access terminals in the public network. But the user needs to control it remotely, so it needs to be configured.
在具体实现时,就是为私网中的内部终端分配一些保留的全局唯一的端口号。例如将65000~65530范围的端口号作为保留端口号,分配给空调等“被动式”的设备使用,由用户通过计算机对家庭网关进行配置,具体配置内容就是为类似的“被动式”设备建立PCB数据结构。例如,某个空调的终端IP地址为IP_aircondition;连接到家庭网关的内部网络接口的地址为IP_local_air;为其分配的全局唯一的端口号为65001;由于这种被动设备不会同时出现多个会话(session),所以内部网络结构的端口号理论上可以不用,但为了保持一致性,也为了计算校验和方便,可以将其设为与全局唯一端口号相同即65001;并且超时计时器tmr可设为无穷大,即此项PCB数据结构不会由于时间过久没有使用而失效。则建立的PCB数据结构如表2所示:In actual implementation, some reserved globally unique port numbers are assigned to the internal terminals in the private network. For example, the port numbers in the range of 65000~65530 are used as reserved port numbers and allocated to "passive" devices such as air conditioners. The user configures the home gateway through a computer. The specific configuration content is to establish a PCB data structure for similar "passive" devices. . For example, the terminal IP address of an air conditioner is IP_aircondition; the address of the internal network interface connected to the home gateway is IP_local_air; the globally unique port number assigned to it is 65001; since this passive device does not have multiple sessions at the same time ( session), so the port number of the internal network structure can theoretically be used, but in order to maintain consistency and facilitate the calculation of the checksum, it can be set to be the same as the globally unique port number, that is, 65001; and the timeout timer tmr can be set It is infinity, that is, this PCB data structure will not be invalidated due to long-term non-use. The established PCB data structure is shown in Table 2:
表2Table 2
建立上述处理控制块后,数据转发的操作流程与实施例1中所描述的正常的处理流程相同。在本实施例中不再作进一步的说明。After the above processing control block is established, the operation flow of data forwarding is the same as the normal processing flow described in
上述的实施例1和实施例2以家庭局域网为例,对本发明的网络地址转换方法进行说明,但本领域的普通技术人员应当明白,在其他涉及公网IP地址与私网IP地址转换的应用场景中,本发明的网络地址转换方法同样适用。The above-mentioned
Claims (6)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CNB2006101442480A CN100525251C (en) | 2006-11-30 | 2006-11-30 | A method for network address translation |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CNB2006101442480A CN100525251C (en) | 2006-11-30 | 2006-11-30 | A method for network address translation |
Publications (2)
Publication Number | Publication Date |
---|---|
CN1996945A CN1996945A (en) | 2007-07-11 |
CN100525251C true CN100525251C (en) | 2009-08-05 |
Family
ID=38251887
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CNB2006101442480A Active CN100525251C (en) | 2006-11-30 | 2006-11-30 | A method for network address translation |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN100525251C (en) |
Families Citing this family (15)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101635747B (en) * | 2008-07-24 | 2012-07-18 | 工业和信息化部电信传输研究所 | Inter-network address resolution device for non-PTDN networks and PTDN networks |
CN101360030B (en) * | 2008-08-21 | 2011-10-05 | 华为技术有限公司 | Method and gateway for private network users to use public network address to access public network |
CN101800690B (en) * | 2009-02-05 | 2012-08-15 | 北京启明星辰信息技术股份有限公司 | Method and device for realizing source address conversion by using address pool |
US8860775B2 (en) | 2009-04-14 | 2014-10-14 | Huawei Device Co., Ltd. | Remote presenting system, device, and method |
JP5561976B2 (en) * | 2009-09-11 | 2014-07-30 | キヤノン株式会社 | Information processing apparatus, information processing apparatus control method, and program |
CN102055755B (en) * | 2009-10-29 | 2013-10-23 | 杭州华三通信技术有限公司 | A method for data communication between a public network and a private network and a secure card insertion |
CN102118455B (en) * | 2009-12-30 | 2015-08-19 | 康佳集团股份有限公司 | A kind of method of Web TV configuration network address, device and the network equipment |
US8902743B2 (en) * | 2010-06-28 | 2014-12-02 | Microsoft Corporation | Distributed and scalable network address translation |
CN101986666B (en) * | 2010-11-05 | 2013-07-24 | 清华大学 | Network data transmission method based on virtual network interface and reverse address resolution |
CN103024089B (en) * | 2011-09-20 | 2016-02-17 | 中国电信股份有限公司 | Method for network address translation and equipment |
WO2012162996A1 (en) * | 2011-09-30 | 2012-12-06 | 华为技术有限公司 | Ip address obtaining method and network access device |
CN103379187B (en) * | 2012-04-28 | 2016-12-14 | 南京中兴新软件有限责任公司 | A kind of data processing method and Gateway Network Element |
CN105827427B (en) * | 2015-01-08 | 2020-06-23 | 联想(北京)有限公司 | Information processing method and electronic equipment |
CN105681330A (en) * | 2016-02-29 | 2016-06-15 | 四川长虹电器股份有限公司 | Telecommunication internal network remote access method |
CN110198365B (en) * | 2019-05-27 | 2022-12-23 | 杭州迪普科技股份有限公司 | Address translation detection method and system |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1332552A (en) * | 2000-03-03 | 2002-01-23 | 尼克斯兰德公司 | Network address conversion gateway of local network using local IP address and untranslated port address |
CN1458598A (en) * | 2002-05-17 | 2003-11-26 | 清华同方股份有限公司 | Method and its device for household network gateway |
CN1460347A (en) * | 2001-06-22 | 2003-12-03 | 埃克斯克网络有限公司 | Method for implementing transparent gateway or proxy in network |
CN1694430A (en) * | 2005-05-25 | 2005-11-09 | 复旦大学 | Gateway Penetration Method of UDP Streaming Media Server Based on NAT |
-
2006
- 2006-11-30 CN CNB2006101442480A patent/CN100525251C/en active Active
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1332552A (en) * | 2000-03-03 | 2002-01-23 | 尼克斯兰德公司 | Network address conversion gateway of local network using local IP address and untranslated port address |
CN1460347A (en) * | 2001-06-22 | 2003-12-03 | 埃克斯克网络有限公司 | Method for implementing transparent gateway or proxy in network |
CN1458598A (en) * | 2002-05-17 | 2003-11-26 | 清华同方股份有限公司 | Method and its device for household network gateway |
CN1694430A (en) * | 2005-05-25 | 2005-11-09 | 复旦大学 | Gateway Penetration Method of UDP Streaming Media Server Based on NAT |
Also Published As
Publication number | Publication date |
---|---|
CN1996945A (en) | 2007-07-11 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN100525251C (en) | A method for network address translation | |
ES2356848T3 (en) | METHOD AND SYSTEM OF MANAGEMENT OF LOCAL NETWORKS DISTANCE THROUGH A COMMUNICATION DEVICE. | |
CN1454355A (en) | Method and device for processing network data transmission | |
WO2015066840A1 (en) | Device and method for network address conversion | |
CN101242413A (en) | System and method for obtaining service resource address in same-root multi-layer NAT network | |
CN103973569B (en) | Data message forwarding method, customer premises equipment and system | |
CN105827745A (en) | Addressing communication method based on media access control address and addressing communication device thereof | |
CN101262447A (en) | A method for establishing a NAT traversal channel for a system terminal device | |
CN101883156B (en) | Method for traversing NAT (Network Address Translation) equipment | |
CN106302847B (en) | Network transmission method and system for multi-layer network address translator structure | |
CN105635335B (en) | Social resources cut-in method, apparatus and system | |
CN102685262A (en) | Method, device and system for detecting network address translation (NAT) information | |
TW201414253A (en) | Network address translation system and method | |
CN103516820B (en) | Port mapping method and device based on MAC Address | |
CN104283984B (en) | A kind of method for realizing the interconnection of foreign peoples's address network | |
TWI735633B (en) | Data transmission method, equipment, device and system | |
CN106713528A (en) | Home gateway and method of IPv6 host to access network server | |
CN108696370A (en) | A kind of server and business-binding reconciliation binding method, apparatus and system | |
CN106533984B (en) | A kind of cut-in method and device of social resources | |
KR100661006B1 (en) | Home network terminal management system and method | |
CN104702565A (en) | Media resource sharing method, sharing server and sharing system | |
CN106657377A (en) | WIA-PA (Wireless Networks for Industrial Automation-Process Automation)/full-interconnection manufacturing network information service adaptor and realization method thereof | |
KR100652958B1 (en) | Data transmission method and system through improvement of network address translation method of home gateway | |
CN103458058B (en) | A kind of network household appliance communication agent method and apparatus | |
CN105049302B (en) | Household communication system and communication means based on public server |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
C14 | Grant of patent or utility model | ||
GR01 | Patent grant | ||
EE01 | Entry into force of recordation of patent licensing contract | ||
EE01 | Entry into force of recordation of patent licensing contract |
Application publication date: 20070711 Assignee: Zhongke Yuanshu (Beijing) Technology Co., Ltd. Assignor: Institute of Computing Technology, Chinese Academy of Sciences Contract record no.: X2019990000091 Denomination of invention: A method for network address translation Granted publication date: 20090805 License type: Common License Record date: 20190919 |