What does it mean for naty. NAT - configure network address translation. Things to Consider

NAT, or Network Address Translation, is a way of reassigning one address space to another by changing the network address information in the Internet Protocol or IP. Packet headers change while they are in transit through routing devices. This method was originally used to more easily redirect traffic on IP networks without the need to number each host. It has become an important and popular tool for allocating and maintaining the global address space in the face of an acute shortage of IPv4 addresses.

What is NAT?

The use of network address translation is to map each address from one address space to an address that is in a different address space. This may be necessary in the event that the service provider has changed, and the user does not have the opportunity to publicly announce the new route to the network. In the face of global address space depletion, NAT technology has been increasingly used since the late 1990s. Typically this technology is used in conjunction with IP encryption. IP encryption is a method of converting multiple IP addresses into one space. This mechanism is implemented in a routing device that uses persistent translation tables to map hidden addresses to a single IP address. It also redirects all outgoing IP packets on the egress. Thus, these packets are displayed as leaving the routing device. Backlink responses are mapped to the original IP address using rules stored in translation tables. In turn, the translation tables are cleared after a short time if the traffic does not update its state. This is what the basic NAT mechanism is. What does this mean? This technology makes it possible to organize communication through a router only when the connection takes place in an encrypted network, as this creates translation tables. Inside such a network, a web browser can view a site outside of it, but being installed outside of it, it cannot open a resource that is hosted on it. Most NAT devices today allow the network administrator to configure translation table entries for permanent use. This feature is often referred to as port forwarding or static NAT. It enables traffic outbound to the "outside" network to reach designated hosts on the encrypted network. Because of the popularity of the technique used to preserve the IPv4 address space, the term NAT has practically become synonymous with encryption. Since network address translation changes the address information of IP packets, this can have serious consequences for the quality of the connection. So it requires close attention to all the implementation details. The ways NAT is used differ from each other in their specific behavior in different situations that relate to the impact on network traffic.

Basic NAT

The simplest type of NAT allows one-to-one translation of IP addresses. The main type of this broadcast is RFC-2663. In this case, only the IP addresses are changed, as well as the checksum of the IP headers. Basic translation types can be used to connect two IP networks that have incompatible addressing.

Most NAT flavors are capable of mapping multiple private hosts to a single publicly designated IP address. A LAN in a typical configuration uses one of the assigned "private" IP addresses for the subnet. On this network, the router has a private address in space. Also, the router connects to the Internet using a "public address" that is assigned by the Internet provider. Since traffic passes from the local Internet, the source address in each packet is translated from private to public on the fly. The router also keeps track of basic data about each active connection. In particular, this applies to information such as address and port of destination. When the answer is returned to him, he uses the connection data that is saved during the exit phase. This is necessary in order to determine the private address of the internal network to which the response should be directed. The main advantage of this functionality is that it is a practical solution to the problem of depleting the IPv4 address space. Even large networks can be connected to the Internet using a single IP address. All packet datagrams on IP networks have two IP addresses - the source address and the destination address. Packets traveling from the private network to the public network will have a packet source address that changes during the transition from the public to the private network. More complex configurations are also possible.

Features of NAT configuration

NAT configuration can be specific. Further modifications may be required to avoid the hassle of translating returned packages. Most of the internet traffic will go through UDP and TCP. Their numbers are changed so that IP addresses and port numbers are matched when data is sent back. Protocols that are not based on UDP or TCP require different translation methods. Typically, ICMP, or Internet Message Control Protocol, correlates the transmitted information with the existing connection. This means that they should be displayed using the same IP address and number that was originally set. What needs to be considered? Configuring NAT on the router does not provide end-to-end connectivity. For this reason, such routers cannot participate in some Internet protocols. Services requiring the initiation of TCP connections from the external network or non-protocol users may simply not be available. If the NAT router does not make much effort to support such protocols, then incoming packets may never reach their destination. Some protocols can be hosted in the same translation between the participating hosts, sometimes using an application layer gateway. However, the connection will not be established when both systems are separated from the Internet using NAT. Also, the use of NAT complicates tunneling protocols such as IPsec, as it changes the values ​​in the headers that interact with the integrity checks of requests.

NAT: an existing problem

The basic principle of the Internet is end-to-end connectivity. It has existed since its inception. The current state of the network only proves that NAT is a violation of this principle. In a professional environment, there are serious concerns about the widespread use of network address translation in IPv6. Thus, today the question is raised about how this problem can be eliminated. Because the translation-state tables in NAT routers are not inherently permanent, devices on the internal network lose IP connectivity within a very short time period. We must not forget about this circumstance when talking about what NAT is in a router. This significantly reduces the operating time of compact devices that run on rechargeable batteries and batteries.

