Forum Discussion
simple redirect irule based off ip
- Sep 26, 2022
Hello, how many networks do you need to match?
For allowing multiple client networks you'll need a data group.
See this example below - note that "getfield" returns a string so I'm changing the format to IP address using IP::addr .
when HTTP_REQUEST { if {[string tolower [HTTP::uri]] starts_with "/restricted1" }{ if { [IP::addr [getfield [IP::client_addr] "%" 1] equals "10.2.2.0/24"]}{ #this is a sample with a static client network return } elseif { [class match [getfield [IP::client_addr] "%" 1] equals datagroup_allowed_networks] } { #when you have multiple subnet to match, then it is recommended to use data-group created as Address (IP) type. return } else { HTTP::redirect "https://demo.com/not-allowed" } }
Hello, how many networks do you need to match?
For allowing multiple client networks you'll need a data group.
See this example below - note that "getfield" returns a string so I'm changing the format to IP address using IP::addr .
when HTTP_REQUEST {
if {[string tolower [HTTP::uri]] starts_with "/restricted1" }{
if { [IP::addr [getfield [IP::client_addr] "%" 1] equals "10.2.2.0/24"]}{
#this is a sample with a static client network
return
} elseif { [class match [getfield [IP::client_addr] "%" 1] equals datagroup_allowed_networks] } {
#when you have multiple subnet to match, then it is recommended to use data-group created as Address (IP) type.
return
} else {
HTTP::redirect "https://demo.com/not-allowed"
}
}
- CraigWooOct 06, 2022Nimbostratus
Thanks, CA_Valli
Just the one for now, ive removed the data group for now and seems to be working will do some more testing and let you know. Thanks heaps for this
- CA_ValliOct 07, 2022MVP
Happy to help, if this helped resolve issue please "accept solution" for my previous message so that this thread is closed and it's easier for other users with similar problem to find it.
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