How to query macOS DNS resolver from Terminal?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I know how to query DNS using tools like dig, host, etc. But their macOS man pages state:




The results of DNS queries may also differ from queries that use the macOS DNS routing library.




Given that, how do I query DNS in terminal and get the same results as native macOS apps?



When testing DNS changes I sometimes see different results between the unix tools and native mac applications. Here is an example of what I've encountered:



$ dig +short example.com
192.168.0.100


dig shows that the DNS query returns a local address handled by our own DNS server. Meanwhile using the macOS 'Network Utility' lookup returns a cached result:



Network Utility lookup showing cached IP address



using the macOS network reachability tool, I get a cached result as well (for those not familiar with the output the IP address is revealed in the last line):



$ scutil -W -r example.com
0: direct
<SCNetworkReachability 0x7f8a39605ab0 [0x7fffa3c088f0]> {name = example.com}
Reachable

1: start
<SCNetworkReachability 0x7f8a39606000 [0x7fffa3c088f0]> {name = example.com}

2: on runloop
<SCNetworkReachability 0x7f8a39606000 [0x7fffa3c088f0]> {name = example.com (DNS query active), flags = 0x00000002, if_index = 13}
Reachable


*** 13:08:23.373

3: callback w/flags=0x00000002 (info="by name")
<SCNetworkReachability 0x7f8a39606000 [0x7fffa3c088f0]> {name = example.com (complete, 93.184.216.34, 2606:2800:220:1:248:1893:25c8:1946), flags = 0x00000002, if_index = 13}
Reachable


Is there a macOS command line utility to resolve addresses using the same heuristic that native mac apps use? Note: I am not interested in clearing the DNS cache, I'm interested in using the native macOS DNS resolver from a script. I've looked at man pages for mDNSResponder, dns-sd, scutil, networksetup, and dscacheutil none of which seem to query dns.










share|improve this question





























    0















    I know how to query DNS using tools like dig, host, etc. But their macOS man pages state:




    The results of DNS queries may also differ from queries that use the macOS DNS routing library.




    Given that, how do I query DNS in terminal and get the same results as native macOS apps?



    When testing DNS changes I sometimes see different results between the unix tools and native mac applications. Here is an example of what I've encountered:



    $ dig +short example.com
    192.168.0.100


    dig shows that the DNS query returns a local address handled by our own DNS server. Meanwhile using the macOS 'Network Utility' lookup returns a cached result:



    Network Utility lookup showing cached IP address



    using the macOS network reachability tool, I get a cached result as well (for those not familiar with the output the IP address is revealed in the last line):



    $ scutil -W -r example.com
    0: direct
    <SCNetworkReachability 0x7f8a39605ab0 [0x7fffa3c088f0]> {name = example.com}
    Reachable

    1: start
    <SCNetworkReachability 0x7f8a39606000 [0x7fffa3c088f0]> {name = example.com}

    2: on runloop
    <SCNetworkReachability 0x7f8a39606000 [0x7fffa3c088f0]> {name = example.com (DNS query active), flags = 0x00000002, if_index = 13}
    Reachable


    *** 13:08:23.373

    3: callback w/flags=0x00000002 (info="by name")
    <SCNetworkReachability 0x7f8a39606000 [0x7fffa3c088f0]> {name = example.com (complete, 93.184.216.34, 2606:2800:220:1:248:1893:25c8:1946), flags = 0x00000002, if_index = 13}
    Reachable


    Is there a macOS command line utility to resolve addresses using the same heuristic that native mac apps use? Note: I am not interested in clearing the DNS cache, I'm interested in using the native macOS DNS resolver from a script. I've looked at man pages for mDNSResponder, dns-sd, scutil, networksetup, and dscacheutil none of which seem to query dns.










    share|improve this question

























      0












      0








      0








      I know how to query DNS using tools like dig, host, etc. But their macOS man pages state:




      The results of DNS queries may also differ from queries that use the macOS DNS routing library.




      Given that, how do I query DNS in terminal and get the same results as native macOS apps?



      When testing DNS changes I sometimes see different results between the unix tools and native mac applications. Here is an example of what I've encountered:



      $ dig +short example.com
      192.168.0.100


      dig shows that the DNS query returns a local address handled by our own DNS server. Meanwhile using the macOS 'Network Utility' lookup returns a cached result:



      Network Utility lookup showing cached IP address



      using the macOS network reachability tool, I get a cached result as well (for those not familiar with the output the IP address is revealed in the last line):



      $ scutil -W -r example.com
      0: direct
      <SCNetworkReachability 0x7f8a39605ab0 [0x7fffa3c088f0]> {name = example.com}
      Reachable

      1: start
      <SCNetworkReachability 0x7f8a39606000 [0x7fffa3c088f0]> {name = example.com}

      2: on runloop
      <SCNetworkReachability 0x7f8a39606000 [0x7fffa3c088f0]> {name = example.com (DNS query active), flags = 0x00000002, if_index = 13}
      Reachable


      *** 13:08:23.373

      3: callback w/flags=0x00000002 (info="by name")
      <SCNetworkReachability 0x7f8a39606000 [0x7fffa3c088f0]> {name = example.com (complete, 93.184.216.34, 2606:2800:220:1:248:1893:25c8:1946), flags = 0x00000002, if_index = 13}
      Reachable


      Is there a macOS command line utility to resolve addresses using the same heuristic that native mac apps use? Note: I am not interested in clearing the DNS cache, I'm interested in using the native macOS DNS resolver from a script. I've looked at man pages for mDNSResponder, dns-sd, scutil, networksetup, and dscacheutil none of which seem to query dns.










      share|improve this question














      I know how to query DNS using tools like dig, host, etc. But their macOS man pages state:




      The results of DNS queries may also differ from queries that use the macOS DNS routing library.




      Given that, how do I query DNS in terminal and get the same results as native macOS apps?



      When testing DNS changes I sometimes see different results between the unix tools and native mac applications. Here is an example of what I've encountered:



      $ dig +short example.com
      192.168.0.100


      dig shows that the DNS query returns a local address handled by our own DNS server. Meanwhile using the macOS 'Network Utility' lookup returns a cached result:



      Network Utility lookup showing cached IP address



      using the macOS network reachability tool, I get a cached result as well (for those not familiar with the output the IP address is revealed in the last line):



      $ scutil -W -r example.com
      0: direct
      <SCNetworkReachability 0x7f8a39605ab0 [0x7fffa3c088f0]> {name = example.com}
      Reachable

      1: start
      <SCNetworkReachability 0x7f8a39606000 [0x7fffa3c088f0]> {name = example.com}

      2: on runloop
      <SCNetworkReachability 0x7f8a39606000 [0x7fffa3c088f0]> {name = example.com (DNS query active), flags = 0x00000002, if_index = 13}
      Reachable


      *** 13:08:23.373

      3: callback w/flags=0x00000002 (info="by name")
      <SCNetworkReachability 0x7f8a39606000 [0x7fffa3c088f0]> {name = example.com (complete, 93.184.216.34, 2606:2800:220:1:248:1893:25c8:1946), flags = 0x00000002, if_index = 13}
      Reachable


      Is there a macOS command line utility to resolve addresses using the same heuristic that native mac apps use? Note: I am not interested in clearing the DNS cache, I'm interested in using the native macOS DNS resolver from a script. I've looked at man pages for mDNSResponder, dns-sd, scutil, networksetup, and dscacheutil none of which seem to query dns.







      networking macos mac dns






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 30 at 20:34









      JoshJosh

      1462




      1462






















          1 Answer
          1






          active

          oldest

          votes


















          0














          It seems taking the effort to formulate the question I understood the problem better to perform more precise google searches and found the answer.



          On macOS querying DNS is achieved by:



          $ dscacheutil -q host -a name example.com
          name: example.com
          ipv6_address: 2606:2800:220:1:248:1893:25c8:1946

          name: example.com
          ip_address: 93.184.216.34


          Like most macOS shell commands it is not quite as nice as the unix equivalent, but it gives me consistent results with native mac apps.



          I found this from https://random.ac/cess/2018/04/12/macos-dig-vs-dscacheutil-while-using-split-dns-with-viscosity-vpn-client/






          share|improve this answer
























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "3"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1400250%2fhow-to-query-macos-dns-resolver-from-terminal%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            It seems taking the effort to formulate the question I understood the problem better to perform more precise google searches and found the answer.



            On macOS querying DNS is achieved by:



            $ dscacheutil -q host -a name example.com
            name: example.com
            ipv6_address: 2606:2800:220:1:248:1893:25c8:1946

            name: example.com
            ip_address: 93.184.216.34


            Like most macOS shell commands it is not quite as nice as the unix equivalent, but it gives me consistent results with native mac apps.



            I found this from https://random.ac/cess/2018/04/12/macos-dig-vs-dscacheutil-while-using-split-dns-with-viscosity-vpn-client/






            share|improve this answer




























              0














              It seems taking the effort to formulate the question I understood the problem better to perform more precise google searches and found the answer.



              On macOS querying DNS is achieved by:



              $ dscacheutil -q host -a name example.com
              name: example.com
              ipv6_address: 2606:2800:220:1:248:1893:25c8:1946

              name: example.com
              ip_address: 93.184.216.34


              Like most macOS shell commands it is not quite as nice as the unix equivalent, but it gives me consistent results with native mac apps.



              I found this from https://random.ac/cess/2018/04/12/macos-dig-vs-dscacheutil-while-using-split-dns-with-viscosity-vpn-client/






              share|improve this answer


























                0












                0








                0







                It seems taking the effort to formulate the question I understood the problem better to perform more precise google searches and found the answer.



                On macOS querying DNS is achieved by:



                $ dscacheutil -q host -a name example.com
                name: example.com
                ipv6_address: 2606:2800:220:1:248:1893:25c8:1946

                name: example.com
                ip_address: 93.184.216.34


                Like most macOS shell commands it is not quite as nice as the unix equivalent, but it gives me consistent results with native mac apps.



                I found this from https://random.ac/cess/2018/04/12/macos-dig-vs-dscacheutil-while-using-split-dns-with-viscosity-vpn-client/






                share|improve this answer













                It seems taking the effort to formulate the question I understood the problem better to perform more precise google searches and found the answer.



                On macOS querying DNS is achieved by:



                $ dscacheutil -q host -a name example.com
                name: example.com
                ipv6_address: 2606:2800:220:1:248:1893:25c8:1946

                name: example.com
                ip_address: 93.184.216.34


                Like most macOS shell commands it is not quite as nice as the unix equivalent, but it gives me consistent results with native mac apps.



                I found this from https://random.ac/cess/2018/04/12/macos-dig-vs-dscacheutil-while-using-split-dns-with-viscosity-vpn-client/







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 30 at 20:43









                JoshJosh

                1462




                1462






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Super User!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1400250%2fhow-to-query-macos-dns-resolver-from-terminal%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

                    Alcedinidae

                    RAC Tourist Trophy