Scalability

NAT also only monitors ports that can be quickly exhausted by internal applications that use multiple concurrent connections. These can be HTTP requests for pages with a large number of embedded objects. This problem can be mitigated by tracking the IP address in the destination in addition to the port. One local port can thus be shared by a large number of remote hosts.

NAT: some complications

Since all internal addresses are disguised as one public address, it is impossible for external hosts to initiate a connection to a specific internal host without setting up a special configuration on the firewall. This configuration should redirect connections to a specific port. IP telephony, video conferencing, and similar applications must use NAT traversal techniques to function properly. The Rapt translation port and return address allows a host whose IP address changes from time to time to remain available as a server using the fixed IP address of the home network. This should in principle allow the server setup to keep the connection. Although this solution is not ideal, it can be another useful tool in a network administrator's arsenal when solving problems associated with configuring NAT on a router.

PAT or Port Address Translation

Port Address Translation is a Cisco Rapt implementation that maps multiple private IP addresses to a single public one. Thus, multiple addresses can be mapped as an address because each is tracked using a port number. PAT uses unique internal global IP source port numbers to distinguish the direction of data transfer. These numbers are 16-bit integers. The total number of internal addresses that can be translated to one external address can theoretically reach 65536. In reality, the number of ports to which a single IP address can be assigned is approximately 4000. PAT, as a rule, tries to keep the original port of the "original" ... If it is already in use, Port Address Translation assigns the first available port number, starting at the beginning of the corresponding group. When there are no available ports and there is more than one external IP address, PAT moves to the next to allocate the source port. This process will continue until the available data runs out. Cisco Service displays address and port. It combines the translation port address and data for tunneling IPv4 packets over an internal IPv6 network. In fact, it is an alternative version of Carrier Grade NAT and DS-Lite, which supports IP translation of ports and addresses. This avoids the problems associated with establishing and maintaining a connection. It also provides a transition mechanism for IPv6 deployment.

Translation methods

There are several main ways to implement translation of a network address and port. Certain application protocols require you to determine the external NAT address used at the other end of the connection. It is also often necessary to study and classify the transmission type. Typically, this is done because it is desirable between two clients behind separate NATs to create a direct communication channel. For this purpose, a special protocol RFC 3489 was developed, which provides a simple UPD traversal through NATS. Today it is already considered outdated, since these days such methods are considered insufficient for a correct assessment of the operation of devices. In 2008, RFC 5389 was developed and new methods were standardized. This specification is called Session Traversal today. It is a dedicated utility for NAT.

Create two-way communication

Each UDP and TCP packet contains the source IP address and port number, as well as the destination port coordinates. The port number is very important for getting public services such as mail server functionality. So, for example, port 25 connects to the SMTP mail server and port 80 connects to the web server software. The IP address of the public server is also essential. These parameters must be reliably known to those nodes that intend to establish a connection. Private IP addresses are only relevant on local networks.

These are completely different technologies. Don't confuse them.

What is NAT

NAT is a collective term that refers to a technology for translating network addresses and / or protocols. NAT devices are performed on passing translation packets with the replacement of addresses, ports, protocols, etc.

There are narrower concepts of SNAT, DNAT, masquerading, PAT, NAT-PT, etc.

why NAT is needed, how is it used

To display the internal network on the Internet

  • through the pool of external addresses
  • through one external address

To replace an external ip address with another (traffic redirection)

For load balancing between identical servers with different ip addresses.

To combine two local area networks with overlapping internal addressing.

how NAT works

s + d NAT (branch merging - evil!)

port-mapping, port mapping

Advantages and disadvantages

Incompatible with some protocols. A specific NAT implementation must support the required protocol inspection.

NAT has the property of "shielding" the internal network from the outside world, but it cannot be used in place of a firewall.

Configuring on Cisco IOS

Cisco routers and firewalls support different types of NAT, depending on the set of software options. The most used method is NAT with binding internal local addresses to different ports of the same external address (PAT in Cisco terminology).

To configure NAT on a router, you need to: o Determine the traffic that needs to be translated (using access-lists or route-maps);

Ip access-list extended LOCAL permit ip 10.0.0.0 0.255.255.255 any

Route-map INT1 match ip address LOCAL match interface FastEthernet0 / 1.1

The LOCAL access list selects all traffic from network 10.

The INT1 route-map selects the LOCAL access-list traffic outgoing via the Fa 0 / 1.1 subinterface

o Determine to which external addresses to broadcast. Select a pool of external addresses. One address is enough for PAT.

Ip nat pool GLOBAL 212.192.64.74 212.192.64.74 netmask 255.255.255.0

Specifies a pool of external addresses named GLOBAL. There is only one address in the pool.

o Enable NAT for the selected internal and external addresses.

