The basic principle and application of NAT technology

Source: Internet
Author: User
Tags joins

Original link: https://www.cnblogs.com/dongzhuangdian/p/5105844.html 1 Overview 1.1 Introduction 1.1.1 noun explanation

Public IP Address: also known as the Global address, refers to a legitimate IP address, which is the NIC (Network Information Center) or ISP (Network service provider) assigned address, external representative of one or more internal local address, is a globally unified addressable address.

Private IP Address: also known as internal address, is a non-registered address, specifically for the internal use of the organization. The Internet Allocation Numbering Committee (IANA) retains 3 IP addresses as private IP addresses:

10.0.0.0 ——— 10.255.255.255

172.16.0.0 ——— 172.16.255.255

192.168.0.0 ——— 192.168.255.255

address pool: The address pool is a combination of some external addresses (globally unique IP addresses), which we call a collection of addresses as an address pool. When a packet of an internal network arrives at an external network through address translation, an IP address is selected in the address pool as the source IP address of the packet, which effectively leverages the user's external address to improve the ability to access the external network. 1.1.2 about NAT

Nat English full name is "network address translation", the Chinese meaning is "the net addresses translates", it is an IETF (Internet Engineering Task Force, Internet Engineering Tasks Group) standard, Allows a whole organization to appear on the internet with a public IP (Internet Protocol) address. As the name implies, it is a technique for translating an internal private network address (IP address) into a legitimate network IP address, as shown in the following figure. Therefore, we can think that NAT to a certain extent, can effectively solve the problem of insufficient public network address.

In short, Nat is the use of internal addresses in the LAN internal network, and when the internal node to communicate with the external network, the gateway (can be understood as an exit, like a yard door) place, the internal address is replaced by the public address, so that the external public network (the Internet) normal use, NAT allows multiple computers to share an Internet connection, a feature that solves the problem of a shortage of public IP addresses. This way, you can only request a legitimate IP address, the entire local area network computer access to the Internet. At this point, Nat masks the internal network, and all intranet computers are invisible to the public network, and intranet computer users are not usually aware of the existence of Nat. As shown in the following figure. The internal address mentioned here refers to the private IP address assigned to the node in the internal network, which can only be used in the internal network and cannot be routed forward.

NAT functionality is typically integrated into routers, firewalls, ISDN routers, or separate NAT devices. For example, the Cisco router has joined this feature, the network administrator only need to set the NAT function in the router's iOS, can realize the shield to the internal network. For example, the firewall maps the internal address of the Web server 192.168.1.1 to the external address 202.96.23.11, and the external access 202.96.23.11 address is actually the access 192.168.1.1. In addition, for small businesses with limited funding, this capability can now be achieved through software. This feature is included in Windows 98 SE, Windows 2000. 1.2 Classification

There are three types of NAT: static NAT, dynamic address Nat (pooled NAT), network address port translation napt (Port-level nat).

1.2.1 Static Nat

By setting up manually, communications from Internet customers can be mapped to a specific private network address and port. Static mapping is required if you want to enable computers connected to the Internet to use a server on a private network, such as a Web server, and applications such as games. Static mappings are not removed from the NAT translation table.

If a mapping exists in a NAT translation table, Nat simply transfers data from the Internet to the private network in one Direction. In this way, NAT provides some level of protection for computers connected to the private network portion. However, if you consider the security of the Internet, NAT should be used with a fully functional firewall.

For the above network topology diagram, when the intranet host 10.1.1.1 if you want to communicate with the host 201.0.0.11 of the external network, the host (ip:10.1.1.1) packet passes through the router, the router finds the NAT table The IP packet's source IP address (10.1.1.1) is changed to the corresponding global IP address (201.0.0.1), and the destination IP address 201.0.0.11 remains the same, so that the packet can reach 201.0.0.11. When the host HostB (ip:201.0.0.11) response packet arrives at the router connected to the intranet, the router also looks for the NAT table, changing the IP packet's destination IP address to 10.1.1.1, so that the intranet host can receive packets sent from the external network host. in the static NAT mode, the internal IP address and the public IP address is a mapping relationship , so in this way, the premise is that the organization can apply to a sufficient number of global IP address. 1.2.2 Dynamic NAT

Dynamic address Nat is simply a translation of an IP address, which assigns a temporary external IP address to each internal IP address, is primarily used for dialing, and can also be used for frequent remote joins with dynamic Nat. When a remote user joins, the dynamic address Nat is assigned to an IP address that will be released for later use when the user disconnects.

