Related Documentation
- J Series
- Network Address Translation Overview for JSF
- Configuring Addresses and Ports for Use in NAT Rules
- Configuring NAT Rule Sets
- M Series
- Network Address Translation Overview for JSF
- Configuring Addresses and Ports for Use in NAT Rules
- Configuring NAT Rule Sets
- MX Series
- Network Address Translation Overview for JSF
- Configuring Addresses and Ports for Use in NAT Rules
- Configuring NAT Rule Sets
- T Series
- Network Address Translation Overview for JSF
- Configuring Addresses and Ports for Use in NAT Rules
- Configuring NAT Rule Sets
Configuring NAT Rules
To configure a NAT rule, include the rule rule-name statement at the [edit services nat] hierarchy level:
Each rule must include a match-direction statement that specifies the direction in which the match is applied.
In addition, each NAT rule consists of a set of terms, similar to a firewall filter. A term consists of the following:
- from statement—Specifies the match conditions and applications that are included and excluded.
- then statement—Specifies the actions and action modifiers to be performed by the router software.
The following sections explain how to configure the components of NAT rules:
Configuring Match Direction for NAT Rules
Each rule must include a match-direction statement that specifies the direction in which the match is applied. To configure where the match is applied, include the match-direction statement at the [edit services nat rule rule-name] hierarchy level:
The match direction is used with respect to the traffic flow through the Multiservices PIC. When a packet is sent to the PIC, direction information is carried along with it. The criteria for determining packet direction is as follows:
- With an interface service set, packet direction is determined by whether a packet is entering or leaving the interface on which the service set is applied.
- With a next-hop service set, packet direction is determined by the interface used to route the packet to the Multiservices PIC. If the inside interface is used to route the packet, the packet direction is input. If the outside interface is used to direct the packet to the PIC, the packet direction is output..
- On the Multiservices PIC, a flow lookup is performed. If no flow is found, rule processing is performed. All rules in the service set are considered. During rule processing, the packet direction is compared against rule directions. Only rules with direction information that matches the packet direction are considered.
Configuring Match Conditions in NAT Rules
To configure NAT match conditions, include the from statement at the [edit services nat rule rule-name term term-name] hierarchy level:
To configure traditional NAT, you can use the destination address,
a range of destination addresses, the source address, or a range of
source addresses as a match condition, in the same way that you would
configure a firewall filter; for more information, see the Junos OS Policy Framework Configuration Guide
.
Alternatively, you can specify a list of source or destination prefixes by including the prefix-list statement at the [edit policy-options] hierarchy level and then including either the destination-prefix-list or source-prefix-list statement in the NAT rule.
![]() | Note: If you configure a service set with a destination NAT rule, the address configured in the from condition must be translated. If the service set is deleted from the interface and you want traffic destined to the address to be forwarded without translation, you must explicitly deactivate either the service set or the NAT rule within the service set. |
You can include application protocol definitions that you have configured at the [edit applications] hierarchy level:
- To apply one or more specific application protocol definitions, include the applications statement at the [edit services nat rule rule-name term term-name from] hierarchy level.
- To apply one or more sets of application protocol definitions that you have defined, include the application-sets statement at the [edit services nat rule rule-name term term-name from] hierarchy level.
![]() | Note: If you include one of the statements that specifies application protocols, the router derives port and protocol information from the corresponding configuration at the [edit applications] hierarchy level; you cannot specify these properties as match conditions. When matched rules include more than one ALG, the more specific ALG takes effect; for example, if the stateful firewall rule includes TCP and the NAT rule includes FTP, the NAT rule takes precedence. You can configure ALGs for ICMP and trace route under stateful firewall and NAT. By default, NAT can restore IP, TCP, and UDP headers embedded in the payload of ICMP error messages. You can include the protocol tcp and protocol udp statements with the application statement for NAT configurations. |
Configuring Actions in NAT Rules
To configure NAT actions, include the then statement at the [edit services nat rule rule-name term term-name] hierarchy level:
The no-translation statement allows you to specify addresses that you want to be excluded from NAT.
The syslog statement enables you to record an alert in the system logging facility.
The destination-pool, destination-prefix, source-pool, and source-prefix statements specify addressing information that you define by including the pool statement at the [edit services nat] hierarchy level; for more information, see Configuring Addresses and Ports for Use in NAT Rules.
The translation-type statement specifies the type of network address translation used for source or destination traffic. Choices are basic-nat44, dynamic-nat44, napt44, or dnat-44, which are explained in the following list. For more information, see Network Address Translation Overview for JSF.
![]() | Note: The translation types basic-nat44, dynamic-nat44, napt44, and dnat-44 are used for configuring NAT in IPv4 networks. Apart from these translation types, Junos OS also supports the translation types basic-nat-pt, basic-nat66, napt-66, napt-pt, and stateful-nat64. These translation types are used for configuring NAT in IPv6 networks. Because Junos Services Framework (JSF) does not support configuring NAT in IPv6 networks, these translation types are not mentioned here. |
- basic-nat44—Implement static translation
of source IP addresses without port mapping. You must configure the from destination-address statement in the match condition for
the rule. The size of the address range specified in the statement
must be the same or smaller than the destination pool. You must specify
either a destination-pool or a destination-prefix. The referenced pool can contain multiple addresses but no port configuration.