Ip nat inside source route-map INT1 pool GLOBAL overload

Enables NAT to translate source addresses on the inside interface. Only traffic that meets the conditions of the INT1 route map will be broadcast. The external address will be taken from the GLOBAL pool.

Ip nat inside source static tcp 10.0.0.1 23 212.192.64.74 23 extend

Static "port roll" or "service publication". In traffic going inward to the address 212.192.64.74 on the tcp port 23, the destination will be replaced with the address 10.0.0.1 and port 23.

o Assign internal and external interfaces.

Interface FastEthernet0 / 0 ip nat inside interface FastEthernet0 / 1.1 ip nat outside

Fa 0/0 is designated as internal for NAT.

Fa 0 / 1.1 subinterface is assigned external for NAT.

O Debugging and Diagnostics:

Sh ip nat translations - view the table of current translations; clear ip nat translations - delete all current translations; debug ip nat - enable debug messages (undebug all - disable debugging).

Examples of

Here are some demo examples for the cisco Packet Tracer emulator.

A simple scheme for bringing a small network to the Internet through a pool of external addresses

A simple scheme for bringing the network to the Internet through one external address

Interconnection scheme for networks with overlapping addressing

How NAT works

How NAT rules are applied differs from manufacturer to manufacturer and hardware to hardware. Here is the order of applying NAT policies for routers on cisco IOS:

Inside-to-Outside

If IPSec then check input access list decryption - for CET (Cisco Encryption Technology) or IPSec check input access list check input rate limits input accounting redirect to web cache policy routing routing NAT inside to outside (local to global translation) crypto (check map and mark for encryption) check output access list inspect (Context-based Access Control (CBAC)) TCP intercept encryption Queueing

Outside-to-Inside

If IPSec then check input access list decryption - for CET or IPSec check input access list check input rate limits input accounting redirect to web cache NAT outside to inside (global to local translation) policy routing routing crypto (check map and mark for encryption) check output access list inspect CBAC TCP intercept encryption Queueing

Internet channel from one provider through NAT

Simple single-provider NAT implementation

Internet channel reservation from two providers using NAT, ip sla

Given: we get Internet from ISP1 provider for several computers. They gave us the address 212.192.88.150. Internet access is organized from this ip address through NAT.

Task: connect a backup provider - ISP2. He will give us the address 212.192.90.150. Organize traffic balancing: let web traffic through ISP1, other traffic through ISP2. In case of failure of one of the providers, let all traffic go through a live channel.

What is the difficulty of the task? clear ip nat translations?

Scheme

Config

1 clear ip nat translations *

Found and tested such a piece of EEM. Not all versions of IOS generate an event .. It should be clarified.

! event manager applet NAT-TRACK event syslog pattern "TRACKING-5-STATE" action 0.1 cli command "enable" action 0.2 wait 3 action 0.3 cli command "clear ip nat translation *" action 0.4 syslog msg "NAT translation cleared after track state change "!

2 If the interface falls on the provider, chances are good that its gateway will ping through the second

