Forum Discussion

Gerald_Meese's avatar
Sep 28, 2023

F5 DNS - iRule to rewrite NAPTR response

Hello,

I'm almost new to F5 DNS, and I'm trying to find how to rewrite an NAPTR response from a backend DNS server and send it bacl to the calling client.

The DNS server would answer this :
test.apn NAPTR 10 100 "A" "x-test-pgw:x-s5-gtp:x-gn" "" topoff.pgw-s5s8.pgw-PM-01.node.epc.mnc033.mcc222.test.org.

And the F5 would rewrite that answer to this double entry, and send it back to the client :
test.apn NAPTR 10 60 "A" "x-test-pgw:x-s5-gtp:x-gn" "" topoff.pgw-s5s8.pgw-PM-01.node.epc.mnc033.mcc222.test.org.

test.apn NAPTR 10 40 "A" "x-test-pgw:x-s5-gtp:x-gn" "" topoff.pgw-s5s8.pgw-PM-02.node.epc.mnc033.mcc222.test.org.

Do you think that would work ? Any guidance would be highly appreciated 🙂

I found this old post as a reference :
https://community.f5.com/t5/technical-forum/gtm-naptr-irule/m-p/18996#M2690

Thanks !!

Gerald

  • xuwen's avatar
    xuwen
    Icon for Cumulonimbus rankCumulonimbus

     

     

    when DNS_REQUEST priority 500 {
        if { ([string tolower [DNS::question type]] eq "naptr") and ([DNS::question name] eq "test.apn")} {
            DNS::answer clear
            set new_rr1 {test.apn. 1800 IN NAPTR 10 60 "a" "x-test-pgw:x-s5-gtp:x-gn" "" topoff.pgw-s5s8.pgw-PM-01.node.epc.mnc033.mcc222.test.org.}
            set new_rr2 {test.apn. 1800 IN NAPTR 10 40 "a" "x-test-pgw:x-s5-gtp:x-gn" "" topoff.pgw-s5s8.pgw-PM-02.node.epc.mnc033.mcc222.test.org.}
            set new_rr_1 [DNS::rr $new_rr1]
            set new_rr_2 [DNS::rr $new_rr2]
            DNS::answer insert $new_rr_1
            DNS::answer insert $new_rr_2
            DNS::header rd 0
            DNS::return
        }
    }

    [root@NF42GTT1-A3:Active:Standalone] config # dig @172.16.53.53 test.apn naptr

    ; <<>> DiG 9.11.31 <<>> @172.16.53.53 test.apn naptr
    ; (1 server found)
    ;; global options: +cmd
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 38382
    ;; flags: qr ad; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

    ;; OPT PSEUDOSECTION:
    ; EDNS: version: 0, flags:; udp: 4096
    ;; QUESTION SECTION:
    ;test.apn. IN NAPTR

    ;; ANSWER SECTION:
    test.apn. 1800 IN NAPTR 10 60 "a" "x-test-pgw:x-s5-gtp:x-gn" "" topoff.pgw-s5s8.pgw-PM-01.node.epc.mnc033.mcc222.test.org.
    test.apn. 1800 IN NAPTR 10 40 "a" "x-test-pgw:x-s5-gtp:x-gn" "" topoff.pgw-s5s8.pgw-PM-02.node.epc.mnc033.mcc222.test.org.

    ;; Query time: 2 msec
    ;; SERVER: 172.16.53.53#53(172.16.53.53)
    ;; WHEN: Thu Sep 28 19:24:21 CST 2023
    ;; MSG SIZE rcvd: 243

    • Many many thanks !! Will give it a try in the coming days ! Take care 🙂