Hi All,
I am in need of an iRule that redirects users to URLs based on their source IP. I am attaching it to a standard VS with no pool defined. This is what I have come up with, however it does not seem to do the trick. All I get is a connection reset.
when HTTP_REQUEST { if { ( [IP::addr [IP::client_addr] equals 10.50.1.0/24] ) } { HTTP::redirect "; }
if { ( [IP::addr [IP::client_addr] equals 10.60.1.0/24] ) } {
HTTP::redirect "http://abc2.test.com"
}
if { ( [IP::addr [IP::client_addr] equals 10.70.1.0/24] ) } {
HTTP::redirect "http://abc3.test.com"
}
}
Do you want to redirecct or to forward to internal servers with such hostnames?
if you want to redirect, this code may work. you can optimize it with elseif:
when HTTP_REQUEST {
if { ( [IP::addr [IP::client_addr] equals 10.50.1.0/24] ) } {
HTTP::redirect "http://abc1.test.com"
} elseif { ( [IP::addr [IP::client_addr] equals 10.60.1.0/24] ) } {
HTTP::redirect "http://abc2.test.com"
} elseif { ( [IP::addr [IP::client_addr] equals 10.70.1.0/24] ) } {
HTTP::redirect "http://abc3.test.com"
}
}
You could also accomplish this without any iRule by using a LTM policy. This would be the preferred method. For more info on LTM policies see:
You should use a more optimized solution with “switch” instead of “if”
Code
when CLIENT_ACCEPTED {
switch -glob [IP::client_addr] {
"192.168.5.*" { pool pool1 }
"192.168.6.*" { pool pool2 }
"192.168.7.*" { pool pool3 }
default { pool default_pool }
}
}
Thanks all for your help, this is what finally worked. Notice the placement of the CIDR notation. Also since we use route domains, it needed to be defined by the %1.
when HTTP_REQUEST { if { ( [IP::addr [IP::client_addr]/24 equals 10.50.1.0%1] ) } { HTTP::redirect "http://abc1.test.com"; } elseif { ( [IP::addr [IP::client_addr]/24 equals 10.60.1.0%1] ) } { HTTP::redirect "http://abc2.test.com"; } elseif { ( [IP::addr [IP::client_addr]/24 equals 10.70.1.0%1] ) } { HTTP::redirect "http://abc3.test.com"; } }