Forum Discussion
SachinB_207389
Nimbostratus
Jan 12, 2017DNS iRule
Hi guys,
I am a beginner writing iRules. I have to write an iRule on LTM to match DNS request. Requirement is if it matches fqdn and source is private IP it should resolve to a private VIP else it sh...
Kai_Wilke
MVP
Jan 12, 2017Hi Sachin,
you can pretty much streamline your iRule by generating the
DNS::answer directly within the DNS_REQUEST event. This will make the syntax much simpler and also save a roundtrip between your F5 and your DNS Servers (which is wasted computing power since the DNS::answer gets always replaced).
when RULE_INIT {
set static::whitelist_ttl "300"
}
when DNS_REQUEST {
if { ( [string tolower [DNS::question name]] starts_with "www.domain.tld" )
and ( [DNS::question type] equals "A" ) } then {
log local0.debug "DNS Request match..."
if { [class match [IP::client_addr] equals private_net] } then {
log local0.debug "Client is private..."
DNS::answer insert "[DNS::question name]. $static::whitelist_ttl [DNS::question class] [DNS::question type] 10.10.10.10"
} else {
log local0.debug "Client is public..."
DNS::answer insert "[DNS::question name]. $static::whitelist_ttl [DNS::question class] [DNS::question type] 193.11.11.1"
}
DNS::return
}
}
Cheers, Kai
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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