Forum Discussion
Manuel_Gabaldon
Nimbostratus
Apr 29, 2008Outbound SNAT matching inbound Virtual Servers
Hi,
Our customers are always asking us for a load balancing solution that provides bi-directional correspondence between a virtual server address (inbound) and the SNAT address being applied to the real servers belonging to its pool when going outside through our wildcard outgoing virtual server.
We've been configuring two objects for every virtual server that our customer asks us to define:
- A virtual server listening on the public interface (i.e. 4.4.4.4:80) with a virtual server pool (i.e 2.2.2.10:80 and 2.2.2.11:80)
- An SNAT that translates traffic coming from the pool (2.2.2.10 and 2.2.2.11) and replaces source IP with the virtual server address (4.4.4.4)
I'm trying to figure out a dynamic way of implementing the SNAT with an iRule, by querying the configuration, but I consider it unelegant. I think it could be done by querying if which pool belongs the source IP to, and then querying which virtual server belongs to, and then apply the SNAT, but I can't find a way of doing it.
Has anybody tried to address this issue with an iRule?
Thanks in advance.
- The_Bhattman
Nimbostratus
You could create a simple irule applied to the virtual that is handling your outbound connections.class dg_internal { 2.2.2.10/32 2.2.2.11/32 }
when CLIENT_ACCEPTED { if { [matchclass [IP::client_addr] equals $::dg_internal]} { snat automap } }
- Manuel_Gabaldon
Nimbostratus
Yeah, I've already thought about that solution, but it's not exactly what I'm looking for. - Deb_Allen_18Historic F5 AccountThere really is no way in iRules to enumerate all pools and their members. You can get the list of members of a known pool name using the "active_members" command with the "-list" parameter. (Click here)
- Manuel_Gabaldon
Nimbostratus
Yeah, certainly there isn't a good way. I've thought of another way, however. What about using the Universal Persistence Table as a way of creating these entries dynamically? - Deb_Allen_18Historic F5 AccountWell, I did write a rule that did something like that for pool member selection to push outbound connections over the same proxy the client is already using for an inbound connection.
- Deb_Allen_18Historic F5 AccountOK, give this a shot. (code is untested, but I think the concept will work)
Apply this rule to your outbound virtual server -- outbound requests read & update an existing persistence entry, and apply the appropriate SNAT:when CLIENT_ACCEPTED { set vip [IP::local_addr] } when SERVER_CONNECTED { session add uie {[IP::server_addr] any virtual} $vip 86400 log local0. "Session table record added for [IP::server_addr] via VS $vip" }
when CLIENT_ACCEPTED { set snat_ip "[session lookup uie {[IP::client_addr] any virtual}]" if { $snat_ip != 0 }{ If session table entry exists, use it & refresh to update timeout log local0. "Session table record found for server [IP::client_addr]. SNAT address will be $snat_ip" snat $snat_ip session add uie {[IP::client_addr] any virtual} $snat_ip 86400 } else { log local0. "No session table record found for server [IP::client_addr]." snat ... } }
- Daniel_55334
Altostratus
I can configure the VS IP address (like 4.4.4.4 as in your case) as the SNAT address of the real servers for outbound connections, without using irule. And seems that everything is working fine. Must I need an irule? Or do I miss something? - Deb_Allen_18Historic F5 AccountThat's definitely the easiest way for most deployments, but mgabaldon was looking for a solution that didn't require any configuration as servers and virtuals come & go:I want the SNAT configuration to be automatic, so there isn't any need for our customer to define SNAT rules or classes, just the virtual servers.
- Daniel_55334
Altostratus
I see. Thanks. - Bilal_9919
Nimbostratus
Is there any way of creating a SNAT that will use source IP address as the VIP used for external connection?
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