Deterministic NAT
Deterministic NAPT Overview
You can configure deterministic NAPT44 to ensure that the original source IPv4 address and port always map to the same post-NAT IPv4 address and port range, and that the reverse mapping of a given translated external IPv4 address and port are always mapped to the same internal IPv4 address. You can configure deterministic NAPT64 to ensure that the original source IPv6 address and port always map to the same post-NAT IPv4 address and port range, and that the reverse mapping of a given translated external IPv4 address and port are always mapped to the same internal IPv6 address. Deterministic NAPT uses an algorithm-based allocation of blocks of destination ports.
Deterministic NAPT44 is supported on MX series routers with MS-DPCs and on M Series routers with MS-100, MS-400, and MS-500 MultiServices PICS. Deterministic NAPT 44 is supported for MS-MPCs and MS-MICs starting in Junos OS release 17.3R1, in Junos OS release 14.2R7 and later 14.2 releases, and in Junos OS release 15.1R3 and later 15.1 releases. Starting in Junos OS Release 17.4R1, deterministic NAPT64 is supported on the MS-MPC and MS-MIC.
If the source
address in the from
clause of a deterministic NAPT rule
does not have a prefix of /32, the network and broadcast addresses
in the source address range are not translated unless you configure include-boundary-addresses
.
For detailed information on how to configure deterministic NAPT, see Configuring Deterministic NAPT.
- Benefits of Deterministic NAPT
- Understanding Deterministic NAPT Algorithms
- Deterministic NAPT Restrictions
Benefits of Deterministic NAPT
Eliminates the need for address translation logging because an IP address is always mapped to the same external IP address and port range, and the reverse mapping of a given translated external IP address and port are always mapped to the same internal IP address.
Understanding Deterministic NAPT Algorithms
The effectiveness of your implementation of deterministic NAPT
depends on your analysis of your subscriber requirements. The block
size you provide indicates how many ports will be made available for
each incoming subscriber address from the range in the from
clause specified in the applicable NAT rule. The allocation algorithm
computes an offset value to determine the outgoing IP address and
port. A reverse algorithm is used to derive the originating subscriber
address.
In order to track subscribers without using logs, an ISP must use a reverse algorithm to derive a subscriber (source) addresses from a translated address.
The following variables are used in forward calculation (private subscriber IP address to public IP address) and reverse calculation (public IP address to private subscriber IP address):
Pr_Prefix—Any pre-NAT IPv4 subscriber address.
Pr_Port—Any pre-NAT protocol port.
Block_Size—Number of ports configured to be available for each Pr_Prefix.
If
block-size
is configured as zero, the method for computing the block size is computed as follows:block-size = int(64512/ceil[(Nr_Addr_PR_Prefix/Nr_Addr_PU_Prefix)])
where 64512 is the maximum available port range per public IP address.
Base_PR_Prefix—First usable pre-NAT IPv4 subscriber address in a
from
clause of the NAT rule.Base_PU_Prefix—First usable post-NAT IPv4 subscriber address configured in the NAT pool.
Pu_Port_Range_Start—First usable post-NAT port. This is 1024.
Pr_Offset—The offset of the pre-NAT IP address that is being translated from the first usable pre-NAT IPv4 subscriber address in a
from
clause of the NAT rule. PR_Offset = Pr_Prefix – Base_Pr_Prefix.PR_Port_Offset—Offset of the pre-NAT IP address multiplied by the block size. PR_Port_Offset = Pr_Offset * Block_Size.
Pu_Prefix—Post-NAT address for a given Pr_Prefix.
Pu_Start_Port—Post-NAT start port for a flow from a given Pr_Prefix
Pu_Actual_Port—Post-NAT port seen on a reverse flow.
Nr_Addr_PR_Prefix — Number of usable pre-NAT IPv4 subscriber addresses in a
from
clause clause of the NAT rule.Nr_Addr_PU_Prefix — Number of usable post-NAT IPv4 addresses configured in the NAT pool.
Rounded_Port_Range_Per_IP — Number of ports available for each post-NAT IP address. Rounded_Port_Range_Per_IP = ceil[(Nr_Addr_PR_Prefix/Nr_Addr_PU_Prefix)] * Block_Size.
Pu_Offset—Offset of the post-NAT IP address from the first usable post-NAT address. Pu_Offset = Pu_Prefix – Base_Pu_Prefix.
Pu_Port_Offset— Offset of the post-NAT port from 1024 added to the product of the offset of the post-NAT IP address and the number of ports available for each post-NAT IP address. Pu_Port_Offset = (Pu_Offset * Rounded_Port_Range_Per_IP) + (Pu_Actual_Port – Pu_Port_Range_Start).
Algorithm Usage–Assume the following configuration:
services { nat { pool src-pool { address-range low 32.32.32.1 high 32.32.32.254; port { automatic { random-allocation; } deterministic-block-allocation { block-size 249; } } } rule det-nat { match-direction input; term t1 { from { source-address { 10.1.0.0/16; } } then { translated { source-pool src-pool; translation-type { deterministic-napt44; } } } }
Forward Translation
Pr_Offset = Pr_Prefix – Base_Pr_Prefix
Pr_Port_Offset = Pr_Offset * Block_Size
Rounded_Port_Range_Per_IP = ceil[(Nr_Addr_PR_Prefix/Nr_Addr_PU_Prefix)] * Block_Size
Pu_Prefix = Base_Public_Prefix + floor(Pr_Port_Offset / Rounded_Port_Range_Per_IP)
Pu_Start_Port = Pu_Port_Range_Start + (Pr_Port_Offset % Rounded_Port_Range_Per_IP)
Using the sample configuration and assuming a subscriber flow sourced from 10.1.1.250:5000:
Pr_Offset = 10.1.1.250 – 10.1.0.1 = 505
Pr_Port_Offset = 505 * 249 = 125,745
Rounded_Port_Range_Per_IP = ceil[(65, 533/254)] * 249 = 259 * 249 = 64,491
Pu_Prefix = 32.32.32.1 + floor(125,745 /64,491) = 32.32.32.1 +1 =32.32.32.2
Pu_Start_Port = 1,024 + (125,745 % 64,491) = 62278
10.1.1.250 is translated to 32.32.32.2.
The starting port is 62278. There are 249 ports available to the subscriber based on the configured block size. The available port range spans ports 62278 through 62526 (inclusive).
The specific flow 10.1.1.250:5000 randomly assigns any of the ports in its range because random allocation was specified.
Reverse Translation
Pu_Offset = Pu_Prefix – Base_Pu_Prefix
Pu_Port_Offset = (Pu_Offset * Rounded_Port_Range_Per_IP) + (Pu_Actual_Port – Pu_Port_Range_Start)
Subscriber_IP = Base_Pr_Prefix + floor(Pu_Port_Offset / Block_Size)
The reverse translation is determined as follows. Assume a flow returning to 32.32.32.2:62278.
Pu_Offset = 32.32.32.2 – 32.32.32.1 = 1
Pu_Port_Offset = (1 * 64,491) + (62,280 - 1024) = 125,747
Subscriber_IP = 10.1.0.1 + floor(125,747 / 249) = 10.1.0.1 + 505 = 10.1.1.250
Note:In reverse translation, only the original private IP address can be derived, and not the original port in use. This is sufficiently granular for law enforcement requirements.
When you have configured deterministic NAPT, you can use the show services nat deterministic-nat internal-host
and show services nat deterministic-nat
nat-port-block
commands to show forward and reverse
mapping. However, mappings will change if you reconfigure your deterministic
port block allocation block size or the from
clause for
your NAT rule. In order to provide historical information on mappings,
we recommend that you write scripts that can show specific mappings
for prior configurations.
Deterministic NAPT Restrictions
When you configure deterministic NAPT, you must be aware of the following restrictions. Violation of any restriction results in a commit error. The restrictions and their error messages are shown in Table 1.
Restriction |
Error Message |
---|---|
The total number of deterministic NAT blocks must be greater
than or equal to the |
Number of addresses and port blocks combination in the NAT pool is less than number of addresses in 'from' clause |
IPv6 addresses should not be used in deterministic NAT pool/from clause. |
Invalid IP address in pool p1 with translation type deterministic-napt44 OR There is already a range configured with v4 address range |
The |
With translation-type deterministic-napt44, same 'from' address/range should be configured if pool is shared by multiple rules or terms |
The |
With translation-type deterministic-napt44, at least one non-except 'from' address/range should be configured. error: configuration check-out failed |
There should not be address overlap between |
overlapping address, in the 'from' clause between 'except' entries |
Addresses in a NAT pool used for deterministic NAPT should not overlap with the addresses in any other NAT pool. |
NAT pool det-nat-pool1 overlaps with det-nat-pool used by service set sset_det-nat error: configuration check-out failed |
A deterministic NAT pool cannot be used with other translation types. In addition, a deterministic NAT pool cannot be used in both deterministic NAPT44 and deterministic NAPT64 NAT rules. |
Deterministic NAT pool cannot be used with other translation-types |
Deterministic NAPT44 must use a source pool with deterministic-port-block-allocation configuration. |
Deterministic NAPT44 must use a source pool with deterministic-port-block-allocation configuration |
If |
Address allocation round-robin is not needed with translation-type deterministic-napt44 |
The total number of IP addresses assigned to a deterministic NAT pool should be less than or equal to 224 (16777216). |
Number of addresses in pool with deterministic-napt44 translation are limited to at most 16777216(2^24) |
Configuring Deterministic NAPT
Deterministic NAPT44 is supported on MX series routers with MS-DPCs and on M Series routers with MS-100, MS-400, and MS-500 MultiServices PICS. Deterministic NAPT44 is supported for MS-MPCs and MS-MICs starting in Junos OS release 17.3R1, in Junos OS release 14.2R7 and later 14.2 releases, and in Junos OS release 15.1R3 and later 15.1 releases. Starting in Junos OS Release 17.4R1, deterministic NAPT64 is supported on the MS-MPC and MS-MIC.
To configure deterministic NAPT, perform the following:
- Configuring the NAT Pool for Deterministic NAPT
- Configuring the NAT Rule for Deterministic NAPT
- Configuring the Service Set for Deterministic NAT
Configuring the NAT Pool for Deterministic NAPT
To configure the NAT pool for deterministic NAPT:
See Also
Configuring the NAT Rule for Deterministic NAPT
To configure the NAT rule for deterministic NAPT:
Configuring the Service Set for Deterministic NAT
To configure the service set for deterministic NAPT:
Change History Table
Feature support is determined by the platform and release you are using. Use Feature Explorer to determine if a feature is supported on your platform.
sequential
option is introduced to
enable you to configure sequential allocation of ports.