Is file /etc/hostname ever used for host name resolution?












1















When setting up a local Wi-Fi network in a small place from an ISP, such as Verizon, using a router and modem, the machines in the network are assigned private IP addresses.



In such a local Wi-Fi network, I can use ssh name@<hostname> to access an SSH server on another computer <hostname>, where <hostname> is the output of command hostname. Is the output of hostname resolved to a private IP address, by some DNS server (possibly on the router?)?



But I heard that the output of hostname is unrelated to host name resolution by DNS. Then why can I successfully run ssh name@<hostname>, where <hostname> is the output of command hostname?










share|improve this question





























    1















    When setting up a local Wi-Fi network in a small place from an ISP, such as Verizon, using a router and modem, the machines in the network are assigned private IP addresses.



    In such a local Wi-Fi network, I can use ssh name@<hostname> to access an SSH server on another computer <hostname>, where <hostname> is the output of command hostname. Is the output of hostname resolved to a private IP address, by some DNS server (possibly on the router?)?



    But I heard that the output of hostname is unrelated to host name resolution by DNS. Then why can I successfully run ssh name@<hostname>, where <hostname> is the output of command hostname?










    share|improve this question



























      1












      1








      1








      When setting up a local Wi-Fi network in a small place from an ISP, such as Verizon, using a router and modem, the machines in the network are assigned private IP addresses.



      In such a local Wi-Fi network, I can use ssh name@<hostname> to access an SSH server on another computer <hostname>, where <hostname> is the output of command hostname. Is the output of hostname resolved to a private IP address, by some DNS server (possibly on the router?)?



      But I heard that the output of hostname is unrelated to host name resolution by DNS. Then why can I successfully run ssh name@<hostname>, where <hostname> is the output of command hostname?










      share|improve this question
















      When setting up a local Wi-Fi network in a small place from an ISP, such as Verizon, using a router and modem, the machines in the network are assigned private IP addresses.



      In such a local Wi-Fi network, I can use ssh name@<hostname> to access an SSH server on another computer <hostname>, where <hostname> is the output of command hostname. Is the output of hostname resolved to a private IP address, by some DNS server (possibly on the router?)?



      But I heard that the output of hostname is unrelated to host name resolution by DNS. Then why can I successfully run ssh name@<hostname>, where <hostname> is the output of command hostname?







      linux domain-name-system hostname






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 22 mins ago









      Peter Mortensen

      2,13242124




      2,13242124










      asked 6 hours ago









      TimTim

      69231526




      69231526






















          2 Answers
          2






          active

          oldest

          votes


















          4














          Linux systems using nss-myhostname will resolve the currently configured local hostname (which on some systems comes from /etc/hostname), when you use getaddrinfo/gethostbyname. Systems without nss-myhostname usually have the local hostname listed in /etc/hosts, and resolve the local hostname that way.



          If you specifically do dns lookups (e.g. with nslookup or dig), that bypasses nss and only uses dns, so nss-myhostname doesn't get a chance to influence the result.



          If you want ssh@<hostname> to work from other devices, make sure hostname resolves in dns, or is listed in /etc/hosts on those devices.






          share|improve this answer
























          • Thanks. Updated my post to avoid misleading.

            – Tim
            6 hours ago



















          1














          There are a couple of mechanisms that could be at work here.



          Firstly, a system will often include its locally-configured hostname as a DHCP Client Identifier, and the router (which is also the DHCP and DNS server) will dynamically add a DNS record for that client ID matching the IP it gave out for that request.



          The other likely case is that the system is advertizing it's locally-configured hostname using Multicast DNS Service Discovery (via Bonjour services on macOS, or the avahi daemon on Linux), and many modern distros include mDNS in their NSS lookup chain by default.






          share|improve this answer























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "2"
            };
            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%2fserverfault.com%2fquestions%2f953448%2fis-file-etc-hostname-ever-used-for-host-name-resolution%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            4














            Linux systems using nss-myhostname will resolve the currently configured local hostname (which on some systems comes from /etc/hostname), when you use getaddrinfo/gethostbyname. Systems without nss-myhostname usually have the local hostname listed in /etc/hosts, and resolve the local hostname that way.



            If you specifically do dns lookups (e.g. with nslookup or dig), that bypasses nss and only uses dns, so nss-myhostname doesn't get a chance to influence the result.



            If you want ssh@<hostname> to work from other devices, make sure hostname resolves in dns, or is listed in /etc/hosts on those devices.






            share|improve this answer
























            • Thanks. Updated my post to avoid misleading.

              – Tim
              6 hours ago
















            4














            Linux systems using nss-myhostname will resolve the currently configured local hostname (which on some systems comes from /etc/hostname), when you use getaddrinfo/gethostbyname. Systems without nss-myhostname usually have the local hostname listed in /etc/hosts, and resolve the local hostname that way.



            If you specifically do dns lookups (e.g. with nslookup or dig), that bypasses nss and only uses dns, so nss-myhostname doesn't get a chance to influence the result.



            If you want ssh@<hostname> to work from other devices, make sure hostname resolves in dns, or is listed in /etc/hosts on those devices.






            share|improve this answer
























            • Thanks. Updated my post to avoid misleading.

              – Tim
              6 hours ago














            4












            4








            4







            Linux systems using nss-myhostname will resolve the currently configured local hostname (which on some systems comes from /etc/hostname), when you use getaddrinfo/gethostbyname. Systems without nss-myhostname usually have the local hostname listed in /etc/hosts, and resolve the local hostname that way.



            If you specifically do dns lookups (e.g. with nslookup or dig), that bypasses nss and only uses dns, so nss-myhostname doesn't get a chance to influence the result.



            If you want ssh@<hostname> to work from other devices, make sure hostname resolves in dns, or is listed in /etc/hosts on those devices.






            share|improve this answer













            Linux systems using nss-myhostname will resolve the currently configured local hostname (which on some systems comes from /etc/hostname), when you use getaddrinfo/gethostbyname. Systems without nss-myhostname usually have the local hostname listed in /etc/hosts, and resolve the local hostname that way.



            If you specifically do dns lookups (e.g. with nslookup or dig), that bypasses nss and only uses dns, so nss-myhostname doesn't get a chance to influence the result.



            If you want ssh@<hostname> to work from other devices, make sure hostname resolves in dns, or is listed in /etc/hosts on those devices.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 6 hours ago









            Dennis KaarsemakerDennis Kaarsemaker

            15.8k3766




            15.8k3766













            • Thanks. Updated my post to avoid misleading.

              – Tim
              6 hours ago



















            • Thanks. Updated my post to avoid misleading.

              – Tim
              6 hours ago

















            Thanks. Updated my post to avoid misleading.

            – Tim
            6 hours ago





            Thanks. Updated my post to avoid misleading.

            – Tim
            6 hours ago













            1














            There are a couple of mechanisms that could be at work here.



            Firstly, a system will often include its locally-configured hostname as a DHCP Client Identifier, and the router (which is also the DHCP and DNS server) will dynamically add a DNS record for that client ID matching the IP it gave out for that request.



            The other likely case is that the system is advertizing it's locally-configured hostname using Multicast DNS Service Discovery (via Bonjour services on macOS, or the avahi daemon on Linux), and many modern distros include mDNS in their NSS lookup chain by default.






            share|improve this answer




























              1














              There are a couple of mechanisms that could be at work here.



              Firstly, a system will often include its locally-configured hostname as a DHCP Client Identifier, and the router (which is also the DHCP and DNS server) will dynamically add a DNS record for that client ID matching the IP it gave out for that request.



              The other likely case is that the system is advertizing it's locally-configured hostname using Multicast DNS Service Discovery (via Bonjour services on macOS, or the avahi daemon on Linux), and many modern distros include mDNS in their NSS lookup chain by default.






              share|improve this answer


























                1












                1








                1







                There are a couple of mechanisms that could be at work here.



                Firstly, a system will often include its locally-configured hostname as a DHCP Client Identifier, and the router (which is also the DHCP and DNS server) will dynamically add a DNS record for that client ID matching the IP it gave out for that request.



                The other likely case is that the system is advertizing it's locally-configured hostname using Multicast DNS Service Discovery (via Bonjour services on macOS, or the avahi daemon on Linux), and many modern distros include mDNS in their NSS lookup chain by default.






                share|improve this answer













                There are a couple of mechanisms that could be at work here.



                Firstly, a system will often include its locally-configured hostname as a DHCP Client Identifier, and the router (which is also the DHCP and DNS server) will dynamically add a DNS record for that client ID matching the IP it gave out for that request.



                The other likely case is that the system is advertizing it's locally-configured hostname using Multicast DNS Service Discovery (via Bonjour services on macOS, or the avahi daemon on Linux), and many modern distros include mDNS in their NSS lookup chain by default.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 5 hours ago









                techieb0ytechieb0y

                3,8511315




                3,8511315






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Server Fault!


                    • 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%2fserverfault.com%2fquestions%2f953448%2fis-file-etc-hostname-ever-used-for-host-name-resolution%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

                    How to make a Squid Proxy server?

                    Is this a new Fibonacci Identity?

                    19世紀