Address translation is one of the main things keeping the IPv4 still alive. Nowadays it is considered as one of the basic router or firewall functionalities. On SRXs address translation is divided into three main types:
- source NAT – the source address is translated in the initial flow
- destination NAT – the destination address is translated in the initial flow
- static NAT – combines source and destination NAT. The address translated in the initial flow depends on the flow direction (inbound flows have the destination address translated and outbound flows have the source address translated)
For source and destination NAT the port translation can be enabled or disabled through configuration. In static NAT the ports are not translated. Let's look closer at the static NAT and its operation, configuration and troubleshooting.
One of the most common use cases for static NAT is to provide bidirectional reachability for a host (or hosts). In other words the traffic initial on the host is translated to the same IP address as the external hosts use to reach it. The image below illustrates which type of translation is used in static NAT. It depends on the direction of the initiating flow.
Let's review few basic things about static NAT first. Generally within SRX the address translation processing is separated from the security policies. This means the address translation will take place only on traffic permitted by security policy.
Static NAT configuration is located under the [edit security nat static] stanza. The structure is based on rule-sets and rules (same as source and destination NAT). Multiple rule-sets can exist within the configuration. The first step in NAT processing is to find out which rule-set to select and evaluate for the arrived traffic. The matching criteria for the rules-sets is defined using the “from” statement (similarly as in the destination NAT configuration). The allowed values are either routing-instance/s or zone/s or interface/s. In case the traffic is matching the “from” statement from multiple rule-sets the rule-set with the most specific criteria will be selected (interface over zone over routing-instance).
interface ge-0/0/1.0 and ge-1/1/1.0 belong to the zone DMZ and the zone DMZ belongs to the routing-instance R1
from interface ge-0/0/1.0
from zone DMZ
from routing-instance R1
A packet arriving on the interface ge-0/0/1.0 matches the “from” statement of all three rule-sets. However the TEST1 rules-set will be selected because of its most specific criteria (interface). In case the packet arrives on interface ge-1/1/1.0 (matches TEST2 and TEST3 rule-sets) the TEST2 rule-set will be used because its criteria (zone) is more specific than rule-set TEST3 criteria (routing-instance).
Once the rule-set is selected the rules within are evaluated sequentially one by one in the order they appear in the configuration. Each rule contains a match (criteria) and a then (action) statement. The evaluation stops on the 1st rule that has matching criteria and the action from that rule is executed. In case no rule in the whole rule-set produced a match the packet will not be translated.
Static NAT rule-set structure example:
The complete NAT hierarchy can be found here: http://www.juniper.net/techpubs/en_US/junos12.1/topics/reference/statement-hierarchy/security-hierarchy-nat.html
The procedure above describes the destination part of the static NAT, i.e. for the connections initiated towards the host. It takes place similarly as normal destination NAT before the forwarding lookup and security policies evaluation. As a result the SRX uses the new changed IP address for route lookup and not the one from the received packet. Also the security policies have account for the changed destination IP address in their match criteria.
For the connections in the opposite direction, e.g. from the host, the firewall checks if the source address translation should take place at a later stage in the processing. It happens after the route lookup and security policies evaluation (the same place as normal source NAT). So the security policies match criteria have to reflect the original source IP address from the received packet. To device uses again the criteria from static NAT configuration to determine whether the source address should be translated or not. But in this case they are reverted. The “match destination-address” value in the rule must match the source IP of the received packet and the traffic must be routed out as defined in the “from” statement in the rule-set (e.g. through interface or zone or routing-instance).
Please keep in mind on SRXs in case of criteria overlap static NAT takes priority over destination and source NAT.
Because I was curious about the operation and matching of the source part of the static NAT I did put it to a test. The test setup was very simple as shown on the image below.
I used the available options within Junos – CLI operational mode commands and traceoptions – to examine and validate the tests. They provide useful and helpful information about static NAT which makes them quite suitable for troubleshooting too.
For the test simplicity sake the SRX had the default-policy set to “permit”.
The information provided by the “show security flow session” command helped to me to verify if the address translation took place. For purpose of deeper analysis I enabled the traceoptions for the NAT.
The trace file however contained mainly messages related to the processing of the NAT configuration rather than information about the actual data processing. That makes it useful for situations where problems related to the NAT configuration processing and parsing are suspected.
Few example entries from the NAT trace file:
The example messages above indicate:
- no destination NAT configuration is present
- the “from” statement in the static NAT rule-set A1 has changed from “interface ge-0/0/1.3” to “zone untrust”
- only the destination address 126.96.36.199 is defined in the rule A matching criteria and the address should be translated to 172.17.1.2
Security flow traceoptions are much better option to examine or even troubleshoot the NAT processing on the traffic. Below is the configuration I used. I defined packet filter to allow only messages related to the test traffic to go into the trace file.
The test results contain messages from the traceoptions file. For brevity I removed the messages unrelated to NAT processing.
The whole test is divided into 3 scenarios.
“ping 188.8.131.52” initiated from host2 towards the host1. The expected result is the destination address 184.108.40.206 will be translated to 172.17.1.2.
As the session shows the destination address 220.127.116.11 has been translated correctly to 172.17.1.2. Exactly as defined in the configuration. The traceoptions logs contains the string “mip” which is carried over from the ScreenOS. MIP means “mapped IP“ and in ScreenOS it is used for bidirectional translation (same as static NAT in SRXs).
“ping 172.17.2.2” initiated from the host1 towards host2 to test the source address translation (172.17.1.2 to 18.104.22.168).
The device did correctly translate the source IP address from 172.17.1.2 to 22.214.171.124. As indicated by the messages the reverse static NAT (i.e. source address translation) has been found and applied on the traffic.
“ping 172.17.3.2” initiated from the host1 towards host3. In this case no source translation has to be performed because the outgoing interface is different (ge-0/0/3.0) than the interface in the “from” statement (ge-0/0/2.0).
The session details confirmed the expected behavior - no translation took place. No criteria for reverse static NAT has been found even tough the IP 172.17.1.2 is present in the static NAT configuration. The matching failed on the outgoing interface (ge-0/0/3.0 instead of ge-0/0/2.0).
In the scenarios 2 and 3 I did only the tests focused on the reverse static NAT.
Again “ping 172.17.2.2” initiated from the host1 towards host2 to test the source address translation (172.17.1.2 to 126.96.36.199). But this time with different static NAT configuration – the “from” statement lists the zone instead of the interface.
The session above validates that correct source address translation took place.
“ping 172.17.3.2” initiated from the host1 towards host3. In this case no address translation should take place because the outgoing zone does not match the configuration.
As expected no translation took place. Below are the log entries from the flow traceoptions file that confirm it too.
The same as test2 and test4. “ping 172.17.2.2” initiated from the host1 towards host2. Here the static NAT configuration has the routing instance in the “from” statement.
The result is as expected – the source IP address 172.17.1.2 is translated to 188.8.131.52.
Similar as test3 and test5. “ping 172.17.3.2” initiated from the host1 towards host3. In this case no address translation should take place because the outgoing routing instance does not match the static NAT configuration.
Again as expected no translation happens as indicated also by the log messages below (routing instance mismatch is the reason).
The “show security nat static rule“ is an another useful operational mode command for verifying and checking the static NAT. It displays the static NAT details based on the configuration. And generally operational mode commands should be favored in troubleshooting over examining configuration directly. The command output contains in addition the counter showing the number of translation hits for each rule.
The “translation hits” counter represents all sessions translated using the rule regardless of the translation type (source or destination address). To illustrate the behavior I did sent 5 pings that resulted in destination address translation.
The counter value increased by 5.
Then I generated another 5 pings. But this time to invoke source address translation.
The counter value incremented by another 5.
Today it is quite difficult to find a router or a firewall not capable to perform address translation. The translation is typically being performed by the devices closer to or at the network edge. This post focuses on the static NAT functionality available on the SRX devices. Brief description and configuration overview are provided together with few test cases and their results. The options used for presenting the test results can serve very well also for static NAT troubleshooting purposes.