Forum Discussion

Marc_Weisbrod_6's avatar
Marc_Weisbrod_6
Icon for Nimbostratus rankNimbostratus
Nov 09, 2006

IRule to redirect to another side based on network

All,

 

 

I am trying to write an Irule to redirect users who are not on our local site to another page. I have written this Irule but I am unsure if the Irule can accept subnets.

 

 

when HTTP_REQUEST {

 

if { [[IP::client_addr] is "10.1.0.0/16"] } {

 

pool http-pool

 

} elseif {

 

[[IP::client_addr] is "10.2.0.0/16"] } {

 

pool http-pool

 

} elseif {

 

[[IP::client_addr] is "172.16.0.0/16"] } {

 

pool http-pool

 

} else {

 

HTTP::redirect "http://192.168.0.12/local_only.jsp"

 

}

 

}

 

 

Basically anyone who connects with 10.1.x.x or 10.2.x.x or 172.16.x.x should get the site, but if you connect from 10.3.x.x you get redirected.

 

 

Thanks

 

1 Reply

  • You can set up your hosts and networks in a class (datagroup in the GUI) and then reference that class in a rule. Here is an example:

    
    class my_hosts_networks_class  {
       network 10.0.0.0 mask 255.0.0.0
       host 192.168.0.100
    }

    
    rule filter_clients_rule {
       when HTTP_REQUEST {
          if { [matchclass [IP::remote_addr] equals $::my_hosts_networks_class] } {
             pool http-pool
          }
          else {
             HTTP::redirect "http://192.168.0.12/local_only.jsp"
          }
       }
    }

    You can either add the class in the GUI under iRules >> Datagroups, or edit the bigip.conf and run 'b load' to initialize the change.

    Aaron