Forum Discussion
ukitsysadmin_95
Nimbostratus
Aug 18, 2009Redirect accourding to source IP ranges
Referring to the previous post: http://devcentral.f5.com/Default.aspx?tabid=53&view=topic&postid=34863
I'm looking to create an iRule whereby visitors to a specific website are redirected if they do not come from particular ranges of source IP addresses. The range of IP addresses will be large (IP by country); is there a way to refer the source to a file? Anybody created such a rule previously? Advice much appreciated.
- BlueFort_10580
Nimbostratus
If you want to make decisions based on location, the following may help: - ukstin
Nimbostratus
I think the best way to do it is with a dataclass, an example of rule could be this:class class_ips_country1 { network 150.1.1.1 mask 255.255.255.248 } when HTTP_REQUEST { if { ([matchclass [IP::client_addr] equals $::class_ips_country1]) } { pool pool_country1 } elseif { (matchclass [IP::client_addr] equals $::class_ips_country2]) } { pool pool_country2 } }
- The_Bhattman
Nimbostratus
A colleague of mine subscribes to a service where he downloads the list of IP addresses per country. In his iRule he created a datagroup listing all the ranges in each country and then he wrote up an Irule using Matchclasses Click here and IP::client_addr Click here. It can be quite time consuming because of the data entry. A file can be used as the source within an iRule. Click here to take a look at an example where a source file is used to read the entries into the iRule. - hoolio
Cirrostratus
You can use the format of the preconfigured AOL datagroup as a reference:b class aol list class aol { network 64.12.96.0/19 network 149.174.160.0/20 network 152.163.96.0/22 network 152.163.100.0/23 network 152.163.240.0/21 network 152.163.248.0/22 network 152.163.252.0/23 network 195.93.16.0/20 network 195.93.32.0/22 network 195.93.48.0/22 network 195.93.64.0/19 network 195.93.96.0/19 network 198.81.0.0/22 network 198.81.8.0/23 network 198.81.16.0/20 network 202.67.64.128/25 network 205.188.112.0/20 network 205.188.146.144/30 network 205.188.192.0/20 network 205.188.208.0/23 network 207.200.112.0/21 }
- Rob_13365
Altocumulus
Hi - hoolio
Cirrostratus
Hi, - The_Bhattman
Nimbostratus
I would like to add you could change the logic to something like this to eliminate else statement.when HTTP_REQUEST { if { ![matchclass [IP::client_addr] equals $::UK_Allowed_IP]}{ HTTP::redirect http://redirect.test.com } }
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