8.2. NAT

Dynamic Network Address Translation (NAT) provides a mechanism for translating original source IP addresses to a different address. Outgoing packets then appear to come from a different IP address and incoming packets back to that address have their IP address translated back to the original IP address.

Methods of Configuring NAT in cOS Core

There are two ways of configuring NAT in the cOS Core IP rule set:

Examples of both these methods are included in this section.

NAT Benefits

NAT can have two important benefits:

NAT Provides many-to-one IP Address Translation

NAT provides many-to-one translation. This means that each NATing IP rule set entry can translate between several source IP addresses and a single source IP address.

To maintain session state information, each connection from dynamically translated addresses uses a unique port number and IP address combination as its sender. cOS Core performs automatic translation of the source port number as well as the IP address. In other words, the source IP addresses for connections are all translated to the same IP address and the connections are distinguished from one another by the allocation of a unique port number to each connection.

The diagram below illustrates the concept of NAT.

NAT IP Address Translation

Figure 8.1. NAT IP Address Translation

In the illustration above, three connections from IP addresses A, B and C are NATed through a single source IP address N. The original port numbers are also changed.

The next source port number allocated for a new NAT connection will be the first free port selected randomly by cOS Core. Ports are allocated randomly to increase security.

Limitations on the Number of NAT Connections

Approximately 64,500 simultaneous NAT connections are possible if a "connection" is considered to be a unique pair of IP addresses and different port numbers are not used or the same destination port is used.

However, since there is a possible range of 64,500 source ports and the same number for destination ports, it is theoretically possible to have over 4 billion connections between two IP addresses if all ports are used.

Using NAT Pools Can Increase the Connections

To increase the number of NAT connections that can exist between the Clavister firewall and a particular external host IP, the cOS Core NAT pools feature can be used which can automatically make use of additional IP addresses on the firewall.

This is useful in situations where a remote server requires that all connections are to a single port number. In such cases, the 64,500 limit for unique IP address pairs will apply.

See Section 8.3, NAT Pools for more information about this topic.

The Source IP Address Used for Translation

There are three options for how cOS Core determines the source IP address that will be used for NAT:

The NAT Translation Process

To explain the NAT process in a simple example, consider a protected client behind the firewall which has the private IP address 192.168.1.5. It wants to make an HTTP connection on port 80 of a server with the public IP 203.0.113.10.

The public IP of the cOS Core Ethernet interface connected to the Internet is 203.0.113.5 (for simplicity, assume that the interface and the server are on the same network). NAT translation is applied to connections originating on this interface by specifying a NATing IP rule set entry that allows connections from the client to the server.

The sequence of these events in the NAT process is illustrated in the diagram below and the description of steps that follows.

The NAT Translation Process

Figure 8.2. The NAT Translation Process

  1. The sender at IP address 192.168.1.5 sends a packet from a dynamically assigned port number (assume port 1038) to the server at 203.0.113.10 on port 80.

    		 => 
  2. Assume that the IP policy NAT Outgoing Interface IP option is used. cOS Core will change the source port to a random unused port on its interface which is above port 1024. In this example, assume port 32,789 is chosen. The packet is then sent to its destination with this source port and the source IP of the interface.

    		 => 
  3. The server then processes the packet and sends its response back to the source IP and port.

    		 => 
  4. cOS Core receives the packet and looks up the destination IP and port in its list of open connections. If it finds the connection, it restores the original source IP address and port number and forwards the packet.

    		 => 
  5. The original sender has now received the response without needing a public IP address of its own.

Example 8.1. Setting Up NAT with an IP Policy

This example adds a NAT IP policy that will perform address translation for all HTTP traffic originating from the internal network lan flowing to the Internet on the wan interface. The IP address of the wan interface will be used as the NATing address for all connections.

Command-Line Interface

Device:/> add IPPolicy Name=nat_http
			SourceInterface=lan
			SourceNetwork=lan_net
			DestinationInterface=wan
			DestinationNetwork=all-nets
			Service=http-all
			Action=Allow
			SourceAddressTranslation=NAT
			NATSourceAddressAction=OutgoingInterfaceIP

The NATAction option could be left out since the default value is to use the interface address. The alternative is to specify UseSenderAddress and use the NATSenderAddress option to specify the IP address to use. The sender address will also need to be explicitly ARP published on the interface.

InControl

Follow similar steps to those used for the Web Interface below.