! username NAME password 0 PASSWORD enable secret 0 CONFIG PASSWORD! ! control of login to the router line vty 0 4 login local! ! DHCP ip dhcp pool LAN network Intranet Mask default-router Gateway dns-server 10.11.12.13! DNS - bogus invented - NOT from our local network! ! ! Ping monitor to the gateway address of the provider-1! Wait 100 ms for a response! Ping with a frequency of 1 second ip sla monitor 1 type echo protocol ipIcmpEcho GatewayProv1 source-interface InterfaceOnProv1 timeout 100 frequency 1! ! Ping monitor for provider-2 ip sla monitor 2 type echo protocol ipIcmpEcho GatewayProv2 source-interface InterfaceNaProv2 timeout 50 frequency 1! ! Launching pingals 1 and 2, now and forever ip sla monitor schedule 1 life forever start-time now ip sla monitor schedule 2 life forever start-time now! ! Tracks 10 and 20 - tracking the status of pinging pins! Reacts to Down or Up condition with a 1 sec delay. track 10 rtr 1 reachability delay down 1 up 1! track 20 rtr 2 reachability delay down 1 up 1! ! ! Routes to all external networks on both providers! Routes are tied to tracks! and will be activated only if the track is in the Up! those. if the gateway to the corresponding provider is available ip route 0.0.0.0 0.0.0.0 GatewayPro1 track 10 ip route 0.0.0.0 0.0.0.0 GatewayPro2 track 20! ! ! int fa 0/0 no shut! ! Sub-interfaces towards external providers! marked as outside for NAT interface FastEthernet0 / 0.1 description ISP1 encaps dot1q NumberVlanProv1 ip address ipOnProv1 Mask ip nat outside! interface FastEthernet0 / 0.2 description ISP2 encapsulation dot1Q NumberVlanProv2 ip address ipNonProv2 Mask ip nat outside! ! Intranet interface! marked as inside for NAT! Binding routing policy PBR interface FastEthernet0 / 1 ip address ip ! Access lists from inside to outside! For web traffic and everything else ip access-list extended LOCAL permit ip intNetwork any! ip access-list extended WEB permit tcp intNetwork any eq www permit tcp intNetwork any eq 443! ip access-list extended ALL permit ip any any! ! ! tricky PBR root map! If the traffic from the LAN to the Web! then assign it the first provider as a gateway! Otherwise, other traffic from LAN! designate the second provider as the gateway. ! When assigning a gateway, route-map PBR Tracks are checked permit 10 match ip address WEB set ip next-hop verify-availability GatewayPro1 1 track 10! route-map PBR permit 20 match ip address ALL set ip next-hop verify-availability GatewayPro2 1 track 20! ! ! tricky ISP1 root map! triggered if traffic from LAN! tries to exit through interface Fa0 / 0.1 route-map ISP1 permit 10 match ip address LOCAL match interface FastEthernet0 / 0.1! ! tricky ISP2 root map! triggered if traffic from LAN! tries to exit through the Fa0 / 0.2 route-map ISP2 permit 10 match ip address LOCAL match interface FastEthernet0 / 0.2! ! ! Finally, NAT ;-)! ! Traffic from the LAN to the first provider Natit through the first interface ip nat inside source route-map ISP1 interface FastEthernet0 / 0.1 overload! ! Traffic from the LAN to the second provider Natit through the second interface ip nat inside source route-map ISP2 interface FastEthernet0 / 0.2 overload! ! Transfer traffic to fictitious DNS to Google-DNS ip nat outside source static 8.8.8.8 10.11.12.13 no-alias! ! forwarding internal port 3389 to external port 1111 ip nat inside source static tcp internal host 3389 external 1111 extendable ip nat inside source static tcp internal host 3389 external 1111 extendable! !

Miscellaneous

CGN (carrier grade nat) with a special pool of private addresses

NAT as ALG (application layer gateway), (plain text protocols e.g. SIP)

More and more different digital devices appear in our apartments - laptops, tablets and smartphones. While the computer in the apartment was alone and connected directly to the provider's network, there were no questions. And now, when you are faced with a problem - how to connect now a new laptop or tablet to the Internet. This is where it comes to the rescue NAT technology. What is the essence of NAT technology?
NATNetwork address translation - translated into Russian sounds something like this: "network address conversion". NAT is a mechanism in TCP / IP networks that translates the IP addresses of transit packets.
In simple terms, if there are several computers in the local network, then thanks to the technology NAT all of them can access the external Internet using one external ip address (IP).

What is an IP address?

Routerrouter- works at the third level of the OSI system, accordingly it is used IP protocol- a routed network layer protocol of the TCP / IP stack. An integral part of the protocol is network addressing. In accordance with the existing rules - all devices on the network are assigned IP addresses (IP addresses) - unique network identifiers of the node address. There are 2 types of IP addresses used - gray and white. Gray addresses- this is a part of the address space allocated for a local network - a subnet of IP addresses 10.0.0.0/8, 172.16.0.0/12 or 192.168.0.0/16 ... All other subnets are used on the Internet and are white IP addresses.

How to share the Internet with devices on the network.

In order to connect all devices in the local network to the Internet, you will need router. Router Is a device that can connect through the provider's network to the Internet and distribute it to connected devices due to the fact that it has at least 4 LAN ports and Wi-Fi module... Don't confuse a router with a simple Ethernet switch, which is essentially a dumb "splitter" of the network. Due to the fact that a UNIX-like operating system is installed on the router, various services can be raised on the device, including NAT service... To do this, when configuring the router, check the box Enable NAT .

So what is next router for each request that passes through it, it puts a certain label containing data about the sender in the local network. When this request is answered, router by label determines to which IP-address in the local network to send the packet. That's actually the whole How NAT works in a nutshell.

Network address translation (NAT) is a way of reassigning one address space to another by changing information. That is, packet headers change while they are in transit through a traffic routing device. This method was originally used to easily redirect traffic on IP networks without renumbering each host. It has become a popular and important tool for conserving and distributing global address space in the face of a scarcity of IPv4 addresses.

What is NAT?

