Forum Discussion
Maxim_Taskov_90
Nimbostratus
Jun 05, 2008SNAT Based on Source and Destination
I hope you can help ... thanks.
I am trying to apply conditional SNAT based on source and destination for any service otherwise leave them alone and allow the static NAT to take effect. What I did is ...
NOTE: The client servers normally have static NATs applied.
1. Created Forwarding (IP) VIP available only on the VLAN where the client servers reside with the following configuration:
virtual vsANY-NodeNet
destination any:any
disable
ip forward
rule snat_rule
vlans NodeNet enable
NOTE: NodeNet is the VLAN where the client servers reside.
2. Created an iRule labeled 'snat_rule' as follows:
when CLIENT_ACCEPTED {
if {[matchclass IP::local_addr eq $::the_destination_ip] and [matchclass IP::client_addr eq $::the_source_ip]} {
snat 10.10.1.1
} else {
snat none i tried using 'forward' here too
}
}
2a. I tried this too:
when CLIENT_ACCEPTED {
if {[matchclass IP::local_addr eq $::the_destination_ip]} {
snat 10.10.1.1
} else {
snat none i tried using 'forward' here too
}
}
The result was that all traffic matched the rule and everything started failing, because traffic destined for the internal network is subjected to specific firewall rules, which include source, destination and port as the rule parameters. After this new iRule, the server static NATs are not applied rather all get the 10.10.1.1 SNAT, which obviously is not in any of the firewall rules.
Technically the iRule could be based on matching the destination only but I included the source too as I thought that it will be less invasive/more efficient the more specific it is. Was I correct?
HELP !!!
- hoolio
Cirrostratus
The VIP is showing disabled in your config snippet--I assume it was enabled when you were testing? Also, the IP::client_addr and IP::local_addr commands need to be enclosed in square braces in order to be executed. I would think that the conditional should have failed and no SNAT would have been used.when CLIENT_ACCEPTED { if {[matchclass [IP::local_addr] equals $::the_destination_ip] and [matchclass [IP::client_addr] equals $::the_source_ip]} { log local0. "[IP::client_addr]: using SNAT for [IP::local_addr]" snat 10.10.1.1 } else { log local0. "[IP::client_addr]: not using SNAT for [IP::local_addr]" snat none } }
- Maxim_Taskov_90
Nimbostratus
Thanks for the reply Aaron. - hoolio
Cirrostratus
You're correct... the TCP:: command won't work on a forwarding VIP. Can you take out [TCP::client_port] from the rule as listed above? - Maxim_Taskov_90
Nimbostratus
I took out the '[TCP::client_port]' statement when I tried it the first time as soon as I got the compile error. I tried it again and same behavior, outbound traffic is failing and nothing in th e'ltm' log. - hoolio
Cirrostratus
Can you add a log statement to the SNAT none case? And can you post the contents of the class? You can anonymize the networks if they're public. You can list the class contents using: - Maxim_Taskov_90
Nimbostratus
I added the log statement and still nothing logged ... and definitely still failing. - hoolio
Cirrostratus
If nothing gets logged with both conditions in the rule being logged, I'd guess that either the clients aren't on the nodenet VLAN (which you've said they are) or the NAT is taking precedence over/conflicting with the forwarding VIP. Can you try deleting the NAT for one of the servers and retest? - Maxim_Taskov_90
Nimbostratus
The servers are definitely members of the NodeNet. - hoolio
Cirrostratus
I was suggesting to delete the NAT as a way to test if it's being used for the outbound connection instead of the wildcard VIP. To replace the NAT functionality (at least the inbound portion) can you remove the NAT for one server, add a new VIP on the NAT address on port 0 pointing to a pool containing the server also on port 0? You can then retest the outbound connection from the server through the wildcard VIP with the iRule without the NAT impacting the traffic flow. - JRahm
Admin
The LTM does not track connections for NAT addresses, so they cannot be shared with virtual servers or SNAT's. As Aaron is suggesting, you'll need to revise your inbound flow configuration to achieve your goals.
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects