Forum Discussion

Jim_Araujo_1061's avatar
Jim_Araujo_1061
Icon for Nimbostratus rankNimbostratus
Oct 28, 2014

GTM iRule to modify Query?

Hey folks, is it possible for an iRule to change the DNS name being queried? For example, based on the condition in the article here https://devcentral.f5.com/questions/gtm-irule-to-provide-cname-based-on-source-ip-of-query I want a CNAME to always add .wip. after the subdomain of the query. For example, I want to replace example.company.com with example.wip.company.com. However in a wildcard scenario, so I don't have to manually enter a CNAME for every single record.

example1.company.com --CNAME--> example1.wip.company.com
example2.company.com --CNAME--> example2.wip.company.com
example3.company.com --CNAME--> example3.wip.company.com
example4.company.com --CNAME--> example4.wip.company.com
example5.company.com --CNAME--> example5.wip.company.com
example6.company.com --CNAME--> example6.wip.company.com

Is there a way to have the iRule automatically add the .wip. to any query?

3 Replies

  • and if you cant 'change it', you can always answer the query from the iRule, with the correct cname.

     

  • Hamish's avatar
    Hamish
    Icon for Cirrocumulus rankCirrocumulus

    Yes. You can use the DNS_REQUEST event to access and alter the request as it comes in (And the DNS_RESPONSE to alter it on the way out).

     

    See => DNS_REQUEST and DNS::question that show how to intercept the request and access and alter the question (query) itself.

     

    H

     

  • This is what I came up with, and please feel free to improve and post back as my TCL skills are a bit rusty.

    when DNS_REQUEST {
           set wip ".wip."
           set in_query [DNS::question name]
           set suffix_query [string trim [domain $in_query 2] " "]
           set lead_domain [string trim [lindex [split $in_query "." ] 0] " "]
    
           set out_query "$lead_domain$wip$suffix_query"
           log local0. "$out_query"
    
           cname $out_query
        }