Fundamentals of NAT
Date: Apr 2, 2012
There's a very good chance that you are using Network Address Translation (NAT) right now and most people are not even aware of it. When the IPv4 address space was originally developed everyone thought that there would be more than enough available addresses to cover all eventual needs, but with the veritable explosion of internet users and the ever increasing number of home networks, the number of available IP Addresses turned out to be insufficient to the task at hand. So what does NAT have to do with the ever expanding size of the internet? The answer is: EVERYTHING!
So what does NAT have to do with network security? NAT breaks the end-to-end IP/TCP model. More specifically, dynamic NAT automatically creates a FIREWALL between our internal network and any outside networks, to include the largest external network in the world[md]the internet. Basically, this means that a host on an external network cannot connect to an internal host unless that host has initiated an outbound session. This means that an internal user can browse the internet, and download files; but an external host cannot initiate a session to an internal IP Address and use it to connect to internal devices or services. In this blog we are going to explore the security aspects of this technology.
NAT as a Firewall
NAT translates the addresses of hosts behind a firewall or router and is normally used for internal networks that have unregistered (non-routable) IP addresses. NAT will translate these unregistered addresses into routable addresses assigned to outside networks. Outside networks are most usually referred to as public networks, and NAT allows non-routable or unregistered IP address spaces to connect to the web while providing added security. With Cisco IOS, NAT translation is used by a device that sits between the private, or inside, network and the outside, or public, network. NAT has many forms and works in many ways:
- Static NAT is where we map an unregistered IP Address to a registered IP Address on a one-to-one basis. This is most commonly employed when there is a device that needs to be accessible from outside the network.
- Dynamic NAT is where an unregistered IP Address is mapped to a registered IP Address from a group of available registered IP Addresses.
- PAT (NAT Overload) is a variation of dynamic NAT that maps multiple unregistered IP Addresses to a single registered IP Address by using different ports. Other names for this variation include port-level multiplexed NAT or Single Address NAT.
NAT Terminology
Before we even attempt to look at how to configure NAT on a router or a Firewall, we need to become familiar with the terminology used in the NAT environment.
- Inside Local Address is an IP Address that is assigned to a host on the inside network. This address is not advertised to the Public/Outside network. This is most frequently not a routable or legitimate IP Address.
- Inside Global Address is a routable IP Address assigned by the International Number Authority or its regional delegates.
- Outside Local Address is an IP Address used by an outside host of the network. It is this address that is being translated as it appears to the private network.
- Outside Global Address is the IP Address assigned to a host on the outside or public network that is being translated by that host's network.
Configuring Static NAT
Here we will look at what is involved in configuring Static NAT on a Cisco router. Static NAT is pretty straight forward. Remember this is most commonly used for translating addresses on a one-to-one basis. This is accomplished via a three-step process:
- Step 1: Designate at least one NAT inside interface.
- Step 2: Designate at least one NAT outside interface.
- Step 3: NAT the source IP to the outside IP Address.
R1(config)# interface fastethernet0/1 R1(config-if)# ip address 192.168.100.1 255.255.255.0 R1(config-if)# ip nat inside
R1(config)# int serial0/0 R1(config-if)# ip address 10.10.10.100 255.255.255.0 R1(config-if)# ip nat outside
R1(config)# ip nat inside source static 192.168.100.1 172.1.1.1 R1(config)# ip nat inside source static 192.168.100.2 172.1.1.2 R1(config)# ip nat inside source static 192.168.100.3 172.1.1.3
This configuration will result in the IP Addresses 192.168.100.1 to 192.168.100.3 being translated to 172.1.1.1, 172.1.1.2 and 172.1.1.3 respectively.
Configuring Dynamic NAT
Dynamic NAT configuration is only slightly more complicated than the Static NAT configuration we just looked at. In its simplest form, dynamic NAT is a four-step configuration process:
- Step 1: Designate at least one NAT inside interface.
- Step 2: Designate at least on NAT outside interface.
- Step 3: Create a pool of Public IP Addresses.
- Step 4: Create an Access Control List (ACL) that will include the local hosts or network(s).
R1(config)# interface fastethernet0/0 R1(config-if)# ip nat inside
R1(config-if)# interface serial0/0 R1(config-if)# ip nat outside
R1(config)# ip nat pool PUBLIC 222.2.2.2 222.2.2.5 prefix-length 29
This defines the range of IP Addresses that will be handed out by the router to our internal hosts trying to connect to the Internet. Each time a host sends a packet destined for the Internet, the router will automatically allocate one of the Public IP addresses for the duration of the browser session. When the session is over, the NAT entry will timeout and the Public IP address will be returned to the pool.
R1(config)# ip nat inside source list 100 pool PUBLIC R1(config)# access-list 100 remark == [Control NAT Pool Service]== R1(config)# access-list 100 permit ip 192.168.0.0 0.0.0.255 any
This ACL will be applied to the NAT pool named 'PUBLIC', and control what hosts will be assigned Public IP address and therefore able to access the Internet.
Configuring NAT Overload (PAT)
NAT Overload is the most common NAT deployment used in Small Office/Home Office networks. NAT Overload is a variation of Static or Dynamic NAT with a few enhancements. By this point we have an understanding of how both Static and Dynamic NAT work so we can jump right in.
Overloading implies that a single public IP Address can be used by multiple internal hosts simultaneously. This is done by translating source UDP/TCP ports in the packets and keeping track of them within a NAT translation table. We will look at a typical NAT configuration found in most small networks. In its simplest form we are looking at a four-step process:
- Step 1: Designate at least one NAT inside interface.
- Step 2: Designate at least one NAT outside interface.
- Step 3: Create an Access Control List (ACL) that will include the local hosts or network(s).
- Step 4: Enable NAT overload and bind it to the outside interface.
R1(config)# interface fastethernet0/0 R1(config-if)# ip nat inside
R1(config-if)# interface Serial0/0 R1(config-if)# ip nat outside
R1(config)# ip nat inside source list 100 pool PUBLIC R1(config)# access-list 100 remark == [Control NAT Pool Service]== R1(config)# access-list 100 permit ip 192.168.1.0 0.0.0.255 any
This defines the range of IP Addresses that will be handed out by the router to our internal hosts trying to connect to the Internet.
R1(config)# ip nat inside source list 100 interface serial 0/0 overload
From this point the configuration will create PAT translations to allow the users in the network 192.168.1.0/24 to access the public internet.
Displaying the NAT/PAT translation table
The network translation table can best be viewed by using the 'show ip nat translation' command:
R1#show ip nat translation Pro Inside global Inside local Outside local Outside global tcp 171.71.1.1:3598 10.10.10.2:3598 198.133.219.25:80 198.133.219.25:80 tcp 171.71.1.1:3612 10.10.10.3:3612 198.133.219.25:80 198.133.219.25:80 tcp 171.71.1.1:3616 10.10.10.4:3616 198.133.219.25:80 198.133.219.25:80 tcp 171.71.1.1:3620 10.10.10.5:3620 198.133.219.25:80 198.133.219.25:80 R1#
We can see that this table indicates that multiple packets have passed through R1 all destined to port 80.
Conclusion
We have looked closely at the anatomy and terminology of Network Address Translation protocol. We have configured Static and Dynamic NAT on Cisco routers. In addition to this, we have learned how to control the Dynamic NAT service using ACLs as well as how to obtain detailed statistics on the NAT process itself.