Forum Discussion
pedinopa_170325
Nimbostratus
Sep 14, 2016irule question
I want to write an iRule that will look at the client IP and direct the to a specific URL. I need some help with the irule
if CLIENT_IP -LIKE X.X.X.X
[
HTTP_REQUEST HTTP://SERVER/INDEX.HTM...
Kai_Wilke
MVP
Sep 15, 2016Hi pedinopa@gmail.com,
the best approach would be to use a LTM datagroup to store the different IP Addresses / Subnets and to use the
[class] command to lookup those IPs within an iRule and then trigger the redirect. If you need to add additional IPs then you don't need to change your iRule. Just add a new entry into the data-group using the WebInterface.
Data Group:
ltm data-group internal DG_REDIRECT_IPs {
records {
1.1.1.1/32 { }
2.2.2.2/32 { }
3.3.3.3/32 { }
10.0.0.0/8 { }
172.16.0.0/12 { }
192.168.0.0/16 { }
}
type ip
}
iRule:
when HTTP_REQUEST {
if { [class match [getfield [IP::client_addr] "%" 1] equals DG_REDIRECT_IPs]] } then {
HTTP::redirect "http://SERVER/index.htm"
}
}
For further information you may take a look to the
[class] command wiki page.
https://devcentral.f5.com/wiki/iRules.class.ashx
Cheers, Kai
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects