Most network address translators map multiple private hosts to one publicly exposed IP address. In a typical configuration, a local network uses one of the designated
private IP address subnets (RFC 1918). The network has a router having network interfaces on both the private and the public networks. The public address is typically assigned by an
Internet service provider. As traffic passes from the private network to the Internet, NAT translates the source address in each packet from a private address to the router's public address. The NAT facility tracks each active connection. When the router receives inbound traffic from the Internet, it uses the connection tracking data obtained during the outbound phase to determine to which private address it should forward the reply. Packets passing from the private network to the public network will have their source address modified, while packets passing from the public network back to the private network will have their destination address modified. To avoid ambiguity in how replies are translated, further modifications to the packets are required. The vast bulk of Internet traffic uses
Transmission Control Protocol (TCP) or
User Datagram Protocol (UDP). For these protocols, the
port numbers are changed so that the combination of IP address (within the
IP header) and port number (within the
Transport Layer header) on the returned packet can be unambiguously mapped to the corresponding private network destination. RFC 2663 uses the term
network address and port translation (
NAPT) for this type of NAT. Other names include
port address translation (
PAT),
IP masquerading,
NAT overload, and
many-to-one NAT. This is the most common type of NAT and has become synonymous with the term
NAT in common usage. This method allows communication through the router only when the conversation originates in the private network, since the initial originating transmission establishes the required information in the translation tables. Thus, a
web browser within the private network is able to browse websites that are outside the network, whereas web browsers outside the network are unable to browse a website hosted within. Protocols not based on TCP and UDP require other translation techniques. The primary benefit of one-to-many NAT is mitigation of
IPv4 address exhaustion by allowing entire networks to be connected to the Internet using a single public IP address. ==Methods of translation== Network address and port translation may be implemented in several ways. Some applications that use IP address information may need to determine the external address of a network address translator. This is the address that its communication peers in the external network detect. Furthermore, it may be necessary to examine and categorize the type of mapping in use, for example, when it is desired to set up a direct communication path between two clients, both of which are behind separate NAT gateways. For this purpose, RFC 3489 specified the protocol
Simple Traversal of UDP over NATs (
STUN) in 2003. It classified NAT implementations as
full-cone NAT,
(address) restricted-cone NAT,
port-restricted cone NAT or
symmetric NAT, and proposed a methodology for testing a device accordingly. However, these procedures have since been deprecated from standards status, as the methods are inadequate to correctly assess many devices. RFC 5389 standardized new methods in 2008 and the acronym
STUN since represents the new title of the specification:
Session Traversal Utilities for NAT. As many NAT implementations combine multiple types, it is better to refer to specific individual NAT behavior instead of using the Cone/Symmetric terminology. RFC 4787 attempts to alleviate confusion by introducing standardized terminology for observed behaviors. For the first bullet in each row of the above table, the RFC would characterize Full-Cone, Restricted-Cone, and Port-Restricted-Cone NATs as having an
Endpoint-Independent Mapping, whereas it would characterize a Symmetric NAT as having an
Address- and Port-Dependent Mapping. For the second bullet in each row of the above table, RFC 4787 would also label Full-Cone NAT as having an
Endpoint-Independent Filtering, Restricted-Cone NAT as having an
Address-Dependent Filtering, Port-Restricted Cone NAT as having an
Address- and Port-Dependent Filtering, and Symmetric NAT as having either an
Address-Dependent Filtering or
Address- and Port-Dependent Filtering. Other classifications of NAT behavior mentioned in the RFC include whether they preserve ports, when and how mappings are refreshed, whether external mappings can be used by internal hosts (i.e., its
hairpinning behavior), and the level of determinism NATs exhibit when applying all these rules. Specifically, most NATs combine
symmetric NAT for outgoing connections with
static port mapping, where incoming packets addressed to the external address and port are redirected to a specific internal address and port.
NAT mapping vs NAT filtering RFC 4787 distinguishes between NAT mapping and NAT filtering. Section 4.1 of the RFC covers NAT mapping and specifies the translation of an external IP address and port number into an internal IP address and port number. It defines endpoint-independent mapping, address-dependent mapping and address- and port-dependent mapping, explains that these three possible choices do not relate to the security of the NAT as security is determined by the filtering behavior and then specifies "A NAT MUST have an 'Endpoint-Independent Mapping' behavior." Section 5 of the RFC covers NAT filtering and describes the criteria used by the NAT to filter packets originating from specific external endpoints. The options are endpoint-independent filtering, address-dependent filtering and address- and port-dependent filtering. Endpoint-independent filtering is recommended where maximum application transparency is required while address-dependent filtering is recommended where more stringent filtering behavior is most important. Some NAT devices are not compliant with RFC 4787 as they treat NAT mapping and filtering in the same way, so that their configuration option for changing the NAT filtering method also changes the NAT mapping method (e.g., Netgate TNSR). ==Type of NAT and NAT traversal, role of port preservation for TCP==