Forum Discussion
f5 irule redirect based on source ip
Hello
I want redirect to for specific 5 subnet ip address,and If these 5 addresses were not requested, they should be redirected to another address example to .
- Yann_Desmarest_Nacreous
Hi,
Here is a code sample that may help you :
when HTTP_REQUEST { if { [IP::client_addr] eq "x.x.x.x" and [HTTP::host] eq "www.aaa.com" } { HTTP::redirect http://www.bbb.com[HTTP::uri] } else { HTTP::redirect http://www.ccc.com[HTTP::uri] } }
That's just an example. You can have a look at IP::client_addr or class match commands to integrate a more complex lookup for a range of IP addresses.
You can also replace HTTP::redirect command by a HTTP::respond command.
Hope it helps
Yann
- zhalehNimbostratus
i test it but don't work
- HamishCirrocumulus
That's probably because it was (As Yann stated) an example...
if you'd like some more help please at least tell us what you actually tried, what went wrong and what diagnostics/debugging you attempted to find the issue.
if including a copy of your iRule, please put the code fences around it.
Hi,
Here is a code sample that may help you :
when HTTP_REQUEST { if { [IP::client_addr] eq "x.x.x.x" and [HTTP::host] eq "www.aaa.com" } { HTTP::redirect http://www.bbb.com[HTTP::uri] } else { HTTP::redirect http://www.ccc.com[HTTP::uri] } }
That's just an example. You can have a look at IP::client_addr or class match commands to integrate a more complex lookup for a range of IP addresses.
You can also replace HTTP::redirect command by a HTTP::respond command.
Hope it helps
Yann
- zhalehNimbostratus
i test it but don't work
- HamishCirrocumulus
That's probably because it was (As Yann stated) an example...
if you'd like some more help please at least tell us what you actually tried, what went wrong and what diagnostics/debugging you attempted to find the issue.
if including a copy of your iRule, please put the code fences around it.
- RicoCirrus
zhaleh,
Try this iRule
when HTTP_REQUEST { if {[IP::addr 10.0.0.0/8 equals [IP::client_addr]]} { HTTP::redirect http://bbb.com[HTTP::uri] } else { HTTP::redirect http://ccc.com[HTTP::uri] } }
You can use the IP::addr command to compare the subnets of the IP address. The if statement would also work like this:
if {[IP::addr "10.0.0.0 mask 255.0.0.0" equals [IP::client_addr]]} {
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com