Forum Discussion

Mario_Franco's avatar
Icon for Altocumulus rankAltocumulus
Sep 20, 2023

Implementing F5 DNS and Creating Custom CNAME Redirects

We are currently implementing a solution in Azure and have encountered some DNS-related issues. I think it's a good idea to implement F5 DNS. However, I wonder if we can create an iRule to set up a CNAME for a specific domain. In other words, if a domain like "" is received, the iRule would inspect this request and respond to the user with a CNAME from "" to "".

I have created the following irule:

set original_name [DNS::question name]
if { [string tolower $original_name] ends_with "" } {
set modified_name [string map {"" ""} [string tolower $original_name]]
DNS::question name $modified_name
set cname_record "${original_name} IN CNAME ${modified_name}."
log local0. "$cname_record"
set new_rr [DNS::rr $cname_record]
log local0. "$new_rr"
DNS::answer clear
DNS::answer insert $new_rr
DNS::header aa 1

If I see the logs it looks good:

However, when I perform an nslookup, dig, or access the domain directly from the browser, it doesn't work.


Server: UnKnown
Address: x.x.x.x



dig @x.x.x.x
;; Question section mismatch: got


Any idea if this is possible?

6 Replies

  • f51's avatar
    Icon for Cirrostratus rankCirrostratus

    Your approach to use an iRule on F5 DNS to manipulate DNS requests and responses is correct. However, the issue you're facing might be due to how DNS resolution works and the context in which iRules operate. The iRule you provided is designed to modify the DNS request for "" to "", and then create a CNAME record in the DNS response. When you perform a DNS lookup for "", the lookup is redirected to "". However, this does not necessarily mean that "" will resolve correctly.

    • Mario_Franco's avatar
      Icon for Altocumulus rankAltocumulus

      If I try to consume it works, however, when I verify the nslookup output for it doesn't show the cname or even an answer, it's just empty, however verifying the logs the irule is creating the cname record but looks like it's not returning the answer to the client

  • xuwen's avatar
    Icon for Cumulonimbus rankCumulonimbus
    when DNS_REQUEST priority 500 {
        set original_name [DNS::question name]
        if { [string tolower $original_name] ends_with "" } {
            set modified_name [string map {"" ""} [string tolower $original_name]]
            # DNS::question name $modified_name
            set cname_record "${original_name}. 300 IN CNAME ${modified_name}."
            log local0. "cname_record is ${cname_record}"
            set new_rr [DNS::rr ${cname_record}]
            # log local0. "$new_rr"
            DNS::answer clear
            DNS::answer insert $new_rr
            DNS::header aa 1
            DNS::header rd 0
            DNS::header ra 0
            DNS::header ad 0



    [root@NF42GTT1-A3:Active:Standalone] config # dig @

    ; <<>> DiG 9.11.31 <<>> @
    ; (1 server found)
    ;; global options: +cmd
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 60738
    ;; flags: qr aa; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

    ; EDNS: version: 0, flags:; udp: 4096
    ; IN A


    ;; Query time: 4 msec
    ;; SERVER:
    ;; WHEN: Fri Sep 22 15:44:52 CST 2023
    ;; MSG SIZE rcvd: 76




    where are you using or applying this irule in f5 , I guess a WIDEIP must be required to get the desired results.


    Dns name to IP address is handled by system. Http request is handled by browser!

    Browser is not aware if there is a DNS CNAME.

    To make it simple, when you enter "" in your browser, the DNS resolution is done by the system. but in no case a redirection is done by dns or browser.So CNAME can't redirect URL which we input to another URL...

    If your service is hosted by F5, you can set a rule to allow you to redirect your request to another host.

    but if this is not the case you have to find you have to find other solutions. I do not think that's the best solution, but you can for example hosted a service in F5 for host "" and juste implement a redirection on host "". the other solutions is to see the side of your host so that he can make the configuration necessary to accpter the host "".

    But I'm not sure that in this case, GTM can help you because all it will do is return an IP and never redirect you...

    Without involving a WIDEIP I dont think it will work.

    for me on GTM-only iRules, but I think this will work for you:

    when DNS_REQUEST {
      if { [wideip name] eq "" } {
         cname ""



    1). Configure WIP with A record and CNAME

    2). Irules

    1. when DNS_REQUEST {
    2. if { [wideip name] eq "" } {
    3. cname ""
    4. }
    5. }



    • Mario_Franco's avatar
      Icon for Altocumulus rankAltocumulus

      Looks like the CNAMEs in F5 are not functioning. I've attempted various methods to implement a CNAME record, but it's not working. Specifically, the iRule doesn't seem to have any effect. I also attempted to create a CNAME wideIP-pool following the F5 documentation, but that didn't work either. Additionally, I tried creating a CNAME record from the ZoneRunner, but it seems impossible to create. I filled out all the fields and clicked on 'create', but upon verifying the Resource Record List, the CNAME record doesn't appear. I'm using version Could this be a bug?

  • I believe that what you want to do is use a single DNAME record that will effect the multi-CNAME behavior you want to implement.

    Specifically, in your DNS zone EXAMPLE.COM, you can create a DNAME record: <ttl> IN DNAME

    Then, for instance, using your "test" hostname, a DNS query for resolution of the IP address of FQDN should result in the dig utility returning:


    assuming that that the hostname "test" is defined to resolve to IP address in the EXAMPLE.2.COM domain.