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












4















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

























  • Essentially, you're not using DNS directly, but using "the resolver" (via e.g. gethostbyname), which can be configured to use a variety of subsystems, such as DNS and /etc/hosts.

    – John Wiersba
    Feb 15 at 19:57
















4















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

























  • Essentially, you're not using DNS directly, but using "the resolver" (via e.g. gethostbyname), which can be configured to use a variety of subsystems, such as DNS and /etc/hosts.

    – John Wiersba
    Feb 15 at 19:57














4












4








4


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 Feb 12 at 6:29









Peter Mortensen

2,14242124




2,14242124










asked Feb 11 at 23:53









TimTim

69031527




69031527













  • Essentially, you're not using DNS directly, but using "the resolver" (via e.g. gethostbyname), which can be configured to use a variety of subsystems, such as DNS and /etc/hosts.

    – John Wiersba
    Feb 15 at 19:57



















  • Essentially, you're not using DNS directly, but using "the resolver" (via e.g. gethostbyname), which can be configured to use a variety of subsystems, such as DNS and /etc/hosts.

    – John Wiersba
    Feb 15 at 19:57

















Essentially, you're not using DNS directly, but using "the resolver" (via e.g. gethostbyname), which can be configured to use a variety of subsystems, such as DNS and /etc/hosts.

– John Wiersba
Feb 15 at 19:57





Essentially, you're not using DNS directly, but using "the resolver" (via e.g. gethostbyname), which can be configured to use a variety of subsystems, such as DNS and /etc/hosts.

– John Wiersba
Feb 15 at 19:57










2 Answers
2






active

oldest

votes


















8














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































    7














    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
      Feb 12 at 0:36











    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









    8














    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




























      8














      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


























        8












        8








        8







        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 Feb 12 at 1:21









        techieb0ytechieb0y

        3,9411315




        3,9411315

























            7














            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
              Feb 12 at 0:36
















            7














            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
              Feb 12 at 0:36














            7












            7








            7







            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 Feb 12 at 0:33









            Dennis KaarsemakerDennis Kaarsemaker

            16k3766




            16k3766













            • Thanks. Updated my post to avoid misleading.

              – Tim
              Feb 12 at 0:36



















            • Thanks. Updated my post to avoid misleading.

              – Tim
              Feb 12 at 0:36

















            Thanks. Updated my post to avoid misleading.

            – Tim
            Feb 12 at 0:36





            Thanks. Updated my post to avoid misleading.

            – Tim
            Feb 12 at 0:36


















            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

            Index of /

            Tribalistas

            Listed building