The dynamic NAT method is suitable for the situation when the organization requests the global IP address less, and the internal network host is more. Intranet host IP and global IP address are many-to-one relationships. When the packet goes in and out of the intranet, the NAT-enabled device handles the IP packet the same as the static NAT, except that the record in the NAT table is dynamic , and if the intranet host does not communicate with the external network for a certain period of time, the IP address mapping relation will be deleted. The global IP address is assigned to the new IP packet for use, creating a new NAT table mapping record. 1.2.3 Network address port conversion napt

The network address port conversion, NAPT, is where the internal address is mapped to a different port on an IP address of the external network. It can hide small and medium-sized networks behind a legitimate IP address. Unlike dynamic address NAT, NAPT maps An internal connection to a separate IP address in the external network, adding a port number selected by the NAT device to the address.

Napt is the most common form of conversion, and it contains two different ways of converting: Snat and Dnat.

(1) Source NAT (source Nat,snat): Modifies the source address of the packet. Source NAT changes the source address of the first packet, which is always done before the packet is sent to the network, and packet spoofing is a snat example.

(2) Purpose NAT (Destination Nat,dnat): Modifies the destination address of the packet. Destination Nat is just the opposite of Snat, which is changing the destination address of the first packet, such as balanced load, port forwarding, and transparent proxy, which belong to Dnat.

Source NAT Example: for the above network topology diagram, the number of hosts in the intranet is more, but the organization has a legitimate IP address, when the intranet host (10.1.1.3) outgoing packets, you need to modify the packet IP address and TCP/UDP port number, for example, the

SOURCE ip:10.1.1.3

SOURCE port:1493

Change into

SOURCE ip:201.0.0.1

SOURCE port:1492 (Note: The source port number can be the same as the original)

When the external network host (201.0.0.11) responds to the intranet host (10.1.1.3), it should:

Objective ip:201.0.0.1

Objective port:1492

Change into

Objective ip:10.1.1.3

Objective port:1493

In this way, by modifying the IP address and port method, all the hosts in the intranet can access the external network, such NAT is applicable to only one legitimate IP address within the organization or agency, and is also a special case of dynamic NAT.

Purpose NAT Example: This approach is suitable for some servers in the intranet that need to provide some services to the extranet . For example, the above topology, intranet server farm (IP address is: 10.1.1.1,10.1.1.2,10.1.1.3, etc.) need to provide Web services for the external network, when the external network host HOSTB access to the intranet, The destination IP address of the packet being sent is 10.1.1.127, the port number is: 80, when the packet arrives at the intranet connected router, the router looks for NAT table, the router by modifying the destination IP address and port number, the packet of the external network is sent on average to different host (10.1.1.1 , 10.1.1.2,10.1.1.3, etc.), so that load balancing is achieved. 2 NAT Principle 2.1 Address Translation

Nat basically works by converting the source IP or destination IP in the IP packet between the private IP and the NAT public IP when the IP packet that the private network host communicates with the public network host passes through the Nat gateway.

As shown in the following illustration, the NAT Gateway has 2 network ports, where the IP address of the public network port is the uniformly allocated public IP, 202.20.65.5; The IP address of the private network port is the reserved address of 192.168.1.1. The host 192.168.1.2 in the private network sends 1 IP packets (dst=202.20.65.4,src=192.168.1.2) to the host 202.20.65.4 in the public network.


When the IP packet passes through the Nat Gateway, NAT gateways translates the IP packet's source IP into the Nat gateway's public IP and forwards it to the public network, where the IP packet (dst=202.20.65.4,src= 202.20.65.5) does not already contain any private network IP information. Because the IP packet's source IP has been converted to NAT Gateway, the response IP packet (dst= 202.20.65.5,src=202.20.65.4) emitted by the public Ip,web server will be sent to the Nat gateway.

At this point, NAT Gateway translates the IP packet's destination IP into the IP of the host in the private network, and then forwards the IP packet (des=192.168.1.2,src=202.20.65.4) to the private network. The conversion process for this address is completely transparent to both sides of the communication. The conversion diagram is as follows.

If the request packet sent by the intranet host is not NAT, then when the Web server receives the request packet, the destination address in the response packet of the reply is the private network IP address and cannot be delivered correctly on the Internet, causing the connection to fail. 2.2 Connection Tracking

In the above process, when a response packet is received by the NAT Gateway, it is necessary to determine who forwarded the packet to. At this time, such as the fruit net only a small number of clients, can be manually specified with static NAT, but if the intranet has more than one client, and each visit to different sites, then the need for connection tracking (connection track). As shown in the following illustration:

After the Nat gateway receives the request packet from the client, it makes the source address translation and saves the connection record, when the Nat gateway receives the response packet from the server, finds the track Table, determines the forwarding target, makes the destination address translation, and forwards it to the client. 2.3-Port conversion

