Nat modem. How NAT works

In our apartments there are more and more different digital devices- laptops, tablets and smartphones. As long as there was only one computer in the apartment and connected directly to the provider’s network, there were no questions. And now that you are faced with a problem - how to connect now 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 it sounds something like this: “transformation network addresses». NAT is a mechanism in TCP/IP networks that allows you to convert the IP addresses of transit packets.
To put it simply in simple language- then if there are several computers in local network, then thanks to technology NAT all of them can access the external Internet network using one external ip address (IP).

What is an IP address?

Routerrouter— operates at the third level of the OSI system, accordingly it is used IP protocol— routed network layer protocol of the TCP/IP stack. An integral part of the protocol is network addressing. In accordance with 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 part of the address space allocated for the local network - subnets 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 Internet access with devices on your network.

In order to connect all devices on the local network to the Internet you will need router. Router is a device that can connect to the Internet through the provider’s network and distribute it to connected devices due to the fact that it has at least 4 LAN ports and Wi-Fi module . Do not confuse a router with a simple Ethernet switch, which is essentially a stupid network “splitter.” Due to the fact that the router has a UNIX-like operating system installed, the device can raise various services, including NAT service. To do this, when setting up the router, check the box Enable NAT .

And then router For each request that passes through it, it puts a specific label containing data about the sender on the local network. When this request receives a response, router The label determines which IP address on the local network to send the packet to. That's all how NAT technology works in a nutshell.

NAT or Network Address Translation is a method of reassigning one address space to another by changing the network address information in Internet Protocol or IP. Packets' 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 preserving global address space in the face of a severe shortage of IPv4 addresses.

What is NAT?

The use of network address translation is to map each address in one address space to an address that is in another address space. This may be necessary if the service provider has changed, and the user does not have the ability to publicly advertise a new route to the network. NAT technology has been used increasingly since the late 90s in the context of global depletion of address space. Typically this technology is used in combination with IP encryption. IP encryption is a method of moving multiple IP addresses into one space. This mechanism implemented in a routing device that uses stateful translation tables to map hidden addresses into a single IP address. It also forwards all outgoing IP packets at the output. Thus, these packets appear to be leaving the routing device. Responses on the return link are mapped to the source 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 the basic mechanism of NAT. What does this mean? This technology allows communication through a router only when the connection occurs on an encrypted network, as this creates translation tables. Inside such a network, a web browser can view a site outside of it, but when installed outside it, it cannot open the resource that is located within it. Most NAT devices today allow the network administrator to configure translation table entries for permanent use. This function especially often referred to as port forwarding or static NAT. It allows traffic originating on the “external” network to reach designated hosts on the encrypted network. Due to the popularity of the method used to preserve the IPv4 address space, the term NAT has practically become synonymous with the encryption method. Because 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 implementation details. The ways in which NAT is used differ from each other in their specific behavior in different situations, which relate to the impact on network traffic.

Basic NAT

The simplest type of NAT allows for one-to-one translation of IP addresses. The main type of this translation is RFC-2663. In this case, only the IP addresses change, as well as checksum IP headers. You can use basic translation types to connect two IP networks that have incompatible addressing.

Most NAT flavors are capable of mapping multiple private hosts to a single IP address, which is publicly designated. A LAN in a typical configuration uses one of the subnet's assigned "private" IP addresses. In this network, the router has a private address in space. The router also connects to the Internet using a “public address”, which is assigned by the Internet provider. Since the traffic originates from the local Internet, the source address in each packet is translated from private to public on the fly. The router also tracks basic data about each active connection. In particular, this applies to information such as destination address and port. When the response returns to it, it uses the connection data that is stored during the outbound phase. This is necessary in order to determine the private internal network address to which the response should be directed. The main advantage of this functionality is that it is a practical solution to the problem of IPv4 address space exhaustion. With a single IP address, even large networks can be connected to the Internet. All datagram packets in IP networks have two IP addresses - the source address and the destination address. Packets passing from private network to network public use, will have a packet source address that changes during the transition from public network to private. More complex configurations are also possible.

Features of NAT configuration

