Forum Discussion

Faizan's avatar
Icon for Nimbostratus rankNimbostratus
Oct 06, 2020

Source port based load balancing using the persistence least connection

We have 1400 client with define source port from 8000 to 10000 and destination is 2 server for example (x.x.x.x and y.y.y.y)

We need irules for  8000 to 8500 source port load balance to x.x.x.x server if x.x.x.x fail send to y.y.y.y same thing goes all port.

Please help us to create the irules.

1)      Source port 8000 to 8500

2)      Source port 8501 to 9000

3)      Source port 9001 to 9500

4)      Source port 9501 to 10000



 if { [TCP::client_port] starts_with "8000" ends_with "8500" } {

   pool pool1

 } elseif { [TCP::client_port] starts_with "8501" ends_with "9000" } {

   pool pool1


 elseif { [TCP::client_port] starts_with "9001" ends_with "9500" } {

   pool pool1


 elseif { [TCP::client_port] starts_with "9501" ends_with "10000" } {

   pool pool1




2 Replies

  • You can't use starts_with and ends_with that way.

    starts_with and ends_with are string comparison operators.

    Your code will check id string returned by [TCP:client_port] begins with 8000, it will be true only for port 8000.

    You may for example use matches_regex and regular expresion:

    matches_regex "8[01234][0-9][0-9]" to mach all ports from 8000 to 8499

  • It is unclear from your code what your requirements are. Do you want to load balance all connections from all clients with ports in the range of 8000-10000 to pool1, as your sample iRule code shows? Or do you want to load balance to separate pools based on client port, with clients in port range 8000-8500 load balancing to pool1, clients in port range 8501-9000 load balancing to pool2, etc? In either case, where do you want each port grouping to load balance to if the first load balancing choice fails? Depending on what your requirements really are (and the version of BIG-IP you are running), you may be able to do at least the pool selection part with a local traffic policy rather than an iRule, which would be more efficient. For example:





    If you still need to select another node if load balancing fails, my understanding is that can only be done with an iRule at this point.