Forum Discussion

eightsixstud_29's avatar
eightsixstud_29
Icon for Nimbostratus rankNimbostratus
Sep 15, 2016

Error using iRule for Conditional DNS Lookups

I am looking to perform some DNS lookups on a domain and based on the results, either provide the client with the external IP if it exists or the internal IP if there isn't an external A record.

 

I have written the following irule but am receiving this error:

 

"01070151:3: Rule [/Common/Conditional_Test_Lookup] error: /Common/Conditional_Test_Lookup:2: error: [undefined procedure: DNS::rrname][DNS::rrname] /Common/Conditional_Test_Lookup:4: error: [parse error: PARSE syntax 258 {syntax error in expression " $dnsName [DNS::rrtype] equal "A" ": extra tokens at end of expression}][{ $dnsName [DNS::rrtype] equal "A" }] "

 

Code:  
when DNS_REQUEST {
        if { ([IP::addr [IP::client_addr] equals 192.168.1.0/24]) and ([DNS::rrname] contains "test.com") } {
                            set dnsName [RESOLV::lookup @8.8.8.8 -a [DNS::rrname]] 
                            if { $dnsName [DNS::rrtype] equal "A" } {
                                DNS::return
                            } 
            }
}
  • HI,

    Can you please try below irule.

       when DNS_REQUEST {
        if { ([IP::addr [IP::client_addr] equals 192.168.1.0/24]) and ([DNS::rrname] contains "test.com") } {
                            set dnsName [RESOLV::lookup @8.8.8.8 -a [DNS::rrname]] 
                            if { ([DNS::rrtype] equal "A") } {
                                DNS::return
                            } 
            }
        }
    
  • R_Marc's avatar
    R_Marc
    Icon for Nimbostratus rankNimbostratus

    Not sure how relevant this is, but for me, I had to create a local virtual to get Resolve to work consistently. Going direct actually caused all DNS to stop working on the box (TMos and Linux).

    [RESOLV::lookup @/Common/dns-proxy-ipv4-dns-virtual -a $name] 
    
  • HI,

    Can you please try below irule.

       when DNS_REQUEST {
        if { ([IP::addr [IP::client_addr] equals 192.168.1.0/24]) and ([DNS::rrname] contains "test.com") } {
                            set dnsName [RESOLV::lookup @8.8.8.8 -a [DNS::rrname]] 
                            if { ([DNS::rrtype] equal "A") } {
                                DNS::return
                            } 
            }
        }
    
    • eightsixstud_29's avatar
      eightsixstud_29
      Icon for Nimbostratus rankNimbostratus

      We tried using the modified version, but are receiving the same error. Also, we have made the below changes, with no luck. Any ideas?

      01070151:3: Rule [/Common/Test] error: /Common/Test:2: error: [undefined procedure: DNS::rrname][DNS::rrname]
      /Common/Test:4: error: [undefined procedure: DNS::rrtype][DNS::rrtype]
      
      when DNS_REQUEST {
      if { ([IP::addr [IP::client_addr] equals 192.168.1.0/24]) and ([DNS::rrname] equals "test.com") } {
                          [RESOLV::lookup @8.8.8.8 -a [DNS::rrname]] 
                          if { ([DNS::rrtype] equals "A") } {
                              DNS::return
                          } 
          }
      }