Forum Discussion
can we direct traffic based on IP address
we have two servers (srvr1, srvr2) behind a F5 load balancer.
Is it possible to write an iRule (or any other type of rule ) to direct the traffic based on IP address? Specifically, i would like to direct all traffic from a small range of IP addresses (representing internal IPs) to srvr1 and all other IPs (external IPs) to srvr2
3 Replies
- Kevin_Stewart
Employee
I'd use an address-based data group, two pools, and a small iRule. Example:
when CLIENT_ACCEPTED { if { [class match [IP::client_addr] equals my_ip_dg] } { pool srv1_pool } else { pool srv2_pool } }where "my_ip_dg" (arbitrary name) is an address-based data group that contains single (client source) IP addresses and/or subnets. Also, using two separate pools allows you to add additional resources later if you ever need to scale out the application.
- Matt_Dierick
Employee
For sure, you can check IP address on client side, and select a member on server side.
https://devcentral.f5.com/articles/irules-101-05-selecting-pools-pool-members-and-nodes.UksHqmRRlRQ
https://devcentral.f5.com/wiki/irules.ip__addr.ashx
Hope this help. Let me know if you do not find your syntax in the irule 😉
Small i.e with pool selection :
when CLIENT_ACCEPTED { if { [IP::addr [IP::client_addr] equals 10.10.10.10] } { pool my_pool } } - What_Lies_Bene1
Cirrostratus
You might be better off using two separate Virtual Servers and the Priority Group Activation feature but if you really must have an iRule;
when CLIENT_ACCEPTED { If the source IP address is in the internal network; if { [IP::addr [IP::remote_addr] equals x.x.x.x/xx] } { continue and check if both Pool members are up if { [active_members pool_name] > 1 } { if so, select our prefered pool member for internal traffic; pool pool_name member x.x.x.x } else { if not, exit and let the standard load balancing method do it's thing return } If not an internal, assume it's an external IP and check if both Pool members are up elseif { [active_members pool_name] > 1 } { If so, select our prefered pool member for external traffic; pool pool_name member x.x.x.x } else { if not, exit and let the standard load balancing method do it's thing return } } }
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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