The original use of network address translation is to map each address from one address space to a corresponding address in another space. For example, this is necessary if the ISP has changed and the user is unable to publicly announce the new route to the network. With the foreseeable global depletion of the IP address space, NAT has been increasingly used since the late 1990s in conjunction with IP encryption (which is a method of passing multiple IP addresses into one space). This mechanism is implemented in a routing engine that uses stateful translation tables to map "hidden" addresses to a single IP address, and redirects outgoing IP packets out. Thus, they appear to be leaving the routing device. In reverse, the responses are mapped to the original IP address using rules stored in translation tables. Translation table rules, in turn, are cleared after a short period if new traffic does not update its state. This is the basic NAT mechanism. What does this mean?

This method allows communication through the router only when the connection is on an encrypted network, as this creates translation tables. For example, a web browser inside such a network can view a site outside of it, but, being installed outside of it, it cannot open a resource hosted on it. However, most NAT devices today allow you to configure translation table entries for permanent use. This feature is often referred to as static NAT or port forwarding, and allows traffic outbound to the "outside" network to reach designated hosts on the encrypted network.

Due to the popularity of this method, used in order to preserve the IPv4 address space, the term NAT (this is what it actually is - stated above) has become almost synonymous with the encryption method.

Since network address translation changes the address information of IP packets, this has serious implications for the quality of the Internet connection and requires close attention to the details of its implementation.

The way NAT is applied differ from each other in their specific behavior in different cases regarding the impact on network traffic.

Basic NAT

The simplest type of Network Address Translation (NAT) provides one-to-one translation of IP addresses. RFC 2663 is the main type of this translation. In this type, only the IP addresses and the checksum of the IP headers are changed. Basic broadcast types can be used to connect two IP networks that have incompatible addressing.

What is NAT in a one-to-many connection?

Most NAT flavors are capable of mapping multiple private hosts to a single publicly designated IP address. In a typical configuration, the LAN uses one of the assigned "private" IP addresses for the subnet (RFC 1918). A router on this network has a private address in this space.

The router also connects to the Internet using the "public" address assigned by the ISP. Since traffic passes from the local network of the source, each packet is transferred on the fly from a private address to a public one. The router keeps track of basic data about each active connection (in particular, the address and destination port). When the response is returned to it, it uses the connection data that is stored during the outbound phase to determine the private address on the internal network to which the response should be routed.

One of the benefits of this functionality is that it serves as a practical solution to the impending depletion of the IPv4 address space. Even large networks can be connected to the Internet using a single IP address.

All packet datagrams on IP networks have 2 IP addresses - source and destination. Typically, packets traveling from the private network to the public network will have the packet source address changing during the transition from the public network back to the private one. More complex configurations are also possible.

Peculiarities

NAT configuration can have some peculiarities. Further modifications are required to avoid difficulties in how to translate the returned packages. The vast majority of Internet traffic goes through the TCP and UDP protocols, and their port numbers change in such a way that the combination of IP address and port number in the reverse direction of data begins to match.

Non-TCP and UDP protocols require different translation methods. The Message Control Protocol (ICMP) typically associates the data being transferred with an existing connection. This means that they must be displayed using the same IP address and number as originally set.

What should be considered?

Configuring NAT on the router does not give it end-to-end connectivity. Therefore, such routers cannot participate in some Internet protocols. Services that require initiation of TCP connections from the external network or users without protocols may not be available. Unless the NAT router makes special efforts to support such protocols, incoming packets cannot reach their destination. Some protocols can reside in the same translation between participating hosts (FTP "passive mode", for example), sometimes using an application layer gateway, but the connection will not be established when both systems are separated from the Internet using NAT. The use of network address translation also complicates tunneling protocols such as IPsec because it modifies the values ​​in the headers that interact with the integrity checks of requests.

The existing problem

End-to-end connectivity has been a fundamental tenet of the Internet since its inception. The current state of the network shows that NAT is in violation of this principle. There is a serious concern among experts in connection with the widespread use of IPv6 network address translation, and a problem is raised about how to effectively eliminate it.

Due to the short-lived nature of translation-state tables in NAT routers, devices on the internal network lose IP connectivity, typically within a very short period of time. Speaking about what NAT is in a router, we must not forget about this circumstance. This dramatically reduces the operating time of compact battery and rechargeable devices.

Scalability

In addition, NAT only monitors ports that can be quickly exhausted by internal applications using multiple concurrent connections (for example, HTTP requests for web pages with a lot of embedded objects). This problem can be mitigated by tracking the destination IP in addition to the port (thus, one local port is shared by many remote hosts).

Some difficulties

Since all internal addresses are masqueraded as one public address, it becomes impossible for external hosts to initiate a connection to a specific internal host without special configuration on the firewall (which should redirect connections to a specific port). Applications such as IP telephony, video conferencing, and similar services must use NAT traversal techniques to function properly.

