Ken_B_50116
Jun 12, 2012Cirrostratus
How to select a pool based on client's hostname?
I need to write an iRule that will select a pool based on the requesting client's DNS hostname. I know an iRule can perform a reverse DNS lookup to get the client's hostname from the source IP address, but I'm not sure how to put it all together.
This sample shows a reverse DNS lookup:
https://devcentral.f5.com/wiki/iRules.Block_requests_by_reverse_DNS_record.ashx
However, being new to iRules I'm not sure the best way to work this into a script to fit my needs. One problem is that the sample code seems to be dependent on HTTP, however I am not concerned with the application layer. My iRule needs to work regardless of the application protocol.
This example assumes there are two data groups (non-prod-list and prod-list), each containing the hostnames of several servers. Does anyone think this will fly? Certainly it has problems.
when CLIENT_ACCEPTED {
Trigger a name lookup for new connections
set do_lookup 1
Check if we haven't done a lookup already on this connection
if { $do_lookup }{
Start a name resolution on the client IP address
NAME::lookup -ptr [IP::client_addr]
}
}
when NAME_RESOLVED {
set ptr [string tolower [NAME::response]]
if { $ptr starts_with $::non-prod-list } {
pool pool_a }
elseif { $ptr starts_with $::prod-list } {
pool pool_b }
}
else pool default_pool
}