Web Interface

  1. Go to: Policies > Firewalling > Main IP Rules > Add > IP Policy
  2. Now enter:
    • Name: nat_http
    • Action: Allow
  3. Under Filter enter:
    • Source Interface: lan
    • Source Network: lan_net
    • Destination Interface: wan
    • Destination Network: all-nets
    • Service: http
  4. Under Source Translation enter:
    • Address Translation: NAT
    • Address Action: Outgoing Interface IP
  5. Click OK

Logging is enabled by default.

Example 8.2. Setting Up NAT with an IP Rule

This example replicates the scenario in Example 8.1, “Setting Up NAT with an IP Policy” but this time uses an IP Rule object. This is included here to show an IP rule can be used. Using an IP Policy is the recommended method as it can provide more options that can be configured directly on the IP policy.

Command-Line Interface

Device:/> add IPRule Action=NAT
			SourceInterface=lan
			SourceNetwork=lan_net
			DestinationInterface=wan
			DestinationNetwork=all-nets
			Service=http-all
			NATAction=UseInterfaceAddress
			Name=NAT_HTTP

The NATAction option could be left out since the default value is to use the interface address. The alternative is to specify UseSenderAddress and use the NATSenderAddress option to specify the IP address to use. The sender address will also need to be explicitly ARP published on the interface.

InControl

Follow similar steps to those used for the Web Interface below.

Web Interface

  1. Go to: Policies > Firewalling > Main IP Rules > Add > IP Rule
  2. Specify a suitable name for the rule, for example NAT_HTTP
  3. Now enter:
    • Action: NAT
    • Service: http-all
    • Source Interface: lan
    • Source Network: lan_net
    • Destination Interface: wan
    • Destination Network: all-nets
  4. Under the NAT tab, make sure that the Use Interface Address option is selected
  5. Click OK

Logging is enabled by default.

Protocols Handled by NAT

Dynamic address translation is able to deal with the TCP, UDP and ICMP protocols with a good level of functionality since the algorithm knows which values can be adjusted to become unique in the three protocols. For other IP level protocols, unique connections are identified by their sender addresses, destination addresses and protocol numbers.

This means that:

[Note] Note: Restrictions only apply to IP level protocols

These restrictions apply only to IP level protocols other than TCP, UDP and ICMP, such as OSPF and L2TP. They do not apply to the protocols transported by TCP, UDP and ICMP such as telnet, FTP, HTTP and SMTP.

cOS Core can alter port number information in the TCP and UDP headers to make each connection unique, even though such connections have had their sender addresses translated to the same IP.

Some protocols, regardless of the method of transportation used, can cause problems during address translation.

Anonymizing Internet Traffic with NAT

A useful application of the NAT feature in cOS Core is for anonymizing service providers to anonymize traffic between clients and servers across the Internet so that the client's public IP address is not present in any server access requests or peer to peer traffic.

The typical case will be examined, where the firewall acts as a PPTP server and terminates the PPTP tunnel for PPTP clients. Clients that wish to be anonymous, communicate with their local ISP using PPTP. The traffic is directed to the anonymizing service provider where the firewall is installed to act as the PPTP server for the client, terminating the PPTP tunnel. This arrangement is illustrated in the diagram below.

Anonymizing with NAT

Figure 8.3. Anonymizing with NAT

cOS Core is set up with NATing IP rule set entries so it takes communication traffic coming from the client and NATs it back out onto the Internet. Communication with the client is with the PPTP protocol but the PPTP tunnel from the client terminates at the firewall. When this traffic is relayed between the firewall and the Internet, it is no longer encapsulated by PPTP.

When an application, such as a web server, now receives requests from the client it appears as though they are coming from the anonymizing service provider's external IP address and not the client's IP. The application therefore sends its responses back to the firewall which relays the traffic back to the client through the PPTP tunnel. The original IP address of the client is not revealed in traffic as it is relayed beyond the termination of the PPTP tunnel at the cOS Core.

Typically, all traffic passes through the same physical interface and that interface has a single public IP address. Multiple interfaces could be used if multiple public IPv4 addresses are available. There is clearly a small processing overhead involved with anonymizing traffic but this need not be an issue if sufficient hardware resources are employed to perform the anonymizing.

This same technique can also be used with L2TP instead of PPTP connections. Both protocols are discussed further in Section 10.4.4, PPTP/L2TP Clients.