The return address and translation port (Rapt) allows a host, whose real IP address changes from time to time, to remain reachable as a server using the fixed IP address of the home network. Basically, this should allow the server setup to keep the connection. Although this is not a perfect solution to the problem, it can be another useful tool in the arsenal of a network administrator when solving the problem of how to configure NAT on a router.

Port Address Translation (PAT)

The Cisco Rapt implementation is Port Address Translation (PAT), which maps multiple private IP addresses to a single public one. Multiple addresses can be displayed as an address because each is tracked using a port number. PAT uses unique internal global IP source port numbers to distinguish the direction of data transfer. These numbers are 16-bit integers. The total number of internal addresses that can be transferred to one external address can theoretically reach 65536. The actual number of ports to which a single IP address can be assigned is about 4000. As a rule, PAT tries to keep the original port of the "original". If it is already in use, Port Address Translation assigns the first available port number from the beginning of the corresponding group - 0-511, 512-1023, or 1024-65535. When there are no more ports available and there is more than one external IP address, PAT moves to the next one to try to allocate the source port. This process continues until the available data runs out.

Address and port mapping is handled by Cisco, which combines the translation port address with the tunneling data for IPv4 packets over the internal IPv6 network. Basically, it is an unofficial alternative to CarrierGrade NAT and DS-Lite that supports IP address / port translation (and hence NAT customization is supported). Thus, it avoids connection setup and maintenance issues and provides a transition mechanism for IPv6 deployment.

Translation methods

There are several ways to implement translation of network address and port. In some application protocols that use IP addressing applications running over an encrypted network, it is necessary to determine the external NAT address (which is used at the other end of the connection), and, in addition, it is often necessary to study and classify the type of transmission. This is usually done because it is desirable to create a direct communication channel (either to keep data flowing smoothly through the server, or to improve performance) between two clients, both of which are behind separate NATs.

For this purpose (how to configure NAT), a special protocol RFC 3489 was developed in 2003 to provide simple UDP traversal through NATS. Today, it is outdated, since such methods today are insufficient for correctly assessing the operation of many devices. The new methods were standardized in RFC 5389, which was developed in October 2008. This specification is today called SessionTraversal and is a utility for NAT.

Create two-way communication

Each TCP and UDP packet contains the source IP address and port number, as well as the coordinates of the destination port.

For public services such as mail server functionality, the port number is essential. For example connects to web server software and 25 connects to mail server SMTP. The IP address of a public server is also essential, like a postal address or a telephone number. Both of these parameters must be reliably known to all nodes that intend to establish a connection.

Private IP addresses only matter on the local area networks where they are used, as well as for host ports. Ports are unique communication endpoints on a host, so NAT traversal is supported using a combined port and IP address mapping.

PAT (Port Address Translation) resolves conflicts that can arise between two different hosts using the same source port number to establish unique connections at the same time.

2 32 or 4 294 967 296 IPv4 is it a lot of addresses? It seems that yes. However, with the proliferation of personal computing, mobile devices, and the rapid growth of the Internet, it soon became apparent that 4.3 billion IPv4 addresses would not be enough. The long term solution was IPv6 but a faster solution was needed to address the shortage of addresses. And this decision was NAT (Network Address Translation).

What is NAT

Networks are usually designed using private IP addresses. These are addresses 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16 ... These private addresses are used internally by an organization or site to allow devices to communicate locally and are not routed across the Internet. To allow a device with a private IPv4 address to access devices and resources outside of the local network, the private address must first be translated to a public public address.

And just NAT translates private addresses into public ones. This allows a device with a private IPv4 address to access resources outside of its private network. NAT, combined with private IPv4 addresses, has proven to be a useful method of keeping IPv4 addresses publicly available. A single public IPv4 address can be used by hundreds, even thousands, of devices, each with a private IPv4 address. NAT has the added benefit of adding a degree of privacy and security to the network because it hides internal IPv4 addresses from external networks.

NAT-enabled routers can be configured with one or more valid public IPv4 addresses. These public addresses are called the NAT pool. When a device on the internal network sends traffic from the network to the outside, a NAT-enabled router translates the internal IPv4 address of the device to a public address from the NAT pool. To external devices, all traffic entering and leaving the network appears to have a public IPv4 address.

NAT router usually runs at the border Stub-network. A stub network is a stub network that has one connection to a neighboring network, one entry and exit from the network.

When a device inside a Stub network wants to communicate with a device outside of its own network, the packet is forwarded to the border router, and it performs the NAT process, translating the internal private address of the device into a public, external, routable address.

NAT terminology

In NAT terminology, an internal network is a collection of networks to be translated. Outside network refers to all other networks.

When using NAT, IPv4 addresses have different designations based on whether they are on a private network or on a public network (the Internet), and whether the traffic is inbound or outbound.

NAT includes four types of addresses:

  • Inside local address;
  • Inside global address;
  • Outside local address;
  • Outside global address;

