Does a computer system (Linux) only have one host name?Unable to set hostname for use within networkHow to...

Should I have shared a document with a former employee?

Will copper pour help on my single-layer PCB?

Did Hitler say this quote about education?

Do gauntlets count as armor?

Could Europeans in Europe demand protection under UN Declaration on the Rights of Indigenous Peoples?

How did Jayne know when to shoot?

How electronics on board of JWST can survive the low operating temperature while it's difficult to survive lunar night?

Is encryption still applied if you ignore the SSL certificate warning for self-signed certs?

When a ball on a rope swings in a circle, is there both centripetal force and tension force?

Should I have one hand on the throttle during engine ignition?

Dative single noun Bankautomaten?

How to not confuse readers with simultaneous events?

Why do we need an estimator to be consistent?

What's a German word for »Sandbagger«?

Project Euler # 25 The 1000 digit Fibonacci index

What's the physical meaning of the statement that "photons don't have positions"?

Transistor power dissipation rating

What could make large expeditions ineffective for exploring territory full of dangers and valuable resources?

Why is this guy handcuffed censored?

Is "repository" pronounced /rɪˈpɒzɪt(ə)ri/ or ri-ˈpä-zə-ˌtȯr-ē or /rəˈpäzəˌtôrē/?

How should I interpret a promising preprint that was never published in a peer-reviewed journal?

Why aren't there any women super Grandmasters (GMs)?

Extract the attribute names from a large number of Shapefiles

Discontinuous Tube visualization



Does a computer system (Linux) only have one host name?


Unable to set hostname for use within networkHow to properly configure DNS . . . from a conceptual perspectiveWhich kind of additional cleanup may be required after removing manually added entries from /etc/hosts?What is the difference between hostname, hostname --fqdn, and hostname -AUnderstanding hostnameswhat is the value for setting a hostname in installation of oracle enterprise linux r6u5 should have?How to correctly set hostname and domain name?What is the Linux equivalent command for the Windows ipconfig /registerdns command?Fedora 26 and fully qualified domain names?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







15















hostname is used to display the system's DNS name, and to display or set its hostname or NIS domain name.



Does a computer system (Linux) only have one host name?



In virtual hosting, several host names can be resolved to different root directories in a web server. If a computer system (Linux) can only have one host name, how is virtual hosting possible?



Thanks.










share|improve this question

























  • DNS A or AAA records point to the same IP address for multiple domains. The hostname of the machine is not necessarily important.

    – RubberStamp
    Feb 11 at 23:03











  • (1) Is the output of hostname ever used in resolving hostname to IP address? (2) A means IPv4 address, AAAA IPv6. What is AAA?

    – Tim
    Feb 11 at 23:15













  • mDNS services, such as avahi depend on the machine hostname. In that case, hostname.local would resolve to the local IP address of the machine. I see someone wrote an answer which is an expansion of my first comment... too simultaneous for my browser notifications.

    – RubberStamp
    Feb 11 at 23:25











  • AAA is a 'A' short typo

    – RubberStamp
    Feb 11 at 23:33













  • Virtual Host has nothing to do with hostname. It purely depends on web server behavior. The server responses differently to different Host field of HTTP request header. I don't think typical web server would do anything related to DNS or hostname to offer virtual host functionality.

    – 炸鱼薯条德里克
    Feb 12 at 10:23


















15















hostname is used to display the system's DNS name, and to display or set its hostname or NIS domain name.



Does a computer system (Linux) only have one host name?



In virtual hosting, several host names can be resolved to different root directories in a web server. If a computer system (Linux) can only have one host name, how is virtual hosting possible?



Thanks.










share|improve this question

























  • DNS A or AAA records point to the same IP address for multiple domains. The hostname of the machine is not necessarily important.

    – RubberStamp
    Feb 11 at 23:03











  • (1) Is the output of hostname ever used in resolving hostname to IP address? (2) A means IPv4 address, AAAA IPv6. What is AAA?

    – Tim
    Feb 11 at 23:15













  • mDNS services, such as avahi depend on the machine hostname. In that case, hostname.local would resolve to the local IP address of the machine. I see someone wrote an answer which is an expansion of my first comment... too simultaneous for my browser notifications.

    – RubberStamp
    Feb 11 at 23:25











  • AAA is a 'A' short typo

    – RubberStamp
    Feb 11 at 23:33













  • Virtual Host has nothing to do with hostname. It purely depends on web server behavior. The server responses differently to different Host field of HTTP request header. I don't think typical web server would do anything related to DNS or hostname to offer virtual host functionality.

    – 炸鱼薯条德里克
    Feb 12 at 10:23














15












15








15


4






hostname is used to display the system's DNS name, and to display or set its hostname or NIS domain name.



Does a computer system (Linux) only have one host name?



In virtual hosting, several host names can be resolved to different root directories in a web server. If a computer system (Linux) can only have one host name, how is virtual hosting possible?



Thanks.










share|improve this question
















hostname is used to display the system's DNS name, and to display or set its hostname or NIS domain name.



Does a computer system (Linux) only have one host name?



In virtual hosting, several host names can be resolved to different root directories in a web server. If a computer system (Linux) can only have one host name, how is virtual hosting possible?



Thanks.







linux hostname






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 11 at 22:48









Jeff Schaller

48k11 gold badges71 silver badges156 bronze badges




48k11 gold badges71 silver badges156 bronze badges










asked Feb 11 at 22:40









TimTim

30k86 gold badges283 silver badges530 bronze badges




