Forum Discussion
Roark_Fisher_29
Nimbostratus
May 01, 2006Outbound routing based upon source IP
I hope the intellects here may be able to help me with a confusing setup. I worked for 3 days with F5 tech support on this and they finally sent me here.
I have about a dozen T1 lines that come into a switch and the switch connects to my "external" VLAN port.
On the "internal" side my systems use SNAT to start an outbound connection.
The problem is that the outbound connections always use the default route. But I need them to route through the T1 that matches their SNAT address.
As an example. I have a system with an address of 10.10.10.10. It starts an outbound connection and gets a SNAT address of 62.2.2.10. I need to create an iRule that will look at this the SNAT address and route the traffic down the 62.x.x.x T1 and not through the default address.
Again, I am not trying to route based upon the destination address. Rather, I need to choose the correct router based upon the source address. Otherwise, if the wrong router is chosen, the packets get dropped.
If any of you F5 guru's know how to create an iRule to do this, I would greatly appreciate the help.
Thanks.
-Roark Fisher
- JRahm
Admin
I am doing this in the lab currently:when CLIENT_ACCEPTED { if { [IP::addr [IP::client_addr] equals 192.168.1.100/255.255.255.255] } { node 10.10.1.5 Firewall 1 } elseif { [IP::addr [IP::client_addr] equals 192.168.2.100/255.255.255.255] } { node 10.10.2.5 Firewall 2 } }
- JRahm
Admin
With a dozen T1's, I'd recommend using a class instead of 12 if statements:class snat_gw { "snat_IP1 gw_IP1" "snat_IP2 gw_IP2" "snat_IP3 gw_IP3" "........ ......" "snat_IP12 gw_IP12" } when CLIENT_ACCEPTED { set my_gw [findclass [IP::client_addr] $::snat_gw " "] if { $my_gw ne "" } { node $my_gw } else { discard } }
- Roark_Fisher_29
Nimbostratus
Wow! I appreciate your testing this as this is very big to a very big project. And I was amazed to get such a good response so quickly. Sadly, I have to claim being dumb with iRules. I tried to setup the second example you gave as it was (to me) the clearest and easiest to understand. - JRahm
Admin
The class isn't part of the iRule, it needs to be added either to the bigip.conf file (don't forget to do a bigpipe load after editing the file)at the CLI or under the datagroups tab on the irules tab. - Roark_Fisher_29
Nimbostratus
Thank you. I think this is close to working. - JRahm
Admin
The iRule should be associated to the 0.0.0.0/0 network forwarding virtual you created. Also, I'd like to note that I lock down this virtual to only the internal VLAN's, so external traffic won't be forwarded to internal networks. I'd be curious if the iRule is being triggered before/after the nat occurs? Might add some logging to find out:when CLIENT_ACCEPTED { set my_gw [findclass [IP::client_addr] $::snat_gw " "] if { $my_gw ne "" } { log "My gateway is $my_gw and my client IP is [IP::client_addr]" node $my_gw } else { log "My client IP is [IP::client_addr]" discard } }
- Roark_Fisher_29
Nimbostratus
Fantastic! Starting to see some things working. I still have a few follow-up questions to get some last parts working. (for those following along at home and who may, like me, not be fully F5 literate, I will put what I have done at the end of this post). - JRahm
Admin
1. [IP::addr [IP::remote_addr] equals "x.x.x.0/24"] will match your client IP to anything in the specified network and mask. It might be good to assign snat based on client network, then assign gw based on snat, but the developers could have better ideas. - Roark_Fisher_29
Nimbostratus
Thank you for your excellent help on this!!!! This is now working as expected. I really appreciate your help in getting through this. -Roark - Rodrigo_EV_7869
Nimbostratus
I'd like to propose another scenario we got in a customer:class class_static_snat_servers { host 10.0.0.10 host 10.0.0.11 } class class_static_snat_gateways { "200.1.0.1 200.1.0.10" "200.2.0.1 200.2.0.10" } when CLIENT_ACCEPTED { set static_snat_server [IP::client_addr] } when LB_SELECTED { if {$::static_snat_server eq $::class_static_snat_servers]} { set selected_gateway [findclass [LB::server addr] $::class_static_snat_gateways " "] if { $selected_gateway ne "" } { snat $selected_gateway } } }
when LB_SELECTED { if {[matchclass [IP::client_addr] eq $::class_static_snat_servers]} { set my_gw [findclass [LB::server addr] $::class_static_snat_gateways " "] if { $my_gw ne "" } { snat $my_gw } } }
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