When determining which type of address to use, it is important to remember that NAT terminology is always applied from the perspective of a translated address device:

  • Inside address- the address of the device that is translated by NAT;
  • Outside address- address of the destination device;
  • Local address- this is any address that appears on the inside of the network;
  • Global address- this is any address that is displayed on the outside of the network;

Let's consider this using an example of a circuit.


In the figure, the PC has an internal local ( Inside local) address 192.168.1.5 and from his point of view the web server has an external ( outside) address 208.141.17.4. When packets are sent from the PC to the global address of the web server, the internal local ( Inside local) the PC address is translated to 208.141.16.5 ( inside global). The external device address is usually not translated because it is a public IPv4 address.

It is worth noting that the PC has different local and global addresses, while the web server has the same public IP address. From his point of view, the traffic outgoing from the PC comes from the internal global address 208.141.16.5. A NAT router is a demarcation point between the internal and external networks and between local and global addresses.

Terms inside and outside, combined with the terms local and global to link to specific addresses. In the figure, the router is configured to provide NAT and has a pool of public addresses to assign to internal hosts.

The figure shows how traffic is sent from an internal PC to an external web server, through a NAT-enabled router, and sent and translated in the opposite direction.


Internal local address ( Inside local address) is the source address visible from the internal network. In the figure, the address 192.168.1.5 is assigned to the PC - this is its internal local address.

Inside global address ( Inside global address) is the source address visible from the external network. In the figure, when traffic from the PC is sent to the web server at 208.141.17.4, the router translates the inside local address ( Inside local address) to the internal global address ( Inside global address). In this case, the router changes the IPv4 source address from 192.168.1.5 to 208.141.16.5.

Outside global address ( Outside global address) is the destination address visible from the external network. This is a globally routable IPv4 address assigned to a host on the Internet. In the diagram, the web server is available at 208.141.17.4. Most often, the external local and external global addresses are the same.

External local address ( Outside local address) is the recipient's address visible from the internal network. In this example, the PC is sending traffic to the web server at 208.141.17.4

Consider the entire path of the packet. The PC with the address 192.168.1.5 is trying to communicate with the web server 208.141.17.4. When a packet arrives at a NAT-enabled router, it reads the packet's destination IPv4 address to determine if the packet meets the criteria for translation. In this example, the source address meets the criteria and translates from 192.168.1.5 ( Inside local address) at 208.141.16.5. ( Inside global address). The router adds this local-to-global mapping to the NAT table and sends the packet with the translated source address to the destination. The web server responds with a packet addressed to the PC's internal global address (208.141.16.5). The router receives a packet with a destination address of 208.141.16.5 and checks the NAT table in which it finds an entry for this mapping. It uses this information and translates back the inside global address (208.141.16.5) to the inside local address (192.168.1.5), and the packet is forwarded towards the PC.

NAT types

There are three types of NAT translation:

  • Static Address Translation (Static NAT)- one-to-one address mapping between local and global addresses;
  • Dynamic Address Translation (Dynamic NAT)- Many-to-many address mapping between local and global addresses;
  • Port Address Translation (NAT)- multicast address mapping between local and global addresses using ports. This method is also known as NAT Overload;

Static NAT uses one-to-one mapping between local and global addresses. These mappings are configured by the network administrator and remain permanent. When devices send traffic to the Internet, their internal local addresses are translated into configured internal global addresses. For external networks, these devices have public IPv4 addresses. Static NAT is especially useful for web servers or devices that need to have a consistent address that is accessible from the Internet, such as a company web server. Static NAT requires a sufficient number of public addresses to satisfy the total number of concurrent user sessions.

A static NAT table looks like this:


Dynamic NAT uses a pool of public addresses and assigns them on a first come, first served basis. When the inside device requests access to the outside network, dynamic NAT assigns an available public IPv4 address from the pool. Like static NAT, dynamic NAT requires a sufficient number of public addresses to satisfy the total number of concurrent user sessions.

A dynamic NAT table looks like this:


Port Address Translation (PAT)

PAT translates multiple private addresses to one or more public addresses. This is what most home routers do. The ISP assigns one address to the router, but multiple family members can access the Internet at the same time. This is the most common form of NAT.

With PAT, multiple addresses can be mapped to one or more addresses, since each private address is also tracked by a port number. When a device initiates a session TCP / IP, it generates the value of the source port TCP or UDP to uniquely identify the session. When a NAT router receives a packet from a client, it uses its source port number to uniquely identify a specific NAT translation. PAT ensures that devices use a different TCP port number for each session. When a response is returned from the server, the source port number, which becomes the destination port number on the return path, determines which device the router is forwarding packets to.

The picture illustrates the PAT process. PAT adds unique source port numbers to the inside global address to distinguish translations.


Since the router processes every packet, it uses the port number (1331 and 1555, in this example) to identify the device from which the packet was sent.

Source address ( Source Address) is the inside local address appended with a port number assigned by TCP / IP. Destination address ( Destination Address) is the external local address with the added service port number. In this example, the service port is 80: HTTP.

For the source address, the router translates the inside local address to the inside global address with the appended port number. The destination address does not change, but it is now referred to as the outside global IP address. When the web server responds, the path is reversed.

In this example, client port numbers 1331 and 1555 did not change on the NAT router. This is not a very likely scenario because there is a good chance that these port numbers have already been assigned to other active sessions. PAT tries to keep the original source port. However, if the source port of the source is already in use, PAT assigns the first available port number, starting at the beginning of the corresponding port group. 0-511, 512-1023 or 1024-65535 ... When there are no more ports and there is more than one external address in the address pool, PAT goes to the next address to try to allocate the original source port. This process continues until there are no available ports or external IP addresses.

That is, if another host can choose the same port number 1444. This is acceptable for an internal address because hosts have unique private IP addresses. However, on the NAT router, the port numbers must be changed - otherwise, packets from two different hosts will exit with the same source address. Therefore, PAT assigns the next available port (1445) to the second host address.

Let's summarize the comparison between NAT and PAT. As you can see from the tables, NAT translates IPv4 addresses on a 1: 1 basis between private IPv4 addresses and public IPv4 addresses. However, PAT changes both the address itself and the port number. NAT redirects incoming packets to their internal address based on the incoming source IP address specified by the host on the public network, and with PAT there is usually only one or very few publicly exposed IPv4 addresses, and incoming packets are redirected based on the NAT table of the router.

What about IPv4 packets containing data other than TCP or UDP? These packets do not contain a Layer 4 port number. PAT translates the most common protocols carried by IPv4, which do not use TCP or UDP as the transport layer protocol. The most common of these are ICMPv4. Each of these types of protocols is handled differently by PAT. For example, ICMPv4 Request Messages, Echo Requests, and Responses include the Request ID Query ID... ICMPv4 uses Query ID. to identify the echo request with the corresponding response. The request ID is incremented with each echo request sent. PAT uses the request id instead of the layer 4 port number.

Advantages and Disadvantages of NAT

NAT provides many benefits, including:

  • NAT preserves the registered addressing scheme, allowing the privatization of intranets. With PAT, internal hosts can share a single public IPv4 address for all external communications. This type of configuration requires very few external addresses to support many internal hosts;
  • NAT increases the flexibility of connections to the public network. Multiple pools, backup pools, and load balancing pools can be implemented to provide reliable public network connections;
  • NAT provides consistency for internal network addressing schemes. On a network that does not use private IPv4 addresses and NAT, changing the general IPv4 address scheme requires that all hosts on the existing network be redirected. Host forwarding costs can be significant. NAT allows the existing private IPv4 addressing scheme to remain, making it easy to modify the new public addressing scheme. This means that the organization can change providers and does not need to change any of its internal customers;

  • NAT provides network security. Because private networks do not advertise their addresses or internal topology, they remain robust enough when used in conjunction with NAT to gain controlled external access. However, you need to understand that NAT does not replace firewalls;

But NAT has some drawbacks. The fact that hosts on the Internet seem to communicate directly with a NAT-enabled device rather than the actual host within the private network creates a number of problems:

  • One of the disadvantages of using NAT has to do with network performance, especially for real-time protocols such as VoIP... NAT increases switch delays because it takes time to translate each IPv4 address in packet headers;
  • Another disadvantage of using NAT is that end-to-end addressing is lost. Many Internet protocols and applications depend on end-to-end addressing from source to destination. Some applications do not work with NAT. Applications that use physical addresses rather than a qualified domain name do not reach destinations that are translated through a NAT router. Sometimes this problem can be avoided by implementing static NAT mappings;
  • IPv4 end-to-end tracing is also lost. It is more difficult to trace packets that undergo multiple packet address changes over multiple NAT hops, making troubleshooting more difficult;
  • The use of NAT also makes it difficult for tunneling protocols such as IPsec because NAT changes the values ​​in the headers that interfere with the integrity checks performed by IPsec and other tunneling protocols;
  • Services requiring the initiation of TCP connections from the external network, or stateless protocols such as those using UDP, may be disrupted. If the NAT router is not configured to support these protocols, incoming packets cannot reach their destination;

Was this article helpful to you?

Please tell me why?

We are sorry that the article was not useful to you: (Please, if it does not make it difficult, indicate why? We will be very grateful for a detailed answer. Thank you for helping us become better!

Service