30k86 gold badges283 silver badges530 bronze badges













  • DNS A or AAA records point to the same IP address for multiple domains. The hostname of the machine is not necessarily important.

    – RubberStamp
    Feb 11 at 23:03











  • (1) Is the output of hostname ever used in resolving hostname to IP address? (2) A means IPv4 address, AAAA IPv6. What is AAA?

    – Tim
    Feb 11 at 23:15













  • mDNS services, such as avahi depend on the machine hostname. In that case, hostname.local would resolve to the local IP address of the machine. I see someone wrote an answer which is an expansion of my first comment... too simultaneous for my browser notifications.

    – RubberStamp
    Feb 11 at 23:25











  • AAA is a 'A' short typo

    – RubberStamp
    Feb 11 at 23:33













  • Virtual Host has nothing to do with hostname. It purely depends on web server behavior. The server responses differently to different Host field of HTTP request header. I don't think typical web server would do anything related to DNS or hostname to offer virtual host functionality.

    – 炸鱼薯条德里克
    Feb 12 at 10:23



















  • DNS A or AAA records point to the same IP address for multiple domains. The hostname of the machine is not necessarily important.

    – RubberStamp
    Feb 11 at 23:03











  • (1) Is the output of hostname ever used in resolving hostname to IP address? (2) A means IPv4 address, AAAA IPv6. What is AAA?

    – Tim
    Feb 11 at 23:15













  • mDNS services, such as avahi depend on the machine hostname. In that case, hostname.local would resolve to the local IP address of the machine. I see someone wrote an answer which is an expansion of my first comment... too simultaneous for my browser notifications.

    – RubberStamp
    Feb 11 at 23:25











  • AAA is a 'A' short typo

    – RubberStamp
    Feb 11 at 23:33













  • Virtual Host has nothing to do with hostname. It purely depends on web server behavior. The server responses differently to different Host field of HTTP request header. I don't think typical web server would do anything related to DNS or hostname to offer virtual host functionality.

    – 炸鱼薯条德里克
    Feb 12 at 10:23

















DNS A or AAA records point to the same IP address for multiple domains. The hostname of the machine is not necessarily important.

– RubberStamp
Feb 11 at 23:03





DNS A or AAA records point to the same IP address for multiple domains. The hostname of the machine is not necessarily important.

– RubberStamp
Feb 11 at 23:03













(1) Is the output of hostname ever used in resolving hostname to IP address? (2) A means IPv4 address, AAAA IPv6. What is AAA?

– Tim
Feb 11 at 23:15







(1) Is the output of hostname ever used in resolving hostname to IP address? (2) A means IPv4 address, AAAA IPv6. What is AAA?

– Tim
Feb 11 at 23:15















mDNS services, such as avahi depend on the machine hostname. In that case, hostname.local would resolve to the local IP address of the machine. I see someone wrote an answer which is an expansion of my first comment... too simultaneous for my browser notifications.

– RubberStamp
Feb 11 at 23:25





mDNS services, such as avahi depend on the machine hostname. In that case, hostname.local would resolve to the local IP address of the machine. I see someone wrote an answer which is an expansion of my first comment... too simultaneous for my browser notifications.

– RubberStamp
Feb 11 at 23:25













AAA is a 'A' short typo

– RubberStamp
Feb 11 at 23:33







AAA is a 'A' short typo

– RubberStamp
Feb 11 at 23:33















Virtual Host has nothing to do with hostname. It purely depends on web server behavior. The server responses differently to different Host field of HTTP request header. I don't think typical web server would do anything related to DNS or hostname to offer virtual host functionality.

– 炸鱼薯条德里克
Feb 12 at 10:23





Virtual Host has nothing to do with hostname. It purely depends on web server behavior. The server responses differently to different Host field of HTTP request header. I don't think typical web server would do anything related to DNS or hostname to offer virtual host functionality.

– 炸鱼薯条德里克
Feb 12 at 10:23










3 Answers
3






active

oldest

votes


















25














Yes, and no. The are two distinct things called hostnames.



The "internal" hostname is basically a string kept by the kernel. This is the one returned by the hostname command (or the gethostname() call) and it's unique within a system(*).



It's mostly used when a program wants to output some identifier for the system it's running on. E.g. h in Bash's PS1 expands to the hostname. Similarly, syslog-style logfiles also include the hostname on log entries.



(* Though as Stephen Kitt comments, namespaces can be used to show different hostnames to processes on the same system. That's mostly used for containers, which try to act like they're distinct systems.)



Then there's also DNS names that are used by other systems to look up the IP address of another. There might be more than one DNS name that point to the same IP address, and so the same host.



The internal hostname and the DNS names don't need to be the same. Suppose someone has a webserver they've decided to call orange(*), with the IP address 192.0.2.9 .
It could serve two different domains and the DNS would be set up to have www.example.org and www.example.com both point to 192.0.2.9, while the internal hostname of the system might be orange.example.org or just orange. In that case, the DNS setup would usually also have a reverse lookup on 192.0.2.9 point back to the name orange.example.org, but there's nothing to force that.



