This article provides instructions on how to set up NAT hairpinning on any SRX series device (supported as of Junos OS 11.2).
When a public IP is used to gain access to a server in a private, internal network, the traffic will attempt to go out to the internet. In order to reach the server, the traffic will need to be redirected to the correct location. A useful technique for accessing an internal server using a public IP is NAT hairpinning.
The cause is shown in the scenario below. If the Destination NAT is used in this scenario:
NAT hairpinning is a useful technique for accessing an internal server using a public IP.
Both the source and destination IP addresses need to be modified so each device sees the traffic flowing to and from the correct locations. This allows the return traffic to return through the SRX, and the client to receive the packets from the correct IP.
Make sure a security policy is configured which will allow intra-zone communication in the default zone.
set security nat source rule-set hairpin from zone default set security nat source rule-set hairpin to zone default set security nat source rule-set hairpin rule hairpin-source match source-address 10.0.0.0/24 set security nat source rule-set hairpin rule hairpin-source then source-nat interface set security nat destination pool server address 10.0.0.15/32 set security nat destination rule-set hairpin from zone default set security nat destination rule-set hairpin rule hairpin-destination match destination-address 155.100.1.1/32 set security nat destination rule-set hairpin rule hairpin-destination then destination-nat pool server set security policies from-zone default to-zone default policy INTRA-default match source-address any set security policies from-zone default to-zone default policy INTRA-default match destination-address any set security policies from-zone default to-zone default policy INTRA-default match application any set security policies from-zone default to-zone default policy INTRA-default then permit
2020-07-18: Article reviewed for accuracy; made minor non-technical edits. 2022-02-25: Fixed typo in cause section.