NAT setup may have certain characteristics. To avoid difficulties associated with translating returned packages, further modifications may be required. Most Internet traffic will go through the UDP and TCP protocols. Their numbers are changed in such a way that the IP addresses and port numbers begin to be compared when sending data back. Protocols that are not based on UDP or TCP require other translation methods. Typically, ICMP, or Internet Control Message Protocol, matches the information being sent to the existing connection. This means that they must be displayed using the same IP address and number that was originally set. What needs to be taken into account? Configuring NAT on a router does not provide it with end-to-end connectivity. For this reason, such routers cannot participate in some Internet protocols. Services that require initiation of TCP connections from the external network or users without protocols may simply not be available. If the NAT router does not make special efforts to support such protocols, then incoming packets may never reach their destination. Some protocols can be hosted in a single broadcast between participating hosts, sometimes using an application layer gateway. However, the connection will not be established when both systems are separated from the Internet by NAT. Also, the use of NAT complicates tunnel protocols such as IPsec because it changes the values ​​in headers that interact with request integrity checks.

NAT: an existing problem

The basic principle of the Internet is end-to-end connection. It has existed since its development. The current state of the network only proves that NAT is a violation this principle. There is serious concern in the professional community regarding 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 inherently impermanent, internal network devices lose IP connectivity within a very short period of time. We must not forget about this circumstance when talking about what NAT is in a router. This significantly reduces operating time compact devices, which operate on batteries and rechargeable batteries.

Scalability

When using NAT, only those ports that can be quickly depleted are monitored internal applications, which use multiple simultaneous connections. It could be HTTP requests for pages with a large number of embedded objects. soften this problem possible by tracking the IP address in the destinations in addition to the port. One local port can thus be shared by a large number of remote hosts.

NAT: some difficulties

Because all internal addresses are masqueraded as a single 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 forward connections to a specific port. Applications for IP telephony, video conferencing and similar services must use NAT traversal methods to function properly. The Rapt translation port and the return address allows a host whose IP address changes from time to time to remain available as a server using a fixed IP address home network. This should in principle allow the servers setup to remain connected. Although this solution to the problem is not ideal, it may be another useful tool in the arsenal of a network administrator when solving problems related to configuring NAT on a router.

PAT or Port Address Translation

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

Translation methods

There are several basic ways to implement network address and port translation. 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 examine and classify the type of transmission. As a rule, this is done because it is desirable to create a direct communication channel between two clients located behind separate NATs. A special protocol, RFC 3489, was developed for this purpose, which provides simple UPD bypass over NATS. Today it is already considered obsolete, since these days such methods are considered insufficient for correctly assessing the operation of devices. In 2008, RFC 5389 was developed, which standardized new methods. This specification is today called Session Traversal. She represents special utility, designed for NAT operation.

Creating two-way communication

Each UDP and TCP packet contains the source IP address and its port number, as well as the coordinates of the destination port. The port number is very important for receiving public services such as mail server functionality. So, for example, port 25 connects to SMTP mail server, and port 80 connects to software web server. 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.

Network Address Translation (NAT) is used by many service providers and private users to solve the problem of the lack of real IP addresses and ensure the security of local networks connected to the Internet. For example. An enterprise may have a dedicated range of real IP addresses, but much more more computers with local IP addresses that need Internet access. To solve this problem, address translation technology is used, which allows computers on a local network to interact with the Internet using just one external real IP address. NAT solves this problem by replacing the local IP address with an external public address. By replacing the internal IP address and port with the external IP address and port, NAT maintains a mapping table, then converts it back when a response packet is received.
Local IP addresses include the following address ranges: 10.xxx.xxx.xxx, 192.168.xxx.xxx, 172.16.xxx.xxx - 172.32.xxx.xxx.


Types of Network Address Translators (NAT)

Address translators are divided into 4 types:
1. Full Cone
2. Restricted Cone
3. Port Restricted Cone
4. Symmetric

