Forum Discussion

Jeff_46763's avatar
Jeff_46763
Icon for Nimbostratus rankNimbostratus
May 16, 2016

Irule to Load Balance traffic based on group of IP's

I would like to write an Irule to basically say "if a group of IP's come into the VIP, load balance to server 1 and 2, all others hit server 3" I'm newish to Irules so would like some help please.

 

Thanks

 

2 Replies

  • There are a few ways to deal with this, but one example is to use an iRule data group and match the specific source IP and make a decision based on that. I would set this up using two pools, a data group and a rule as per this example:

    Pool1 - Server 1 and 2 Pool2 - Server 3

    iRule Data group (String type)

    Name: Pool1IPs

    Add the IP Addresses to route to Pool1

    iRule to direct the traffic:

    when HTTP_REQUEST {
        if {[class match [IP::client_addr] equals Pool1IPs} {
            Pool Pool1
        } else {
            Pool Pool2
        }
    }
    
  • Hello,

    You can use list directly in the irule as shown in the example below :

    when RULE_INIT {
        set static::ipaddress ["10.1.1.1" "10.1.1.2" "10.1.1.3"]
    }
    
    when HTTP_REQUEST {
        if { [lsearch -glob $static::ipaddress "[IP::client_addr]"] != -1 } {
            pool mypool
        } else {
            pool default_pool
        }
    }