Forum Discussion
Mark_Burchard_5
Nimbostratus
Mar 21, 2006iRule to limit access to webserver directory by client IP
Hi all,
First time posting here, and you'll probably laugh and shake your heads at this simple problem, but hopefully I'll learn. I have searched for similar iRules and can't seem to find them.
This is my issue: I'm looking to deny access by client ip to a certain directory on a site (eg. host.domain.tld/Example. For clients originating from the correct IP range(s), it would pass them through. For those outside the allowed range, it would redirect them to the site's base URI.
Here is what I have so far:
when HTTP_REQUEST {
if { [matchclass [HTTP::uri] contains "/Example"] }
if { [[IP::client_addr] not equals mask "10.0.0.0\24"] }
HTTP::respond 301 Location "http://host.domain.tld/"
}
The iRule validator has this to say about that rule:
line 3: [missing a script after "if"] [ ]
line 5: [missing a script after "if"] []
Am I even on the right track here? Has anybody ever tried to use an iRule this way?
Thanks very much in advance for any help you can give.
-Mark
- Mark_Burchard_5
Nimbostratus
Colin, - JRahm
Admin
when HTTP_REQUEST { if { ( [ string tolower [HTTP::uri] ] starts_with "/example" ) and ( not ( [ matchclass [IP::client_addr] equals $::IPranges ] ) ) } { HTTP::redirect "http://host.domain.tld/" } }
- Guillaume_Bruss
Nimbostratus
I try thiswhen RULE_INIT { log local0. "Init redirect Https V2" array set ::http_allowed_ip_list { "10.0.0.11/12" "10.0.0.12/13" } } when HTTP_REQUEST { log local0. "IP [IP::client_addr] Tries to connect" if { ( not ( [ matchclass [IP::client_addr] equals $::http_allowed_ip_list ] ) ) } { HTTP::redirect https://[HTTP::host][HTTP::uri] } }
- Colin_Walker_12Historic F5 AccountThis is because you're defining an array when what you really want is a class.
class http_allowed_ip_list { "10.0.0.11/12" "10.0.0.12/13" }
- Guillaume_Bruss
Nimbostratus
thanks Collin - Colin_Walker_12Historic F5 AccountIn the GUI, if you create a data group and set the type to "Address", then under the Records section, you'll want to select "Network" as the type. This will display another field that allows you to enter the network mask along with the address.
- Derek_Nelson_10
Nimbostratus
Hi.
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