In the first three types of NAT, different IP addresses of the external network can interact with an address from the local network using the same external port. The fourth type uses a separate external port for each address and port.
NATs do not have a static table of addresses and ports. The display opens when the first packet is sent from the local network to the outside through NAT and is valid for a certain period of time (usually 1-3 minutes); if packets do not pass through this port, then the port is removed from the lookup table. Typically NAT allocates external ports dynamically, using a range above 1024.

Full Cone

When using full cone NAT, the external mapped port is open to packets coming from any address. If someone from the external Internet wants to send a packet to a client located behind NAT at this moment, then he only needs to know the external port through which the connection is established. For example, a computer behind a NAT with an IP address of 10.0.0.1 sends and receives packets on port 8000, mapped to the external IP address and port 212.23.21.25:12345, then anyone on the Internet can send packets to that 212.23.21.25:12345, and these packets will reach client computer 10.0.0.1:8000.


Restricted Cone

NAT, with a limited cone, opens an external port immediately after local computer will send data to a specific external IP address. For example, if a client sends a packet outside external computer 1, NAT maps client 10.0.0.1:8000 to 212.23.21.25:12345, and external computer 1 can send packets back to this destination. However, NAT will block packets coming from computer 2 until the client sends a packet to that computer's IP address. When it does this, both external computers 1 and 2 will be able to send packets back to the client, and both will have the same mapping across the NAT.

Port Restricted Cone

NAT with a limited cone port is almost identical to NAT with a limited cone port. Only in this case, NAT blocks all packets unless the client has previously sent a packet outside to the IP address and port of the computer that is sending packets to the client. Therefore, if a client sends an external computer 1 on port 5060, then NAT will only allow the packet to reach the client when it comes from 212.33.35.80:5060. If a client sent packets outward to multiple IP addresses and ports, then they may respond to the client on the same mapped IP address and port.

Symmetric

Symmetric NAT is fundamentally different from the first three in the way it maps an internal IP address and port to an external address and port. This mapping depends on the IP address and port of the computer to which the sent packet is destined. For example, if a client sends from the address 10.0.0.1:8000 to computer 1, then it can be displayed as 212.23.21.25:12345, at the same time, if it sends from the same port (10.0.0.1:8000) to another IP address, it is displayed differently (212.23.21.25:12346).


Computer 1 can only reply to 212.23.21.25:12345, and Computer 2 can only reply to 212.23.21.25:12346. If any of them tries to send packets to a port from which it did not receive packets, then those packets will be ignored. The external IP address and port are opened only when the internal computer sends data outside to a specific address.

NAT and Internet telephony using the SIP protocol

There are three main problems with passing calls through NAT using the SIP protocol.
1. Availability of local addresses in SIP signaling.

What is NAT

Your computer can be connected to the Internet directly. Then they say that he has external IP address.

This usually means that the computer is connected directly to a modem (DSL, cable or regular analog).

Behind NAT means that your computer is not connected to the Internet, but to a local network. Then he has interior An IP address that is itself inaccessible from the Internet.

Your computer accesses the Internet through NAT - the process of translating internal addresses to external ones and vice versa. A NAT device is usually called a router.

The specificity of NAT is that connections initiated by your computer transparently pass through the NAT device to the Internet. However, connections that other computers from the Internet would like to establish with you cannot reach you.

Finding the computer's IP address

Run">Open a dialog box to run programs: click on the Start button, select Run from the menu.

In Windows 2000/XP, type the command cmd /k ipconfig, click OK and look at the result.

Windows 2000 IP Configuration Ethernet adapter Local Area Connection: Connection-specific DNS Suffix . : IP Address. . . . . . . . . . . . : 192.168.1.10 Subnet Mask. . . . . . . . . . . : 255.255.255.0 Default Gateway. . . . . . . . . : 192.168.1.1

The first of these addresses is the IP address of your computer.

Are you behind NAT?

Three special range IP addresses are reserved for local networks and are not used on the Internet:

10. 0. 0. 0 - 10. 255.255.255 172. 16. 0. 0 - 172. 31.255.255 192.168. 0. 0 - 192.168.255.255

If your computer's IP address is in one of these ranges, that is, it starts with 10. or with 192.168. or from 172.nn. (where nn is from 16 to 31), then this is a local (internal) address, and you are definitely behind NAT.

If not, now check what IP address other computers on the Internet see you under. For example, on whatsmyip.org (“Your IP Address is x.x.x.x” at the top of the page) or on myipaddress.com.

If your computer's IP address matches one of these sites shown, then you are definitely connected to the Internet directly.

In other cases it is impossible to say for sure. The following options are possible:

  • You are behind NAT, but your network administrator has chosen non-standard internal addresses for your local network. Find him and ask why he had to do this.
  • you access the Internet through a proxy server (then whatsmyip.org showed you the address of this proxy server). In many cases, you can determine whether there is a proxy server between you and the Internet, using for example lagado.com/proxy-test.

    Connecting via a proxy is not covered in this guide..

Connection options via NAT

If you are behind NAT, then the next step is to determine where exactly the NAT device is located.

NAT provider

    Then they say that
  • the provider provides you with the Internet via NAT,
  • or that the provider does not give you an external IP address,
  • or that you are connected via the provider's local network

The easiest way is to call your provider and find out. Or ask knowledgeable neighbors with the same connection.

When connecting to the Internet through the provider’s local network, you cannot make an accessible port for yourself. Unless, of course, your provider redirects a specific port specifically for you, which is unlikely. Or unless you pay extra for a service that is usually called an "external" ("white") IP address.

NAT in an office or apartment building

In principle, the situation is the same, but you can look for approaches to the local admin. Ultimately, deciding whether a port is available depends on whether you have access to the router settings.

In addition, you can also try UPnP, in case your router left it enabled.

NAT is your own

In this case, you can almost always configure it and get an available port.

Usually this is either a connection through a home router or a connection through another computer, for example using ICS (the second option is not considered here).

Of course, in principle, it also happens that you have NAT both at home and at your provider, that is, your computer is behind two NATs at once. This can be checked by going to the router settings, looking at its external address and then following the above scenario (whether it belongs to this address of local network ranges, does it match the address under which you are seen on the Internet).

Internet router, access server, firewall. The most popular is Source NAT(SNAT), the essence of the mechanism is to replace the source address when a packet passes in one direction and reversely replace the destination address in the response packet. Along with the source/destination addresses, the source and destination port numbers can also be replaced.

Besides SNAT, i.e. providing users of a local network with internal addresses with access to the Internet, is often also used Destination NAT, when requests from outside are translated by the firewall to a server on the local network that has an internal address and therefore is not directly accessible from the external network (without NAT).

The figures below show an example of the operation of the NAT mechanism.


Rice. 7.1.

User corporate network sends a request to the Internet, which arrives at the internal interface of the router, access server, or firewall (NAT device).

The NAT device receives the packet and makes an entry in the connection tracking table, which controls address translation.

It then replaces the source address of the packet with its own external public IP address and sends the packet to its destination on the Internet.

The destination host receives the packet and sends a response back to the NAT device.

The NAT device, in turn, having received this packet, looks up the sender of the original packet in the connection tracking table, replaces IP address destination to the corresponding private IP address and forwards the packet to source computer. Because the NAT device sends packets on behalf of everyone internal computers, it changes the original network port And this information stored in the connection tracking table.

There are 3 basic concepts for address translation:

  • static (SAT, Static Network Address Translation),
  • dynamic (DAT, Dynamic Address Translation),
  • masquerade (NAPT, NAT Overload, PAT).

Static NAT maps local IP addresses to specific public addresses on a one-to-one basis. Used when the local host must be accessible from outside using fixed addresses.

Dynamic NAT maps a set of private addresses to a set of public IP addresses. If the number of local hosts does not exceed the number of public addresses available, each local address will be guaranteed to correspond to a public address. Otherwise, the number of hosts that can simultaneously access external networks will be limited by the number of public addresses.

Masquerade NAT(NAPT, NAT Overload, PAT, masquerading) is a form of dynamic NAT that maps multiple private addresses to a single public IP address using different ports. Also known as PAT (Port Address Translation).