Taking the client Access server as an example, when only one client accesses the server, NAT gateway only needs to change the source IP or destination IP of the packet to communicate properly. However, if client A and client B are accessing the Web Server at the same time, when the Nat gateway receives the response packet, it cannot determine which client to forward the packet to, as shown in the following figure.


At this point, the NAT gateway will add port information to the connection track to differentiate it. If the two clients access the same server source port is different, then add the port information in the track table can be distinguished, if the source port is exactly the same, then the implementation of Snat and dnat the source port to do the corresponding conversion, as shown in the figure below.

3 Applications

NAT can implement several functions: Packet spoofing, load balancing, port forwarding, and transparent proxy.

Data Camouflage: The address information in the intranet packet can be changed into a unified external address information, not allow the intranet host directly exposed to the Internet, to ensure the security of the intranet host. At the same time, this feature is also commonly used to achieve shared Internet access. For example, when an intranet host accesses an extranet, the private address is replaced with a global address in order to hide the intranet topology.

Port forwarding: when the intranet host external service, because the use of the internal private IP address, the external network can not directly access. Therefore, port forwarding is required on the gateway to forward packets for a particular service to the intranet host. For example, the company's king set up a Web site on his server, his IP address is 192.168.0.5, using the default port 80, now he wants to let users outside the LAN can also directly access his web site. With Nat it is easy to solve this problem, the IP address of the server is 210.59.120.89, then assign a port to Xiao Wang, for example 81, all requests to access 210.59.120.89:81 automatically turn to 192.168.0.5 : 80, and the process is transparent to the user.

Load Balancing: Destination address translation NAT can redirect some servers to connect to other randomly selected servers. For example 1.2.3 for the purpose of the NAT example.

End of failure: Destination Address translation NAT can be used to provide high reliability services. If a system has a critical server accessed through a router, once the router detects the server, it can use the destination address to translate the NAT transparently to transfer the connection to a backup server to improve the system reliability.

Transparent proxy: For example, you set up a lack of server space, you need to point some links to the existence of another server space, or a computer does not have IIS services installed, but want to let users access to the content on the computer, This time using IIS Web site redirection can easily help us to take care of. 4 NAT Defects

NAT is perfect at the very beginning, but with the development of the network, a variety of new applications are emerging, Nat also exposes the shortcomings. The disadvantages of NAT are mainly manifested in the following aspects:

(1) Cannot process embedded IP address or port

The NAT device cannot translate the IP address or port information that is embedded in the Application Data section, it can only translate the address information that is normally located in the IP header and the port information in the TCP/UDP header, as shown in the following figure, because the other party uses the address and port embedded in the received packet to communicate. This can create a connection failure, if both sides are using the public IP, this will not cause any problems, but if the embedded address and port is the intranet, it is obvious that the connection is not possible to attack, the reason is the same as the opening said. Some features of MSN Messenger Use this method to pass IP and port information, which causes a connection failure for the client network application after the NAT device.

(2) Cannot access the Internal network service from the public network

Because the intranet is a private IP, it is not possible to access the internal network services directly from the public network, such as Web services, for this problem, we can use the establishment of static mapping method to solve. For example, there is a static mapping, 218.70.201.185:80 and 192.168.0.88:80 mapping, when the public network users to access the internal Web server, it is first connected to the 218.70.201.185 : 80, then the NAT device passes the request to the 192.168.0.88:80,192.168.0.88 to return the response to the NAT device, which is then transmitted by the NAT device to the public access user.

(3) Some applications, although the use of a port to send data, but the use of B port to receive, but the NAT device is not aware of this, it still establishes a map for a port, the result of the response of the other side of the data to the B port, the NAT device can not find the relevant mapping entries and discard the packet.
(4) Some peers cannot be used after NAT
For pure-to-peer applications that do not have intermediate servers (such as videoconferencing, entertainment, etc.), if everyone is behind a NAT device, the two sides cannot establish a connection. Because there is no intermediate server relay, the peer-to program behind the NAT device on the NAT device will not have a mapping bar, that is, the other side is unable to initiate a connection to you. There is now a technique called peer-to-peer NAT traversal to solve this problem. 5. Conclusion

NAT technology is undeniably a mitigating function in the absence of the IPv4 address resource, which brings a number of benefits in terms of reducing the cost of user requests for ISP services and providing a more complete load balancing function. But the IPv4 address will be depleted in the next few years, and NAT technology cannot change the nature of the lack of IP address space. However, there is also a potential threat to the security mechanism, which is also a challenge in configuration and management. If you want to fundamentally solve the problem of IP address resources, IPv6 is the most fundamental way. Nat technology is really a good choice in the IPv4 transition to IPv6, and it is also obvious relative to other scenarios.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.