Forum Discussion

icopperman_1347's avatar
icopperman_1347
Icon for Nimbostratus rankNimbostratus
Oct 01, 2013

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

  • 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.

  • 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
        }
     }
    }