Note: In an interface service set, all packets destined for the destination-address specified in the match condition are automatically routed to the services PIC, even if no service set is associated with the interface.
- dynamic-nat44—Implement dynamic translation
of source IP addresses without port mapping. You must specify a source-pool name. The referenced pool must include an address configuration (for address-only translation).
The dynamic-nat44 option supports translating up to 64,000 addresses to a smaller size pool. The requests from the source address range are assigned to the addresses in the pool until the pool is used up, and any additional requests are rejected. A NAT address assigned to a host is used for all concurrent sessions from that host. The address is released to the pool only after all the sessions for that host expire. This feature enables the router to share a few public IP addresses between several private hosts. Since all the private hosts might not simultaneously create sessions, they can share a few public IP addresses.
- napt44—Implement dynamic address translation
for destination traffic with port mapping. You must specify a source-pool name. The referenced pool must include a port configuration
(for NAPT). The napt44 option supports translating up to
32 addresses to a smaller size pool.
If you specify port automatic or a port range, NAPT is used. If a port is not defined, the port value defaults to 1.
- dnat-44—Implement static translation of destination IP addresses without port mapping. The size of the pool address space must be greater than or equal to the source address space. You must specify a source-pool name. The referenced pool can contain multiple addresses, ranges, or prefixes, as long as the number of NAT addresses in the pool is larger than the number of source addresses in the from statement. You must include exactly one source-address value at the [edit services nat rule rule-name term term-name from] hierarchy level; if it is a prefix, the size must be less than or equal to the pool prefix size. Any addresses in the pool that are not matched in the source-address value remain unused, because a pool cannot be shared among multiple terms or rules.
![]() | Note: When configuring NAT, if any traffic is destined for the following addresses and does not match a NAT flow or NAT rule, the traffic is dropped:
|
For more information on NAT methods, see RFC 2663, IP Network Address Translator (NAT) Terminology and Considerations.
Related Documentation
- J Series
- Network Address Translation Overview for JSF
- Configuring Addresses and Ports for Use in NAT Rules
- Configuring NAT Rule Sets
- M Series
- Network Address Translation Overview for JSF
- Configuring Addresses and Ports for Use in NAT Rules
- Configuring NAT Rule Sets
- MX Series
- Network Address Translation Overview for JSF
- Configuring Addresses and Ports for Use in NAT Rules
- Configuring NAT Rule Sets
- T Series
- Network Address Translation Overview for JSF
- Configuring Addresses and Ports for Use in NAT Rules
- Configuring NAT Rule Sets