(* because they like to name their servers after fruit. Someone might use webserver1 or such, but the point is that it doesn't need to be named after one of the actual domains.)



In addition to that, virtual hosting requires that the browser tell the web server the name of the site it tried to access. Otherwise the server would not know which virtual site the client tried to reach. HTTP has the Host header for that.





What muddies the distinction between a DNS name and the internal hostname is the mDNS protocol
(implemented e.g. by the avahi daemon) and other discovery protocols. mDNS makes it possible for hosts to query all other
hosts on the same network for name information, and to make their own hostnames visible on other hosts
without explicitly setting them up in DNS.






share|improve this answer


























  • Thanks. (1) "the DNS setup would usually have 192.0.2.9 point back to the name orange.example.org" Doesn't resolving get IP address for a given host name, why the opposite? (2) Is the output of hostname ever used in resolving hostname to IP address?

    – Tim
    Feb 11 at 23:14













  • (2) ... When set up a local wifi network in your home from an ISP using a router and modem, the machines in the network can be identified by the outputs of their hostname commands, correct? Does the router act like a DNS to resolve the outputs of hostname to private IP addresses in the network?

    – Tim
    Feb 11 at 23:20








  • 1





    as for (1), there's also reverse lookups that take the IP address and return a name. (For a system with a single name and a single address, you'd want to have both resolve to the other, just for clarity's sake)

    – ilkkachu
    Feb 11 at 23:30








  • 2





    Small networks may be using mDNS. For better or worse, it lets system owners choose their own hostnames, accessible by other systems on the local network, without the need to register with a DNS server.

    – Mark Plotnick
    Feb 12 at 1:20








  • 1





    In many home networks, the local router acts as a DNS resolver. Hosts send their hostname when they request an address using DHCP, and the router remembers that name and resolves it for all hosts on the network. As Mark and RubberStamp mention, there’s also Bonjour (implemented in Avahi) which allows for service discovery on the LAN (printers in particular). Note too that hosts can have multiple IP addresses, and hostnames are now namespaced so processes can see different hostnames on the same host.

    – Stephen Kitt
    Feb 12 at 6:35



















7















Does a computer system (Linux) only have one host name?




No.



[I'll completely ignore that anybody may give your host any name they like by having a DNS record pointing to its address, or that you can have more than one alias for it in /etc/hosts, or any philosophical considerations about what a name really is]



On a linux system, the hostname is simply a per-process resource (the "UTS namespace") that is inherited by its children by default, but could be disjoined from with unshare(2) or clone(2) by using the CLONE_NEWUTS flag. You should look into the namespaces(7) manpage.



Just like pids, port numbers, mount points, etc the hostname is no longer a global identifier, and it could be virtualized just the same as the address space (virtual memory) or the file descriptor table of a process.




In virtual hosting, several host names can be resolved to different root directories in a web server. If a computer system (Linux) can only have one host name, how is virtual hosting possible?




Virtual hosting is something completely different, and it's usually done by configuring a wildcard DNS record (eg. *.foo.com => 13.13.13.13) with a web server running on 13.13.13.13 and serving different directories / resources based on value of the http Host: header[1] (which is highly configurable; most web servers are able to serve different resources based on any http header, not just Host:). In all this, the OS of the system the web server is running on plays no part.



[1] or on the value of the server name indication in case of https, which allows the same webserver to use different certificates for different virtual hosts.






share|improve this answer


























  • I have to disagree with you on this. For virtual hosting, we generally have a specific set of cname records pointing to the single host. We do not use a wildcard DNS record as we have many systems within the domain needing virtual hosts. Excluding UTS namespaces (how widely used is this anyway?), you have hostnamectl reporting a single hostname for a given server. DNS and hostnamectl are orthogonal and have little to do with each other.

    – doneal24
    Feb 12 at 20:53






  • 1





    @DougO'Neal What are you disagreeing with? That wildcard DNS records are used in the way I describe it? They're wildly used like that (sorry for the pun), whether you like it or not. That the uts info is virtualized per-process in linux? That's simply the way it is. As to the idea that namespaces are only used / to be used by canned containerization/virtualization solutions (as suggested in the other answer), sorry but that is "only girls play with dolls" or "manual transmissions are only used in heavy trucks" quality ;-)

    – Uncle Billy
    Feb 13 at 5:04





















0














You usually set a single hostname in /etc/hostname. And, you set many domain names in /etc/hosts.



UTS namespaces allow a single system to appear to have different host and domain names to different processes. For more info: https://en.wikipedia.org/wiki/Linux_namespaces. So, it is absolutely possible to have multiple hostnames and domain names for the same system. E.g., docker container inside the same host has different hostname than host system.






share|improve this answer










New contributor



Uddhav Gautam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "106"
    };
    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: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    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%2funix.stackexchange.com%2fquestions%2f500050%2fdoes-a-computer-system-linux-only-have-one-host-name%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    25














    Yes, and no. The are two distinct things called hostnames.



    The "internal" hostname is basically a string kept by the kernel. This is the one returned by the hostname command (or the gethostname() call) and it's unique within a system(*).



    It's mostly used when a program wants to output some identifier for the system it's running on. E.g. h in Bash's PS1 expands to the hostname. Similarly, syslog-style logfiles also include the hostname on log entries.



    (* Though as Stephen Kitt comments, namespaces can be used to show different hostnames to processes on the same system. That's mostly used for containers, which try to act like they're distinct systems.)



    Then there's also DNS names that are used by other systems to look up the IP address of another. There might be more than one DNS name that point to the same IP address, and so the same host.



    The internal hostname and the DNS names don't need to be the same. Suppose someone has a webserver they've decided to call orange(*), with the IP address 192.0.2.9 .
    It could serve two different domains and the DNS would be set up to have www.example.org and www.example.com both point to 192.0.2.9, while the internal hostname of the system might be orange.example.org or just orange. In that case, the DNS setup would usually also have a reverse lookup on 192.0.2.9 point back to the name orange.example.org, but there's nothing to force that.



    (* because they like to name their servers after fruit. Someone might use webserver1 or such, but the point is that it doesn't need to be named after one of the actual domains.)



    In addition to that, virtual hosting requires that the browser tell the web server the name of the site it tried to access. Otherwise the server would not know which virtual site the client tried to reach. HTTP has the Host header for that.





    What muddies the distinction between a DNS name and the internal hostname is the mDNS protocol
    (implemented e.g. by the avahi daemon) and other discovery protocols. mDNS makes it possible for hosts to query all other
    hosts on the same network for name information, and to make their own hostnames visible on other hosts
    without explicitly setting them up in DNS.






    share|improve this answer


























    • Thanks. (1) "the DNS setup would usually have 192.0.2.9 point back to the name orange.example.org" Doesn't resolving get IP address for a given host name, why the opposite? (2) Is the output of hostname ever used in resolving hostname to IP address?

      – Tim
      Feb 11 at 23:14













    • (2) ... When set up a local wifi network in your home from an ISP using a router and modem, the machines in the network can be identified by the outputs of their hostname commands, correct? Does the router act like a DNS to resolve the outputs of hostname to private IP addresses in the network?

      – Tim
      Feb 11 at 23:20








    • 1





      as for (1), there's also reverse lookups that take the IP address and return a name. (For a system with a single name and a single address, you'd want to have both resolve to the other, just for clarity's sake)

      – ilkkachu
      Feb 11 at 23:30








    • 2





      Small networks may be using mDNS. For better or worse, it lets system owners choose their own hostnames, accessible by other systems on the local network, without the need to register with a DNS server.

      – Mark Plotnick
      Feb 12 at 1:20








    • 1





      In many home networks, the local router acts as a DNS resolver. Hosts send their hostname when they request an address using DHCP, and the router remembers that name and resolves it for all hosts on the network. As Mark and RubberStamp mention, there’s also Bonjour (implemented in Avahi) which allows for service discovery on the LAN (printers in particular). Note too that hosts can have multiple IP addresses, and hostnames are now namespaced so processes can see different hostnames on the same host.

      – Stephen Kitt
      Feb 12 at 6:35
















    25














    Yes, and no. The are two distinct things called hostnames.



    The "internal" hostname is basically a string kept by the kernel. This is the one returned by the hostname command (or the gethostname() call) and it's unique within a system(*).



    It's mostly used when a program wants to output some identifier for the system it's running on. E.g. h in Bash's PS1 expands to the hostname. Similarly, syslog-style logfiles also include the hostname on log entries.



    (* Though as Stephen Kitt comments, namespaces can be used to show different hostnames to processes on the same system. That's mostly used for containers, which try to act like they're distinct systems.)



    Then there's also DNS names that are used by other systems to look up the IP address of another. There might be more than one DNS name that point to the same IP address, and so the same host.



    The internal hostname and the DNS names don't need to be the same. Suppose someone has a webserver they've decided to call orange(*), with the IP address 192.0.2.9 .
    It could serve two different domains and the DNS would be set up to have www.example.org and www.example.com both point to 192.0.2.9, while the internal hostname of the system might be orange.example.org or just orange. In that case, the DNS setup would usually also have a reverse lookup on 192.0.2.9 point back to the name orange.example.org, but there's nothing to force that.



    (* because they like to name their servers after fruit. Someone might use webserver1 or such, but the point is that it doesn't need to be named after one of the actual domains.)



    In addition to that, virtual hosting requires that the browser tell the web server the name of the site it tried to access. Otherwise the server would not know which virtual site the client tried to reach. HTTP has the Host header for that.





    What muddies the distinction between a DNS name and the internal hostname is the mDNS protocol
    (implemented e.g. by the avahi daemon) and other discovery protocols. mDNS makes it possible for hosts to query all other
    hosts on the same network for name information, and to make their own hostnames visible on other hosts
    without explicitly setting them up in DNS.






    share|improve this answer


























    • Thanks. (1) "the DNS setup would usually have 192.0.2.9 point back to the name orange.example.org" Doesn't resolving get IP address for a given host name, why the opposite? (2) Is the output of hostname ever used in resolving hostname to IP address?

      – Tim
      Feb 11 at 23:14













    • (2) ... When set up a local wifi network in your home from an ISP using a router and modem, the machines in the network can be identified by the outputs of their hostname commands, correct? Does the router act like a DNS to resolve the outputs of hostname to private IP addresses in the network?

      – Tim
      Feb 11 at 23:20








    • 1





      as for (1), there's also reverse lookups that take the IP address and return a name. (For a system with a single name and a single address, you'd want to have both resolve to the other, just for clarity's sake)

      – ilkkachu
      Feb 11 at 23:30








    • 2





      Small networks may be using mDNS. For better or worse, it lets system owners choose their own hostnames, accessible by other systems on the local network, without the need to register with a DNS server.

      – Mark Plotnick
      Feb 12 at 1:20








    • 1





      In many home networks, the local router acts as a DNS resolver. Hosts send their hostname when they request an address using DHCP, and the router remembers that name and resolves it for all hosts on the network. As Mark and RubberStamp mention, there’s also Bonjour (implemented in Avahi) which allows for service discovery on the LAN (printers in particular). Note too that hosts can have multiple IP addresses, and hostnames are now namespaced so processes can see different hostnames on the same host.

      – Stephen Kitt
      Feb 12 at 6:35














    25












    25








    25







    Yes, and no. The are two distinct things called hostnames.



    The "internal" hostname is basically a string kept by the kernel. This is the one returned by the hostname command (or the gethostname() call) and it's unique within a system(*).



    It's mostly used when a program wants to output some identifier for the system it's running on. E.g. h in Bash's PS1 expands to the hostname. Similarly, syslog-style logfiles also include the hostname on log entries.



    (* Though as Stephen Kitt comments, namespaces can be used to show different hostnames to processes on the same system. That's mostly used for containers, which try to act like they're distinct systems.)



    Then there's also DNS names that are used by other systems to look up the IP address of another. There might be more than one DNS name that point to the same IP address, and so the same host.



    The internal hostname and the DNS names don't need to be the same. Suppose someone has a webserver they've decided to call orange(*), with the IP address 192.0.2.9 .
    It could serve two different domains and the DNS would be set up to have www.example.org and www.example.com both point to 192.0.2.9, while the internal hostname of the system might be orange.example.org or just orange. In that case, the DNS setup would usually also have a reverse lookup on 192.0.2.9 point back to the name orange.example.org, but there's nothing to force that.



    (* because they like to name their servers after fruit. Someone might use webserver1 or such, but the point is that it doesn't need to be named after one of the actual domains.)



    In addition to that, virtual hosting requires that the browser tell the web server the name of the site it tried to access. Otherwise the server would not know which virtual site the client tried to reach. HTTP has the Host header for that.





    What muddies the distinction between a DNS name and the internal hostname is the mDNS protocol
    (implemented e.g. by the avahi daemon) and other discovery protocols. mDNS makes it possible for hosts to query all other
    hosts on the same network for name information, and to make their own hostnames visible on other hosts
    without explicitly setting them up in DNS.






    share|improve this answer















    Yes, and no. The are two distinct things called hostnames.



    The "internal" hostname is basically a string kept by the kernel. This is the one returned by the hostname command (or the gethostname() call) and it's unique within a system(*).



    It's mostly used when a program wants to output some identifier for the system it's running on. E.g. h in Bash's PS1 expands to the hostname. Similarly, syslog-style logfiles also include the hostname on log entries.



    (* Though as Stephen Kitt comments, namespaces can be used to show different hostnames to processes on the same system. That's mostly used for containers, which try to act like they're distinct systems.)



    Then there's also DNS names that are used by other systems to look up the IP address of another. There might be more than one DNS name that point to the same IP address, and so the same host.



    The internal hostname and the DNS names don't need to be the same. Suppose someone has a webserver they've decided to call orange(*), with the IP address 192.0.2.9 .
    It could serve two different domains and the DNS would be set up to have www.example.org and www.example.com both point to 192.0.2.9, while the internal hostname of the system might be orange.example.org or just orange. In that case, the DNS setup would usually also have a reverse lookup on 192.0.2.9 point back to the name orange.example.org, but there's nothing to force that.



    (* because they like to name their servers after fruit. Someone might use webserver1 or such, but the point is that it doesn't need to be named after one of the actual domains.)



    In addition to that, virtual hosting requires that the browser tell the web server the name of the site it tried to access. Otherwise the server would not know which virtual site the client tried to reach. HTTP has the Host header for that.





    What muddies the distinction between a DNS name and the internal hostname is the mDNS protocol
    (implemented e.g. by the avahi daemon) and other discovery protocols. mDNS makes it possible for hosts to query all other
    hosts on the same network for name information, and to make their own hostnames visible on other hosts
    without explicitly setting them up in DNS.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Feb 12 at 19:51

























    answered Feb 11 at 23:04









    ilkkachuilkkachu

    65.5k10 gold badges109 silver badges189 bronze badges




    65.5k10 gold badges109 silver badges189 bronze badges













    • Thanks. (1) "the DNS setup would usually have 192.0.2.9 point back to the name orange.example.org" Doesn't resolving get IP address for a given host name, why the opposite? (2) Is the output of hostname ever used in resolving hostname to IP address?

      – Tim
      Feb 11 at 23:14













    • (2) ... When set up a local wifi network in your home from an ISP using a router and modem, the machines in the network can be identified by the outputs of their hostname commands, correct? Does the router act like a DNS to resolve the outputs of hostname to private IP addresses in the network?

      – Tim
      Feb 11 at 23:20








    • 1





      as for (1), there's also reverse lookups that take the IP address and return a name. (For a system with a single name and a single address, you'd want to have both resolve to the other, just for clarity's sake)

      – ilkkachu
      Feb 11 at 23:30








    • 2





      Small networks may be using mDNS. For better or worse, it lets system owners choose their own hostnames, accessible by other systems on the local network, without the need to register with a DNS server.

      – Mark Plotnick
      Feb 12 at 1:20








    • 1





      In many home networks, the local router acts as a DNS resolver. Hosts send their hostname when they request an address using DHCP, and the router remembers that name and resolves it for all hosts on the network. As Mark and RubberStamp mention, there’s also Bonjour (implemented in Avahi) which allows for service discovery on the LAN (printers in particular). Note too that hosts can have multiple IP addresses, and hostnames are now namespaced so processes can see different hostnames on the same host.

      – Stephen Kitt
      Feb 12 at 6:35



















    • Thanks. (1) "the DNS setup would usually have 192.0.2.9 point back to the name orange.example.org" Doesn't resolving get IP address for a given host name, why the opposite? (2) Is the output of hostname ever used in resolving hostname to IP address?

      – Tim
      Feb 11 at 23:14













    • (2) ... When set up a local wifi network in your home from an ISP using a router and modem, the machines in the network can be identified by the outputs of their hostname commands, correct? Does the router act like a DNS to resolve the outputs of hostname to private IP addresses in the network?

      – Tim
      Feb 11 at 23:20








    • 1





      as for (1), there's also reverse lookups that take the IP address and return a name. (For a system with a single name and a single address, you'd want to have both resolve to the other, just for clarity's sake)

      – ilkkachu
      Feb 11 at 23:30








    • 2





      Small networks may be using mDNS. For better or worse, it lets system owners choose their own hostnames, accessible by other systems on the local network, without the need to register with a DNS server.

      – Mark Plotnick
      Feb 12 at 1:20








    • 1





      In many home networks, the local router acts as a DNS resolver. Hosts send their hostname when they request an address using DHCP, and the router remembers that name and resolves it for all hosts on the network. As Mark and RubberStamp mention, there’s also Bonjour (implemented in Avahi) which allows for service discovery on the LAN (printers in particular). Note too that hosts can have multiple IP addresses, and hostnames are now namespaced so processes can see different hostnames on the same host.

      – Stephen Kitt
      Feb 12 at 6:35

















    Thanks. (1) "the DNS setup would usually have 192.0.2.9 point back to the name orange.example.org" Doesn't resolving get IP address for a given host name, why the opposite? (2) Is the output of hostname ever used in resolving hostname to IP address?

    – Tim
    Feb 11 at 23:14







    Thanks. (1) "the DNS setup would usually have 192.0.2.9 point back to the name orange.example.org" Doesn't resolving get IP address for a given host name, why the opposite? (2) Is the output of hostname ever used in resolving hostname to IP address?

    – Tim
    Feb 11 at 23:14















    (2) ... When set up a local wifi network in your home from an ISP using a router and modem, the machines in the network can be identified by the outputs of their hostname commands, correct? Does the router act like a DNS to resolve the outputs of hostname to private IP addresses in the network?

    – Tim
    Feb 11 at 23:20







    (2) ... When set up a local wifi network in your home from an ISP using a router and modem, the machines in the network can be identified by the outputs of their hostname commands, correct? Does the router act like a DNS to resolve the outputs of hostname to private IP addresses in the network?

    – Tim
    Feb 11 at 23:20






    1




    1





    as for (1), there's also reverse lookups that take the IP address and return a name. (For a system with a single name and a single address, you'd want to have both resolve to the other, just for clarity's sake)

    – ilkkachu
    Feb 11 at 23:30







    as for (1), there's also reverse lookups that take the IP address and return a name. (For a system with a single name and a single address, you'd want to have both resolve to the other, just for clarity's sake)

    – ilkkachu
    Feb 11 at 23:30






    2




    2





    Small networks may be using mDNS. For better or worse, it lets system owners choose their own hostnames, accessible by other systems on the local network, without the need to register with a DNS server.

    – Mark Plotnick
    Feb 12 at 1:20







    Small networks may be using mDNS. For better or worse, it lets system owners choose their own hostnames, accessible by other systems on the local network, without the need to register with a DNS server.

    – Mark Plotnick
    Feb 12 at 1:20






    1




    1





    In many home networks, the local router acts as a DNS resolver. Hosts send their hostname when they request an address using DHCP, and the router remembers that name and resolves it for all hosts on the network. As Mark and RubberStamp mention, there’s also Bonjour (implemented in Avahi) which allows for service discovery on the LAN (printers in particular). Note too that hosts can have multiple IP addresses, and hostnames are now namespaced so processes can see different hostnames on the same host.

    – Stephen Kitt
    Feb 12 at 6:35





    In many home networks, the local router acts as a DNS resolver. Hosts send their hostname when they request an address using DHCP, and the router remembers that name and resolves it for all hosts on the network. As Mark and RubberStamp mention, there’s also Bonjour (implemented in Avahi) which allows for service discovery on the LAN (printers in particular). Note too that hosts can have multiple IP addresses, and hostnames are now namespaced so processes can see different hostnames on the same host.

    – Stephen Kitt
    Feb 12 at 6:35













    7















    Does a computer system (Linux) only have one host name?




    No.



    [I'll completely ignore that anybody may give your host any name they like by having a DNS record pointing to its address, or that you can have more than one alias for it in /etc/hosts, or any philosophical considerations about what a name really is]



    On a linux system, the hostname is simply a per-process resource (the "UTS namespace") that is inherited by its children by default, but could be disjoined from with unshare(2) or clone(2) by using the CLONE_NEWUTS flag. You should look into the namespaces(7) manpage.



    Just like pids, port numbers, mount points, etc the hostname is no longer a global identifier, and it could be virtualized just the same as the address space (virtual memory) or the file descriptor table of a process.




    In virtual hosting, several host names can be resolved to different root directories in a web server. If a computer system (Linux) can only have one host name, how is virtual hosting possible?




    Virtual hosting is something completely different, and it's usually done by configuring a wildcard DNS record (eg. *.foo.com => 13.13.13.13) with a web server running on 13.13.13.13 and serving different directories / resources based on value of the http Host: header[1] (which is highly configurable; most web servers are able to serve different resources based on any http header, not just Host:). In all this, the OS of the system the web server is running on plays no part.



    [1] or on the value of the server name indication in case of https, which allows the same webserver to use different certificates for different virtual hosts.






    share|improve this answer


























    • I have to disagree with you on this. For virtual hosting, we generally have a specific set of cname records pointing to the single host. We do not use a wildcard DNS record as we have many systems within the domain needing virtual hosts. Excluding UTS namespaces (how widely used is this anyway?), you have hostnamectl reporting a single hostname for a given server. DNS and hostnamectl are orthogonal and have little to do with each other.

      – doneal24
      Feb 12 at 20:53






    • 1





      @DougO'Neal What are you disagreeing with? That wildcard DNS records are used in the way I describe it? They're wildly used like that (sorry for the pun), whether you like it or not. That the uts info is virtualized per-process in linux? That's simply the way it is. As to the idea that namespaces are only used / to be used by canned containerization/virtualization solutions (as suggested in the other answer), sorry but that is "only girls play with dolls" or "manual transmissions are only used in heavy trucks" quality ;-)

      – Uncle Billy
      Feb 13 at 5:04


















    7















    Does a computer system (Linux) only have one host name?




    No.



    [I'll completely ignore that anybody may give your host any name they like by having a DNS record pointing to its address, or that you can have more than one alias for it in /etc/hosts, or any philosophical considerations about what a name really is]



    On a linux system, the hostname is simply a per-process resource (the "UTS namespace") that is inherited by its children by default, but could be disjoined from with unshare(2) or clone(2) by using the CLONE_NEWUTS flag. You should look into the namespaces(7) manpage.



    Just like pids, port numbers, mount points, etc the hostname is no longer a global identifier, and it could be virtualized just the same as the address space (virtual memory) or the file descriptor table of a process.




    In virtual hosting, several host names can be resolved to different root directories in a web server. If a computer system (Linux) can only have one host name, how is virtual hosting possible?




    Virtual hosting is something completely different, and it's usually done by configuring a wildcard DNS record (eg. *.foo.com => 13.13.13.13) with a web server running on 13.13.13.13 and serving different directories / resources based on value of the http Host: header[1] (which is highly configurable; most web servers are able to serve different resources based on any http header, not just Host:). In all this, the OS of the system the web server is running on plays no part.



    [1] or on the value of the server name indication in case of https, which allows the same webserver to use different certificates for different virtual hosts.






    share|improve this answer


























    • I have to disagree with you on this. For virtual hosting, we generally have a specific set of cname records pointing to the single host. We do not use a wildcard DNS record as we have many systems within the domain needing virtual hosts. Excluding UTS namespaces (how widely used is this anyway?), you have hostnamectl reporting a single hostname for a given server. DNS and hostnamectl are orthogonal and have little to do with each other.

      – doneal24
      Feb 12 at 20:53






    • 1





      @DougO'Neal What are you disagreeing with? That wildcard DNS records are used in the way I describe it? They're wildly used like that (sorry for the pun), whether you like it or not. That the uts info is virtualized per-process in linux? That's simply the way it is. As to the idea that namespaces are only used / to be used by canned containerization/virtualization solutions (as suggested in the other answer), sorry but that is "only girls play with dolls" or "manual transmissions are only used in heavy trucks" quality ;-)

      – Uncle Billy
      Feb 13 at 5:04
















    7












    7








    7








    Does a computer system (Linux) only have one host name?




    No.



    [I'll completely ignore that anybody may give your host any name they like by having a DNS record pointing to its address, or that you can have more than one alias for it in /etc/hosts, or any philosophical considerations about what a name really is]



    On a linux system, the hostname is simply a per-process resource (the "UTS namespace") that is inherited by its children by default, but could be disjoined from with unshare(2) or clone(2) by using the CLONE_NEWUTS flag. You should look into the namespaces(7) manpage.



    Just like pids, port numbers, mount points, etc the hostname is no longer a global identifier, and it could be virtualized just the same as the address space (virtual memory) or the file descriptor table of a process.




    In virtual hosting, several host names can be resolved to different root directories in a web server. If a computer system (Linux) can only have one host name, how is virtual hosting possible?




    Virtual hosting is something completely different, and it's usually done by configuring a wildcard DNS record (eg. *.foo.com => 13.13.13.13) with a web server running on 13.13.13.13 and serving different directories / resources based on value of the http Host: header[1] (which is highly configurable; most web servers are able to serve different resources based on any http header, not just Host:). In all this, the OS of the system the web server is running on plays no part.



    [1] or on the value of the server name indication in case of https, which allows the same webserver to use different certificates for different virtual hosts.






    share|improve this answer
















    Does a computer system (Linux) only have one host name?




    No.



    [I'll completely ignore that anybody may give your host any name they like by having a DNS record pointing to its address, or that you can have more than one alias for it in /etc/hosts, or any philosophical considerations about what a name really is]



    On a linux system, the hostname is simply a per-process resource (the "UTS namespace") that is inherited by its children by default, but could be disjoined from with unshare(2) or clone(2) by using the CLONE_NEWUTS flag. You should look into the namespaces(7) manpage.



    Just like pids, port numbers, mount points, etc the hostname is no longer a global identifier, and it could be virtualized just the same as the address space (virtual memory) or the file descriptor table of a process.




    In virtual hosting, several host names can be resolved to different root directories in a web server. If a computer system (Linux) can only have one host name, how is virtual hosting possible?




    Virtual hosting is something completely different, and it's usually done by configuring a wildcard DNS record (eg. *.foo.com => 13.13.13.13) with a web server running on 13.13.13.13 and serving different directories / resources based on value of the http Host: header[1] (which is highly configurable; most web servers are able to serve different resources based on any http header, not just Host:). In all this, the OS of the system the web server is running on plays no part.



    [1] or on the value of the server name indication in case of https, which allows the same webserver to use different certificates for different virtual hosts.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Feb 12 at 14:23

























    answered Feb 12 at 7:18









    Uncle BillyUncle Billy

    1,1581 silver badge8 bronze badges




    1,1581 silver badge8 bronze badges













    • I have to disagree with you on this. For virtual hosting, we generally have a specific set of cname records pointing to the single host. We do not use a wildcard DNS record as we have many systems within the domain needing virtual hosts. Excluding UTS namespaces (how widely used is this anyway?), you have hostnamectl reporting a single hostname for a given server. DNS and hostnamectl are orthogonal and have little to do with each other.

      – doneal24
      Feb 12 at 20:53






    • 1





      @DougO'Neal What are you disagreeing with? That wildcard DNS records are used in the way I describe it? They're wildly used like that (sorry for the pun), whether you like it or not. That the uts info is virtualized per-process in linux? That's simply the way it is. As to the idea that namespaces are only used / to be used by canned containerization/virtualization solutions (as suggested in the other answer), sorry but that is "only girls play with dolls" or "manual transmissions are only used in heavy trucks" quality ;-)

      – Uncle Billy
      Feb 13 at 5:04





















    • I have to disagree with you on this. For virtual hosting, we generally have a specific set of cname records pointing to the single host. We do not use a wildcard DNS record as we have many systems within the domain needing virtual hosts. Excluding UTS namespaces (how widely used is this anyway?), you have hostnamectl reporting a single hostname for a given server. DNS and hostnamectl are orthogonal and have little to do with each other.

      – doneal24
      Feb 12 at 20:53






    • 1





      @DougO'Neal What are you disagreeing with? That wildcard DNS records are used in the way I describe it? They're wildly used like that (sorry for the pun), whether you like it or not. That the uts info is virtualized per-process in linux? That's simply the way it is. As to the idea that namespaces are only used / to be used by canned containerization/virtualization solutions (as suggested in the other answer), sorry but that is "only girls play with dolls" or "manual transmissions are only used in heavy trucks" quality ;-)

      – Uncle Billy
      Feb 13 at 5:04



















    I have to disagree with you on this. For virtual hosting, we generally have a specific set of cname records pointing to the single host. We do not use a wildcard DNS record as we have many systems within the domain needing virtual hosts. Excluding UTS namespaces (how widely used is this anyway?), you have hostnamectl reporting a single hostname for a given server. DNS and hostnamectl are orthogonal and have little to do with each other.

    – doneal24
    Feb 12 at 20:53





    I have to disagree with you on this. For virtual hosting, we generally have a specific set of cname records pointing to the single host. We do not use a wildcard DNS record as we have many systems within the domain needing virtual hosts. Excluding UTS namespaces (how widely used is this anyway?), you have hostnamectl reporting a single hostname for a given server. DNS and hostnamectl are orthogonal and have little to do with each other.

    – doneal24
    Feb 12 at 20:53




    1




    1





    @DougO'Neal What are you disagreeing with? That wildcard DNS records are used in the way I describe it? They're wildly used like that (sorry for the pun), whether you like it or not. That the uts info is virtualized per-process in linux? That's simply the way it is. As to the idea that namespaces are only used / to be used by canned containerization/virtualization solutions (as suggested in the other answer), sorry but that is "only girls play with dolls" or "manual transmissions are only used in heavy trucks" quality ;-)

    – Uncle Billy
    Feb 13 at 5:04







    @DougO'Neal What are you disagreeing with? That wildcard DNS records are used in the way I describe it? They're wildly used like that (sorry for the pun), whether you like it or not. That the uts info is virtualized per-process in linux? That's simply the way it is. As to the idea that namespaces are only used / to be used by canned containerization/virtualization solutions (as suggested in the other answer), sorry but that is "only girls play with dolls" or "manual transmissions are only used in heavy trucks" quality ;-)

    – Uncle Billy
    Feb 13 at 5:04













    0














    You usually set a single hostname in /etc/hostname. And, you set many domain names in /etc/hosts.



    UTS namespaces allow a single system to appear to have different host and domain names to different processes. For more info: https://en.wikipedia.org/wiki/Linux_namespaces. So, it is absolutely possible to have multiple hostnames and domain names for the same system. E.g., docker container inside the same host has different hostname than host system.






    share|improve this answer










    New contributor



    Uddhav Gautam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.
























      0














      You usually set a single hostname in /etc/hostname. And, you set many domain names in /etc/hosts.



      UTS namespaces allow a single system to appear to have different host and domain names to different processes. For more info: https://en.wikipedia.org/wiki/Linux_namespaces. So, it is absolutely possible to have multiple hostnames and domain names for the same system. E.g., docker container inside the same host has different hostname than host system.






      share|improve this answer










      New contributor



      Uddhav Gautam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















        0












        0








        0







        You usually set a single hostname in /etc/hostname. And, you set many domain names in /etc/hosts.



        UTS namespaces allow a single system to appear to have different host and domain names to different processes. For more info: https://en.wikipedia.org/wiki/Linux_namespaces. So, it is absolutely possible to have multiple hostnames and domain names for the same system. E.g., docker container inside the same host has different hostname than host system.






        share|improve this answer










        New contributor



        Uddhav Gautam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        You usually set a single hostname in /etc/hostname. And, you set many domain names in /etc/hosts.



        UTS namespaces allow a single system to appear to have different host and domain names to different processes. For more info: https://en.wikipedia.org/wiki/Linux_namespaces. So, it is absolutely possible to have multiple hostnames and domain names for the same system. E.g., docker container inside the same host has different hostname than host system.







        share|improve this answer










        New contributor



        Uddhav Gautam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.








        share|improve this answer



        share|improve this answer








        edited 15 mins ago





















        New contributor



        Uddhav Gautam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.








        answered 21 mins ago









        Uddhav GautamUddhav Gautam

        1034 bronze badges




        1034 bronze badges




        New contributor



        Uddhav Gautam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.




        New contributor




        Uddhav Gautam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • 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%2funix.stackexchange.com%2fquestions%2f500050%2fdoes-a-computer-system-linux-only-have-one-host-name%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

            Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

            Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

            Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...