Mechanisms for interaction between the internal local network and the external one public network there may be several - it depends on the specific task of providing access to the external network and back and is prescribed by certain rules. There are 4 types of network address translation defined:

  • Full Cone
  • Restricted Cone
  • Port Restricted Cone
  • Symmetric

In the first three types of NAT for interaction different IP addresses external network with addresses from the local network use the same external port. The fourth type - symmetrical - uses a separate external port for each address and port.

Full Cone, the external port of the device (router, access server, firewall) is open to requests coming from any address. If a user from the Internet needs to send a packet to a client located behind a NAT, then he only needs to know the external port of the device through which the connection is established. For example, a computer behind NAT with an IP address of 192.168.0.4 sends and receives packets on port 8000, which map to the external IP address and port as 10.1.1.1:12345. Packets from the external network arrive at the device with IP address: port 10.1.1.1:12345 and are then sent to the client computer 192.168.0.4:8000.

In incoming packets, only the transport protocol is checked; The destination address and port, the source address and port do not matter.

When using NAT, working by type Restricted Cone, the external port of the device (router, access server, firewall) is open to any packet sent from the client computer, in our example: 192.168.0.4:8000. And a packet coming from an external network (for example, from computer 172.16.0.5:4000) to a device with address: port 10.1.1.1:12345 will be sent to computer 192.168.0.4:8000 only if 192.168.0.4:8000 previously sent a request to the IP address of the external host (in our case, to the computer 172.16.0.5:4000). That is, the router will broadcast incoming packets only from a specific source address (in our case, computer 172.16.0.5:4000), but the source port number can be anything. Otherwise, NAT blocks packets coming from hosts to which 192.168.0.4:8000 did not send a request.

NAT mechanism Port Restricted Cone almost similar to the NAT Restricted Cone mechanism. Only in this case, NAT blocks all packets coming from hosts to which the client computer 192.168.0.4:8000 did not send a request to any IP address and port. The router pays attention to the matching source port number and does not pay attention to the source address. In our example, the router will broadcast incoming packets with any source address, but the source port must be 4000. If the client sent requests to the external network to several IP addresses and ports, then they will be able to send packets to the client on the IP address: port 10.1 .1.1:12345.

Symmetric NAT differs significantly from the first three mechanisms in the way it maps the internal IP address:port to the external address:port. This display depends on the IP address:port of the computer to which the sent request is intended. For example, if client computer 192.168.0.4:8000 sends a request to computer #1 (172.16.0.5:4000), then it may appear as 10.1.1.1:12345, while at the same time if it sends from the same port (192.168. 0.4:8000) to a different IP address, it is displayed differently (10.1.1.1:12346).

  • Allows you to prevent or limit access from the outside to internal hosts, leaving the possibility of access from the internal network to the external one. When a connection is initiated from within the network, a broadcast is created. Response packets arriving from outside match the generated broadcast and are therefore passed through. If there is no corresponding translation for packets coming from the external network (and it can be created when the connection is initiated or static), they are not allowed through.
  • Allows you to hide certain internal services of internal hosts/servers. Essentially, the same broadcast above is performed on a specific port, but it is possible to replace the internal port of an officially registered service (for example, TCP port 80 (HTTP server) with external port 54055). Thus, from the outside, on the external IP address after the addresses are translated to the site (or forum), for knowledgeable visitors it will be possible to get to the address http://dlink.ru:54055, but on the internal server located behind NAT, it will work on the usual 80th port.
  • However, it is worth mentioning the disadvantages of this technology:

    1. Not all protocols can "traverse" NAT. Some fail if there is address translation on the path between communicating hosts. Certain IP address translation firewalls can correct this shortcoming by appropriately replacing IP addresses not only in the IP headers, but also with more high levels(for example, in FTP protocol commands).
    2. Due to multi-to-one address translation, additional difficulties arise with identifying users and the need to store complete translation logs.
    3. DoS attack by a host performing NAT - If NAT is used to connect many users to the same service, it can create the illusion of a DoS attack on the service (multiple successes and failures). For example, an excessive amount ICQ users behind NAT leads to problems connecting to the server for some users due to exceeding the permissible connection speed.
    Share