Forum Discussion
Shawn_Puckett_8
Nimbostratus
Jan 26, 2006IP blocking and URI Redirect
We need two rules to be validated before a user is sent to a pool, first we need to make sure they are coming from an allowed IP, then we need to see if they want to go to a specific server via the URI.
So the IP check is easy to do with something like this:
when CLIENT_ACCEPTED
{
if {[IP::addr [IP::remote_addr] equals 205.229.151.206/255.255.255.255]} or
{[IP::addr [IP::remote_addr] equals 65.61.115.222/255.255.255.255]}
{pool QATest01-02-Port80}
else
{reject}
}
And the URI redirect to different pools is also easy to do with something like:
when HTTP_REQUEST
{
if {[HTTP::uri] contains "qatest01"}
{pool QATest01-Port80}
if {[HTTP::uri] contains "qatest02"}
{pool QATest02-Port80}
else
{pool QATest01-02-Port80}
}
But I'm not sure how to combine them.
I do have one additional question, there is about 20 IPs that are allowed in so I want to know if there is a better way to do that then what I have, or is that the approach the best?
Thanks,
Shawn
- JRahm
Admin
Try this. Note that your allowed client IP addresses should replace the X.X.X.X in the class. I'd clean the real IP addresses out of your posting if they are valid.class allowed_client_IP { X.X.X.X X.X.X.X } when HTTP_REQUEST { if {[matchclass [IP::client_addr] eq $::allowed_client_IP]} { if { [HTTP::uri] contains "qatest01" } { use pool QATest01-Port80 } elseif { [HTTP::uri] contains "qatest02" } { use pool QATest02-Port80 } else { use pool QATest01-02-Port80 } } else { reject } }
- Shawn_Puckett_8
Nimbostratus
First off, THANKS for the Help!! - The "class" portion is not part of the iRule. Under the iRule section of the GUI, you need to create a data group named "allowed_client_IP" with all your addresses in it. The class portion of the code snippet is how the data is stored in the BIG-IP's configuration.
- I wouldn't call that a stupid question. Actually it's quite common.
- Shawn_Puckett_8
Nimbostratus
OK, well I've setup the class but when I try to save the rule I get this error: - JRahm
Admin
It's very particular about spacing, place the rule in as I entered it above. - Shawn_Puckett_8
Nimbostratus
OK the spacing was the issue so I'm one step closer: - I would throw in some logging to find out where the rule is not behaving as you would expect.
when HTTP_REQUEST { if { [matchclass [IP::client_addr] eq $::allowed_client_IP] } { log local0. "address [IP::client_addr] found in allowed_client_IP list" if { [HTTP::uri] contains "qatest01" } { log local0. "Found qatest01 in uri '[HTTP::uri]'" use pool QATest01-Port80 } elseif { [HTTP::uri] contains "qatest02" } { log local0. "Found qatest02 in uri '[HTTP::uri]'" use pool QATest02-Port80 } else { log local0. "Didn't find a match in uri '[HTTP::uri]'" use pool QATest01-02-Port80 } } else { log local0. "address [IP::client_addr] not found in allowed_client_IP list" reject } }
- Shawn_Puckett_8
Nimbostratus
It WORKS! - JRahm
Admin
The guide gives most of the available commands (there are some unpublished ones), but this site would be the best place to learn how to weave the various commands together. If you have a BigIP lab unit and a linux box, I'd suggest creating several virtual servers on your linux box and start building rules to solve common problems. You could always use rules directly from this site and modify them for your lab environment, then tweak them slightly and include as much logging as possible throughout the rule so you can see how the events are firing and how the decisions are being made.
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