DNS 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 should resolve to Public IP. Below is my iRule. However i am getting error for DNS Answer. Can someone please guide me in the right direction and point out the error ?
when RULE_INIT { set static::whitelist_ttl "300" }
when DNS_REQUEST {
debugging statement see all questions and request details log -noname local0. "Client: [IP::client_addr] Question:[DNS::question name] Type:[DNS::question type] Class:[DNS::question class] Origin:[DNS::origin]"
if{[class match $fqdn equals x.x.x.x]} { DNS::return } } when DNS_RESPONSE {
debugging statement to see all questions and request details log -noname local0. "Request: $fqdn_name Answer: [DNS::answer] Origin:[DNS::origin] Status: [DNS::header rcode] Flags: RD [DNS::header rd] RA [DNS::header ra]"
if { [class match [IP::client_addr] equals private_net] } { DNS::answer clear DNS::answer insert $fqdn.$static::whitelist_ttl [DNS::question class] [DNS::question type] 10.10.10.10 DNS::return } else { DNS::answer insert $fqdn.$static::whitelist_ttl [DNS::question class] [DNS::question type] 193.11.11.1 DNS::return } }