[Day 11] 4. Dynamic NAT
In Dynamic NAT, there is a many-to-many mapping between private IP addresses and a pool of public IP addresses. Unlike static NAT, where a specific private IP is permanently mapped to a public IP, Dynamic NAT automatically assigns a public IP from a predefined pool to internal devices when they need to communicate outside the network. Once the internal device no longer needs the public IP, that IP can be returned to the pool for other internal devices to use.
This method is ideal when you have more internal devices than available public IP addresses but don't need them all to be online simultaneously.
How Dynamic NAT works?
-
Access Control List (ACL) to Define Inside Addresses: First, you define which internal (private) IP addresses will be translated to the external (public) IP addresses. This is done using an Access Control List (ACL).
A(config)#access-list 15 permit 172.16.10.0 0.0.0.255- ACL 15 permits all devices in the range (a /24 network) to be translated.
172.16.10.0 - 172.16.10.255 - The wildcard mask means the last octet can vary (i.e., all addresses from
0.0.0.255to172.16.10.0are included).172.16.10.255
- ACL 15 permits all devices in the range
-
Define the NAT Pool: You create a pool of public IP addresses from which NAT will dynamically assign public IPs to the private devices. Each device will be dynamically assigned one of these public IPs when it initiates a connection to the outside world.
A(config)#ip nat pool sunbeam 202.208.220.1 202.208.220.6 netmask 255.255.255.248- This command defines a pool called that includes the public IPs
sunbeamto202.208.220.1.202.208.220.6 - The netmask indicates a subnet that supports 6 usable IP addresses.
255.255.255.248 - Alternatively, you can use the instead of
prefixlength 29:netmask 255.255.255.248
A(config)#ip nat pool sunbeam 202.208.220.1 202.208.220.6 prefix-length 29- Both options result in the same pool size.
- This command defines a pool called
-
Link the ACL to the NAT Pool: You then link the access list (which defines the inside local addresses) to the NAT pool (which defines the inside global addresses). This tells the router which internal addresses to translate and from which pool to assign public IPs.
A(config)#ip nat inside source list 15 pool sunbeam- This command tells the router to dynamically translate the addresses permitted by ACL 15 (the private network ) to one of the public IPs from the sunbeam pool (
172.16.10.0/24).202.208.220.1 - 202.208.220.6
- This command tells the router to dynamically translate the addresses permitted by ACL 15 (the private network
Steps to Complete Dynamic NAT Setup:
-
Define Interfaces: As with Static NAT, you must specify the inside and outside interfaces:
A(config)#int g0/0A(config-if)#ip nat inside- is the inside interface (facing the private network).
g0/0
A(config)#int g0/1A(config-if)#ip nat outside- is the outside interface (facing the public network, i.e., the internet).
g0/1
NAT Table Behavior:
With Dynamic NAT, the NAT table is dynamically populated as internal devices initiate connections. Here’s how the table would look in real-time usage:
|Inside Local|Inside Global| |---|---| |172.16.10.2|202.208.220.1| |172.16.10.3|202.208.220.2| |172.16.10.4|202.208.220.3|
- When an internal device (e.g., ) initiates a connection, it's dynamically assigned an available public IP (e.g.,
172.16.10.2).202.208.220.1 - If all public IPs are assigned and more devices request external communication, those devices will have to wait until an IP is freed up from the pool.
Advantages of Dynamic NAT:
- Efficient IP Usage: It allows efficient use of a limited pool of public IPs. As not all devices need to communicate at the same time, the same public IP can be reused when available.
- Simple Configuration: Easier to configure when compared to Static NAT, as mappings are dynamically assigned instead of fixed.
- Flexible: Internal devices can be dynamically assigned any available public IP from the pool, providing more flexibility in managing connections.
- Tough to get hacked: As the IPs are changed frequently, hacker has to guess the currently allocated IP.
Read Next
[Day 11] 5. Dynamic NAT with Overload
**Definition:** Dynamic NAT with overload, also known as **Port Address Translation (PAT)**, allows multiple internal IP addresses to share a single...
[Day 11] 6. IPv6
### **Overview** - **Address Size:** IPv6 addresses are **128 bits long (16 bytes)**, compared to IPv4 addresses, which are only **32 bits (...