Here is the our requirement so if possible can you send me actual iRule to fulfill this requirement. Site: .xyz Domain Names | Join Generation XYZ Allowed below host: 174.26.53.0/24 172.56.36.2 175.63.54.0/24 Block: all others Site: https://wwww.xyz.com Allowed for any So we require only filter for /bac virtual directory all other site running without any filter.
That said, here is an example that could provide some protection. First, create an address data group containing the hosts and networks which can access /bac*. Then use an iRule like this which references a data group named allowed_hosts_dg:
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::path]] {
"/bac*" {
if {not [class match [IP::client_addr] equals allowed_hosts_dg]}{
HTTP::respond 403 content {Blocked!}
}
}
}
}
You can create the data group in the GUI under Local Traffic | iRules | Data group list | Create. Select a name of allowed_hosts_dg and a type of address. Then create the iRule using the code above and add that to the virtual server.
Which LTM version are you on? You can check in the GUI under System | General Properties | Version. If you’re on 9.4.4 or higher, you can use this
9.4.4 - 9.4.8
when HTTP_REQUEST {
Check the requested path set to lower case
switch -glob [string tolower [HTTP::path]] {
"/bac*" {
Path started with /bac so check if client IP is in the allowed_hosts_dg data group
if {not [matchclass [IP::client_addr] equals allowed_hosts_dg]}{
Send a 403 unauthorized response
HTTP::respond 403 content {Blocked!}
Or you could reset the TCP connection
reject
}
}
}
}
9.4.3 and lower
when HTTP_REQUEST {
Check the requested path set to lower case
switch -glob [string tolower [HTTP::path]] {
"/bac*" {
Path started with /bac so check if client IP is in the allowed_hosts_dg data group
if {not [matchclass [IP::client_addr] equals $::allowed_hosts_dg]}{
Send a 403 unauthorized response
HTTP::respond 403 content {Blocked!}
Or you could reset the TCP connection
reject
}
}
}
}
Seeing this rule is a start to what I am currently needing but I have 4 folders that the Private_nets group need access to but external clients should not be allowed. Can I nest those into different rows for each directory?
Correct. In the example you provided, I need to allow access to the last 4 paths from the private_nets datagroup only, and the other path would remain open to everyone. Thanks for your guidance and I’ll begin the tweaking to make it work for me.