Network Address Translation · Topic 1 of 3

Source NAT

Learn SRX source NAT for JNCIA-SEC: rule-sets with from and to context, interface and pool-based translation, port translation, proxy ARP and checks.

  • 6 min
  • Includes a diagram
In a nutshell
  • Source NAT changes the source address and usually the source port.
  • It is configured under security nat source, with rule-sets that need both from and to context.
  • Context can be zone, interface or routing-instance; interface is the most specific.

What it is

Source NAT changes the source IP address, and usually the source port, of packets leaving the SRX. Its most common job is letting many hosts with private addresses reach the internet through one or a few public addresses.

The SRX records the translation in the session table. Return traffic matches the session, so the device puts the original address back without any extra rule.

Host 10.1.1.10trust to untrustSRXsource NATnew source 203.0.113.1Internet serverInternet serverreplySRXsession matchoriginal address restoredHost 10.1.1.10

How it works

Rule-sets, rules and context

Source NAT is configured under [edit security nat source]. Rules live inside a rule-set, and the rule-set sets the context: where the traffic comes from and where it goes.

PartOptions
fromzone, interface or routing-instance
tozone, interface or routing-instance
matchsource-address, destination-address, and optionally ports, protocol or application
then source-natinterface, pool <name> or off

A source NAT rule-set needs both a from and a to context. Inside a rule-set, rules are checked top to bottom and the first match wins.

When several rule-sets could match, the most specific context is used: interface beats zone, and zone beats routing-instance.

Interface-based source NAT

Hosts 10.1.1.10 and 10.1.1.11 both use source port 50001. The SRX translates both sources to its egress interface address 203.0.113.1 with different source ports, which is source-nat interface with port address translation. The simplest form translates the source to the IP address of the egress interface. No pool is needed.

user@srx# set security nat source rule-set TRUST-TO-UNTRUST from zone trust
user@srx# set security nat source rule-set TRUST-TO-UNTRUST to zone untrust
user@srx# set security nat source rule-set TRUST-TO-UNTRUST rule ALL-HOSTS match source-address 10.1.1.0/24
user@srx# set security nat source rule-set TRUST-TO-UNTRUST rule ALL-HOSTS match destination-address 0.0.0.0/0
user@srx# set security nat source rule-set TRUST-TO-UNTRUST rule ALL-HOSTS then source-nat interface

Interface-based source NAT always uses port address translation (PAT). Many hosts share one address, and the SRX tells their sessions apart by giving each one a different source port.

Pool-based source NAT

For more control, define a source pool of public addresses and point the rule at it.

security {
    nat {
        source {
            pool PUBLIC-POOL {
                address {
                    203.0.113.10/32 to 203.0.113.20/32;
                }
            }
            rule-set TRUST-TO-UNTRUST {
                from zone trust;
                to zone untrust;
                rule ALL-HOSTS {
                    match {
                        source-address 10.1.1.0/24;
                        destination-address 0.0.0.0/0;
                    }
                    then {
                        source-nat {
                            pool {
                                PUBLIC-POOL;
                            }
                        }
                    }
                }
            }
        }
    }
}

A pool translates ports by default, just like interface NAT. With port no-translation under the pool, each session takes its own address from the pool and keeps its original port. The pool can then run out, because only as many hosts as there are pool addresses can be translated at once.

Interface-basedPool-based
Translated addressEgress interface addressAddresses from a named pool
Port translationAlwaysOn by default; can be turned off
Pool configurationNonesecurity nat source pool
Proxy ARPNot neededNeeded when pool addresses share the egress subnet

Excluding traffic with source-nat off

then source-nat off means "match this traffic but do not translate it". Place such a rule above a broader rule, for example to keep traffic to a partner VPN network untranslated while everything else is translated.

Proxy ARP

If the pool addresses are in the same subnet as the egress interface but are not the interface's own address, the upstream router sends ARP requests for them. The SRX does not answer unless you configure proxy ARP.

user@srx# set security nat proxy-arp interface ge-0/0/0.0 address 203.0.113.10/32 to 203.0.113.20/32

Interface-based source NAT never needs proxy ARP, because the interface already owns its address.

Where source NAT sits in the flow

Source NAT is applied after the route lookup and after the security policy lookup. The security policy therefore matches the original, private source address.

Packetsource 10.1.1.10Route lookupPolicymatches 10.1.1.10permitSource NATsource 203.0.113.1

NAT never replaces a policy. Traffic from trust to untrust still needs a policy that permits it, and that policy uses the internal addresses or address book entries.

Checking source NAT

Command (operational mode)Shows
show security nat source summaryPools, rule-sets and their counts
show security nat source rule allEach rule, its context and translation hits
show security nat source pool allPool addresses, port translation and usage
show security flow sessionLive sessions with the original and translated addresses

In a session, the In line shows the original source, and the Out line shows the reply wing toward the translated address, so you can read the translation directly.

Exam tip

When translation does not happen, check show security nat source rule all first. A rule with zero translation hits usually has the wrong zones in its context or a match condition that does not cover the host.

Common mistakes

Writing the policy with the public address. Source NAT happens after policy lookup, so the policy matches the private source address.

Leaving out the to context. A source NAT rule-set needs both from and to.

Forgetting proxy ARP for a pool. If pool addresses are in the egress interface subnet, the upstream router cannot reach them without proxy ARP, and return traffic is lost.

Putting a broad rule first. Rules are first match. A rule matching 0.0.0.0/0 above a source-nat off rule means the exception is never used.

Watch out

port no-translation turns many-to-few NAT into one address per session. With more active hosts than pool addresses, new sessions fail to get a translation.

What to remember for the exam

  • Source NAT changes the source address and usually the source port.
  • It is configured under security nat source, with rule-sets that need both from and to context.
  • Context can be zone, interface or routing-instance; interface is the most specific.
  • Rules are first match within a rule-set.
  • Actions: source-nat interface, source-nat pool <name>, source-nat off.
  • Interface-based source NAT always uses PAT; pool-based uses PAT by default.
  • Source NAT is applied after the policy lookup, so policies use the original source address.
  • Proxy ARP is needed for pool addresses in the egress subnet, never for interface-based NAT.

Check yourself

  • A host at 10.1.1.10 is translated to 203.0.113.1 by source NAT. Which source address must the trust to untrust policy match?

    The original address 10.1.1.10, because source NAT is applied after the policy lookup.

  • How does the SRX keep apart 200 inside hosts that share one interface address?

    Interface-based source NAT uses port address translation, giving each session a different source port.

  • Pool addresses 203.0.113.10 to 203.0.113.20 are in the egress interface subnet, and return traffic never arrives. What is missing?

    Proxy ARP for those addresses on the egress interface, so the SRX answers ARP requests for them.

Topic 1 of 3 in Network Address Translation

Test yourself on Network Address Translation

The full Juniper JNCIA-SEC JN0-232 question bank has 658 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by Juniper. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.