- IP Address Planning
- Hierarchical Addressing Using Variable-Length SubnetMasks
- Route Summarization
- Classless Interdomain Routing
- Network Address Translation
- Understanding IP Version 6
- Summary
- References
- Configuration Exercise 1-1: Basic Connectivity
- Configuration Exercise 1-2: NAT Using Access Lists andRoute Maps
- Solution to Configuration Exercise 1-1: Basic Connectivity
- Solution to Configuration Exercise 1-2: NAT Using Access Lists and Route Maps
- Review Questions
Network Address Translation
IP address depletion is a key problem facing the Internet. To assist in maximizing the use of registered IP addresses, Cisco IOS Release 11.2 and later implement NAT. This feature, which is Cisco's implementation of RFC 1631, The IP Network Address Translator (available at http://www.cis.ohio-state.edu/cgi-bin/rfc/rfc1631.html), is a solution that provides a way to use the same IP addresses in multiple internal stub networks, thereby reducing the need for registered IP addresses.
NAT is an important function in most scalable networks and is mandatory for the majority of companies that have Internet connections. ISPs have hundreds of users accessing the Internet, yet commonly are assigned only 8 or 16 individual addresses. The ISPs use NAT to map the hundreds of inside addresses to the few globally unique addresses assigned to that company. After introducing NAT terminology and features, this section demonstrates the following:
How to use basic NAT and a standard access list to assign separate address space to different users.
How to use an extended access list to check a packet's destination address and assign different source addresses based on it.
How to use a Cisco IOS software tool called a route map to create a fully extended address translation in an IP NAT table. The IP NAT table tracks the original address and its translation as well as the destination address and the Transmission Control Protocol (TCP) and User Datagram Protocol (UDP) ports for each.
NAT Terminology and Features
This section first introduces the terminology that is necessary to understand NAT and then explains NAT's various features.
NAT Terminology
The terms inside network and outside network are used with NAT, as shown in Figure 1-21. NAT terminology, as used in Figure 1-21, is defined in Table 1-3.
Figure 1-21 Network Address Translation Is Used to Translate Addresses Between the Inside and Outside Networks
Table 1-3 NAT Terminology
Term |
Definition |
Inside local IP address (A) |
The IP address assigned to a host on the inside network. (The address was either globally unique but obsolete, allocated from RFC 1918, or randomly picked.) |
Inside global IP address (B) |
A legitimate IP address (typically assigned by a service provider) that represents one or more inside local IP addresses to the outside world. (The address was allocated from a globally unique address space, typically provided by the ISP.) |
Outside global IP address (C) |
The IP address that was assigned to a host on the outside network by its owner. (The address was allocated from a globally routable address space.) |
Outside local IP address (not shown) |
The IP address of an outside host as it appears to the inside network. (The address was allocated from address space routable on the inside or possibly was allocated from RFC 1918, for example.) An example of when an outside local IP address is required is given in the "Handling Overlapping Networks" sidebar later in this section. |
Simple translation entry |
A translation entry that maps one IP address to another. This is the type of entry shown in the NAT table in Figure 1-21. |
Extended translation entry (not shown) |
A translation entry that maps one IP address and port pair to another. |
A NAT entry is built in the IP NAT table as the packet goes from an IP NAT inside interface. A NAT entry usually changes the source IP address in the packet from an inside address to an outside address. When a device on the outside responds to the packet, the destination IP address of the returning packet is compared to the entries in the IP NAT table. If a match is found, the destination IP address is translated to the correct inside address and is sent to the routing table to be routed to the correct IP NAT inside interface. If no match is found, the packet is discarded.
NAT is performed when a packet is routed between the following interfaces:
IP NAT inside interface to an IP NAT outside interface
IP NAT outside interface to an IP NAT inside interface
A NAT table may contain the following information:
ProtocolIP, TCP, or UDP.
Inside local IP address:portThe IP address and port number used by the inside host before any translations. The inside local IP address is usually the private addressing defined in RFC 1918.
Inside global IP address:portThe IP address and port number used by the inside host as it appears to the outside network; this is the translated IP address and port. Addresses are allocated from a globally unique address space, typically provided by the ISP if the enterprise connects to the global Internet.
Outside global IP address:portThe configured globally unique IP address assigned to a host in the outside network, and the port number used.
Outside local IP address:portThe IP address and port number of an outside host as it appears to the inside network.
NOTE
Simple NAT entries consist of only the inside local IP address and the inside global IP address.
Features Supported by NAT
Supported NAT features include the following:
Static address translationEstablishes a one-to-one mapping between inside local and global addresses.
Dynamic source address translationEstablishes a dynamic mapping between the inside local and global addresses. This is accomplished by describing the local addresses to be translated, the pool of addresses from which to allocate global addresses, and associating the two. The router creates translations as needed.
Address overloadingCan conserve addresses in the inside global address pool by allowing source ports in TCP connections or UDP conversations to be translated. When different inside local addresses map to the same inside global address, each inside host's TCP or UDP port numbers are used to distinguish between them.
When the router determines that a packet's path is from an IP NAT inside interface to an IP NAT outside interface, an entry is built to include both the original source IP address and the original TCP for UDP port number. Each of these entries is assigned a unique TCP/UDP source port number to distinguish it from the others. When a packet returns to the IP NAT outside interface, it is compared to the IP NAT table. Although the packet destination address could match thousands of entries, NAT checks the destination TCP/UDP port for the correct entry for the returning packet. After the correct entry is found, the current destination address and port number change to the appropriate IP NAT inside destination address and port number.
TCP load distributionA dynamic form of destination translation that can be configured for some outside-to-inside traffic. After a mapping is defined, destination addresses matching an access list are replaced with an address from a rotary pool. Allocation is done on a round-robin basis, and only when a new connection is opened from the outside to the inside. All non-TCP traffic is passed untranslated (unless other translations are in effect).
Handling Overlapping Networks
Figure 1-22 illustrates NAT operation when addresses in the inside network overlap with addresses that are in the outside network; in this case, outside local IP addresses are used.
Figure 1-22 Handling Overlapping Networks
The following describes this process of handling overlapping addresses:
Step 1 |
The user at 10.1.1.1 opens a connection to Host C (10.1.1.3), causing 10.1.1.1 to perform a name-to-address lookup to a DNS server. |
Step 2 |
If there is an overlap, the router intercepts the DNS reply and translates the returned address. In this case, 10.1.1.3 overlaps with an inside address. To translate the return address of Host C, the router creates a simple translation entry that maps the overlapping address 10.1.1.3 to an address from a separately configured outside local address pool. In this example, the address is 172.17.3.3. |
Step 3 |
The router forwards the DNS reply to Host 10.1.1.1. The reply has Host C's address as 172.17.3.3. At this point, 10.1.1.1 opens a connection to 172.17.3.3. |
Step 4 |
When the router receives the packet for Host C (172.17.3.3), it sets up a translation that maps the inside local and global addresses and the outside global and local addresses by replacing the source address of 10.1.1.1 with the inside global address 172.16.2.2 and replacing the destination address of 172.17.3.3 with Host C's outside global address, 10.1.1.3. |
Step 5 |
Host C receives a packet and continues the conversation. |
Step 6 |
For each packet sent between Host 10.1.1.1 and Host C, the router performs a lookup, replaces the destination address with the inside local address, and replaces the source address with the outside local address. |
Configuring NAT with Access Lists
This section explains the IP NAT commands to configure IP NAT with access lists. It provides a sample IP NAT configuration and two specific examples of configuring IP NAT with access lists. The first example demonstrates how to use access lists to determine whether an IP address needs translation based on the original source address. The second example demonstrates how to use an access list to assign a NAT source IP address based on the source and destination addresses of the original packet.
The following commands are used to configure IP NAT with access lists:
ip nat {inside | outside}This interface configuration command marks the IP networks attached to that interface as either internal or external to the controlled network. Only packets arriving on an interface marked as IP NAT inside or outside are subject to translation.
ip nat inside source list {access-list-number | access-list-name} pool pool-nameWhen a packet comes in on an interface marked as IP NAT inside, this global configuration command causes the router to compare the source IP address in the packet to the access list referenced in the command. The access list indicates whether the router should translate that source IP address to the next available address in the pool-name listed. NAT translates an address that is permitted in the access list. Addresses that are not permitted by the access list are not translated, and the packet is routed normally.
ip nat pool pool-name starting-ip-address ending-ip-address {prefix-length prefix-length | netmask netmask}This global configuration command creates the translation pool referenced by the previous command. This command includes the starting and ending addresses for translation and either the prefix length or network mask associated with this range of addresses.
Standard Access List Translation Example
In Figure 1-23, when an IP packet comes in on Ethernet 0 of Router A with a source address of 10.1.2.x, the router translates it from the NAT pool of addresses defined by the name sale_pool. If the packet has a source address of 10.1.3.x, the router translates it from the NAT pool of addresses defined by the name acct_pool.
In this example, the Information Services (IS) department maps different groups of users to different blocks of NAT addresses. The IS department determines the percentage of users per department who can use the NAT interface and assigns an appropriate number of addresses. The percentage of users can typically be determined using accounting or security software.
Figure 1-23 Translating with Standard Access Lists
Extended Access List Translation Example
The network used in this example is the same as that shown in Figure 1-23. However, in this configuration example, the extended access lists 102 and 103 are used to control NAT decisions. Instead of making the decision based only on the source address, an extended access list makes the decision based on the source and destination addresses of all packets coming in on interface Ethernet 0.
The configuration used on Router A is shown in Example 1-2.
Example 1-2 NAT Example Using Extended Access Lists on Router A in Figure 1-23
In this example, if the packet is not from the 10.1.1.0/24 subnet, the packet's source IP address is not translated. If the packet is from the 10.1.1.0/24 subnet and the destination address matches either 172.16.1.0/24 or 192.168.200.0/24, the source IP address is translated to the next available address in the trusted_pool, which is the 192.168.2.0/24 network.
If the packet is from the 10.1.1.0/24 subnet and the destination address does not match either 172.16.1.0/24 or 192.168.200.0/24, the source IP address is translated to the next available address in the untrusted_pool, which is the 192.168.3.0/24 network.
In this example, the outside NAT environment has both trusted and untrustworthy sites. For example, the company might be attached to an industry internetwork where it exchanges information with corporate partners and competitors. 172.16.1.0/24 and 192.168.200.0/24 are addresses of trusted networks on the industry internetwork, but all other destination addresses are considered untrustworthy. (A firewall system may also be added to allow greater control over the trusted sites.)
Configuring NAT with Route Maps
A route map is a Cisco IOS software function that serves a variety of purposes. This section explains route maps and compares the results of using NAT with a route map to the results of using NAT with only an access list.
NOTE
Route maps are discussed in more detail in Chapter 7, "Manipulating Routing Updates."
When you use only access lists for NAT, as described in the previous section, the resulting NAT table has only simple translation entries, identifying only which inside local address is being translated to which inside global address. Example 1-3 shows simple translation entries using the show ip nat translations command. The simple translation entry contains only local and global IP address entries. It does not include any TCP or UDP port information or the packet's destination address.
Example 1-3 Simple IP Address Translation Entries
The entries in this IP NAT translation table are called simple entries because they track only the original source address (the inside local address) and the address to which it is translated (the inside global address). The other fields in the table are left blank. It is difficult to troubleshoot connectivity using simple address entries, because you do not see the destination address or the application (port) associated with each NAT translation. This might also prevent proper translation among multiple address pools. The first address pool matched creates a simple NAT entry; a second session initiated by the same source to a different host already matches the simple entry, thereby preventing proper translation to the second address pool. (Configuration Exercise 1-2, at the end of this chapter, includes an example of this translation problem.)
To get an extended translation entry in the NAT table, you must either configure NAT for overloading (using the overload keyword on the ip inside source command) or use a Cisco IOS software tool called a route map. Example 1-4 shows an example of an extended translation entry. The extended translation entry identifies the source and destination addresses with their appropriate translations, the transport layer protocol used, and the port (or application) used for the session.
Example 1-4 IP Address Translation with Route Maps
Understanding Route Maps
Route maps are complex access lists that allow some conditions to be tested against the packet or route in question using match commands. If the conditions match, some actions can be taken to modify attributes of the packet or route. These actions are specified by set commands.
A collection of route map statements that have the same route map name are considered one route map. Within a route map, each route map statement is numbered and therefore can be edited individually.
The statements in a route map correspond to the lines of an access list. Specifying the match conditions in a route map is similar to specifying the source and destination addresses and masks in an access list.
Key Point: Route Maps Versus Access Lists
One big difference between route maps and access lists is that route maps can modify the route by using set commands.
The route-map map-tag [permit | deny] [sequence-number] global configuration command can be used to define the conditions for NAT. This command is explained in detail in Table 1-4.
Table 1-4 route-map Command
Command |
Description |
map-tag |
Name of the route map |
permit | deny |
Optional parameter that specifies the action to be taken if the route map match conditions are met |
sequence-number |
Optional sequence number that indicates the position that a new route map statement will have in the list of route map statements already configured with the same name |
The default for the route-map command is permit, with a sequence-number of 10.
Route Map Sequence Numbering
If you leave out the sequence number when configuring all statements for the same route map name, the router will assume that you are editing and adding to the first statement, sequence number 10. Route map sequence numbers do not automatically increment!
A route map may be made up of multiple route map statements. The statements are processed top-down, similar to an access list. The first match found for a route is applied. The sequence number is used for inserting or deleting specific route map statements in a specific place in the route map.
The match condition route map configuration commands are used to define the conditions to be checked. The set condition route map configuration commands are used to define the actions to be followed if there is a match and the action to be taken is permit. (The consequences of a deny action depend on how the route map is being used.)
A single match statement may contain multiple conditions. At least one condition in the match statement must be true for that match statement to be considered a match. A route map statement may contain multiple match statements. All match statements in the route map statement must be considered true for the route map statement to be considered matched.
Key Point: Route Map Match Conditions
Only one match condition listed on the same line must match for the entire line to be considered a match.
For example, IP standard or extended access lists can be used to establish match criteria using the match ip address {access-list-number | name} [...access-list-number | name] route map configuration command. (If multiple access lists are specified, matching any one results in a match.) A standard IP access list can be used to specify match criteria for a packet's source address; extended access lists can be used to specify match criteria based on source and destination addresses, application, protocol type, type of service (ToS), and precedence.
The sequence number specifies the order in which conditions are checked. For example, if two statements in a route map are named MYMAP, one with sequence 10 and the other with sequence 20, sequence 10 is checked first. If the match conditions in sequence 10 are not met, sequence 20 is checked.
Like an access list, an implicit deny any appears at the end of a route map. The consequences of this deny depend on how the route map is being used.
Another way to explain how a route map works is to use a simple example and see how a router would interpret it. Example 1-5 shows a sample route map configuration. (Note that on a router, all the conditions and actions shown would be replaced with specific conditions and actions, depending on the exact match and set commands used.)
Example 1-5 route-map Command
The route map named demo in Example 1-5 is interpreted as follows:
NAT with Route Maps Example
The ip nat inside source route-map route-map-name pool pool-name global configuration command causes the router to compare the source IP address in the packet to the route map referenced in the command. The route map indicates whether the router should translate that source IP address to the next available address in the pool-name listed. NAT translates an address that is matched in the route map.
Example 1-6 provides an alternative configuration for Router A in Figure 1-23. Two route maps have been added to the configuration shown in Figure 1-23. In this example, the what_is_sales_doing route map is linked to the sales_pool using the ip nat inside source route-map what_is_sales_doing pool sales_pool command.
Example 1-6 Alternative Configuration for Router A in Figure 1-23
Following the path of a packet through this configuration is the best way to understand it. An IP packet with a source address of 10.1.2.100 arrives on interface Ethernet 0, which is an IP NAT inside interface. The ip nat inside source route-map what_is_sales_doing pool sales_pool command causes the router to send the packet to the what_is_sales_doing route map. Sequence 10 of this route map matches the packet's source IP address, 10.1.2.100, against access list 2, which permits the packet and therefore matches the route map. The router then queries the NAT pool sales_pool and obtains the next address to which to translate the 10.1.2.100 packet.
The what_is_acct_doing route map together with the ip nat inside source route-map what_is_acct_doing pool acct_pool command causes the router to look for source IP addresses in the 10.1.3.0/24 range and change them to source IP addresses in the 192.168.3.0/24 range.
As discussed, to examine the IP NAT translation table, use the show ip nat translations command. When using just an access list (as in the configuration shown in Figure 1-23), the router creates only a simple translation entry, one entry per application, without the TCP and UDP ports; Example 1-3 shows a simple translation entry. However, when using a route map, the router creates a fully extended translation entry in the IP NAT translation table, which includes the source and destination TCP or UDP port numbers. The extended translation entry shown in Example 1-4 results from the configuration in Example 1-6.
Notice in Example 1-4 that each session has individual entries; the IP address of each user and the applications in use can be determined from these entries. The local device with IP address 10.1.2.100 has three sessions with an outside device that has IP address 172.16.1.20. Example 1-4 shows that 10.1.2.100 has a TFTP session (UDP port 69) and an FTP session (TCP ports 20 and 21) with 172.16.1.20. Local device 10.1.3.67 has two sessions with the same remote device (172.16.1.20). Its two sessions are Telnet (TCP port 23) and HTTP (TCP port 80).