Forum Discussion

Welson_Alexandr's avatar
Welson_Alexandr
Icon for Nimbostratus rankNimbostratus
May 18, 2007

Route base on source address

This is my first try at iRules.

 

 

I would like to route a users to a pool in Data Center 1 if let's say they are coming from subnet 10.200.0.0 else redirect them to http://otherurl.com:8080 that is a VIP in Data Center 2

 

 

Will this work:

 

 

when CLIENT_ACCEPTED {

 

if { [IP::addr [IP::client_addr]/8 equals 10.200.0.0] } {

 

pool dev_testpool

 

} else {

 

HTTP::redirect "http://otherurl.com:8080/"

 

}

 

}
  • You might want to structure this a bit differently and use the matchclass command with an appropriate data group to contain the desired source addresses to match against. Something like:

     

     

    when HTTP_REQUEST {
     if { not [ matchclass [ IP::client_addr ] equals $::subnet_group ] {
      HTTP::redirect "http://otherurl.com:8080[HTTP::uri]"
      }
     }

     

     

    Then just set the default pool for the VS to dev_testpool or whatever. This way you execute code to handle the exceptions, can manage stacked iRules a little better, and also redirect them to the URI that was originally requested (if you wanted to do that).