Forum Discussion
iRule to only allow traffic from 3 differents subnets
I need to create an irule that just allow traffic when its from 3 subnets: 10.10.17.0/24, 10.10.18.0/24 and 10.10.19.0/24. I don´t know if the one below, works like I want. Could anybody please help me? Would you recommend me to use datagroups? Do they affect the cpu?
when HTTP_REQUEST { if { [string tolower [HTTP::path]] ends_with "/xxx" } and { { not [IP::addr [IP::client_addr]/24 equals 10.10.17.0])} and { not [IP::addr [IP::client_addr]/23 equals 10.10.18.0])}{ HTTP::respond 200 content "URL Blocked" } } }
Thanks and regards.
6 Replies
- IheartF5_45022
Nacreous
Datagroups are highly performant so no CPU worries there;-
when HTTP_REQUEST { if {[string tolower [HTTP::path]] ends_with "/xxx" && ![class match [IP::client_addr] equals dg_ip_whitelist] } { HTTP::respond 200 content "URL Blocked" } } - pablitop_134672
Nimbostratus
IheartF5, thanks for your answer. Just one more thing, do you think that something like this would work?
when HTTP_REQUEST { if {( [string tolower [HTTP::path]] ends_with "/xxx " ) and not ( [matchclass [IP::client_addr] equals $::xxx_allowed] ) } { HTTP::respond 200 content "URL Blocked" } }
- nitass
Employee
Just one more thing, do you think that something like this would work?
what version are you running? if it is 9.4.4 or later, you should remove $:: prefix.
Class / Data Group List References 9.4.0 - 9.4.3, class reference not compatible as of 9.4.4, "::" and "$::" prefixes are no longer required to reference classes using findclass or matchclass. Classes are static and are therefore CMP compatible. There is no need to treat them as global objects. 10.0, matchclass / findclass deprecated in favor of new class commandCMP Compatibility
https://devcentral.f5.com/wiki/iRules.cmpcompatibility.ashx - pablitop_134672
Nimbostratus
Nitass, I have version 11 in one cluster where I´m testing the irule, but I get this error:
The current configuration forces the Virtual (/Common/XXX) to be demoted from CMP.
The irule is below:
when HTTP_REQUEST { if {( [string tolower [HTTP::path]] ends_with "/xxx " ) and not ( [class [IP::client_addr] equals $::xxx_allowed] ) } { HTTP::respond 200 content "URL Blocked" } }
- nitass
Employee
I have version 11 in one cluster where I´m testing the irule, but I get this error
can you change from $::xxx_allowed to xxx_allowed?
- pablitop_134672
Nimbostratus
Nitass, now it´s working fine. The irule is the below:
when HTTP_REQUEST { if {( [string tolower [HTTP::path]] ends_with "/xxx" ) and not ( [class match [IP::client_addr] equals xxx_allowed] ) } { HTTP::respond 200 content "URL Blocked" } }
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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