Destination NAT happens prior to source NAT in Junos flow. What if the translated destination is the same for two destination NAT rules? This article discusses how to use routing instances to meet such a requirement. It also provides the translated destination in match condition for source NAT.
Two IP address are destination NATed to the same IP address. For example, IP addresses are: 192.168.69.2 and 192.168.69.3 which are getting NATed to the IP address 192.168.70.2. When a user accesses the IP address 192.168.69.2, we want to NAT the traffic to 192.168.71.1 and when a user accesses the IP address 192.168.69.3, the traffic should be NATed to 192.168.72.1
To summarize the requirement:
When accessing 192.168.69.2:
Change the destination IP to 192.168.70.2 and source IP to 192.168.71.1
When accessing 192.168.69.3
Change the destination IP to 192.168.70.2 and source IP to 192.168.72.1
If the packets are entering the device through the Untrust zone and after NAT going to the Trust zone, the following destination NAT configuration can be used:
security {
nat {
destination {
pool poolA {
address 192.168.70.2/32;
}
rule-set from-Untrust {
from zone Untrust;
rule r1 {
match {
destination-address 192.168.69.2/32;
}
then {
destination-nat pool poolA;
}
}
rule r2 {
match {
destination-address 192.168.69.3/32;
}
then {
destination-nat pool poolA;
}
}
}
}
}
}
Define the source NAT rule as per the requirement as follows:
security {
nat {
source {
pool poolA {
address {
192.168.71.1/32;
}
}
pool poolB {
address {
192.168.72.1/32;
}
}
rule-set Untrust-to-Trust {
from zone Untrust;
to zone Trust;
rule r1 {
match {
destination-address 192.168.70.2/32;
}
then {
source-nat {
pool {
poolA;
}
}
}
}
rule r2 {
match {
destination-address 192.168.70.2/32;
}
then {
source-nat {
pool {
poolB;
}
}
}
}
}
}
}
}
Here only rule r1 will be hit as both rules have same context and match condition.