What are the ramifications of setting the hostname?

6,071

Solution 1

I just wanted to add that the hostname should be resolvable, either through DNS or /etc/hosts. If it isn't, many tools might exhibit long delays due to a failing host name lookup. I had this problem with many GUI programs.

Solution 2

The host name (set and displayed by the hostname command, and typically stored in /etc/hostname) is used by local applications. It is not known by other machines, and cannot be used to contact the host. The host name typically appears in shell prompts, and various applications might use it for logging purposes, for example by version control software when you make a commit.

There is no technical connection between the host name and any name that other machines may use to designate your machine. The DNS is what is normally used to name a machine in an Internet context (or more precisely, a network interface). It is a good idea if your host name is identical to the first component of the DNS name of the network interface of your machine that most of the world sees. For example, if your server is connected to the rest of the world through the eth0 Ethernet interface, and the IP address of eth0 has the name foo.example.com, it is a good idea to choose foo as your host name. If you do so, foo.example.com is often called the FQDN (fully qualified domain name) of your machine. But you are free to leave them mismatched; a discrepancy can be confusing to the administrator, but doesn't matter to the software.

The host name may be used by some network protocols to identify the host. If so, it has to be sent by a local process running on the host. For example, in some setups, a DHCP client sends the hostname to the DHCP server to obtain an IP address; the DHCP server may use the claimed host name to decide which IP address to attribute to the client. In such setups, it is mandatory that the host name matches the DNS name.

Related: Why is my hostname different in Emacs?; How to make a machine accessible from the LAN using its hostname

Share:
6,071

Related videos on Youtube

cwd
Author by

cwd

Updated on September 18, 2022

Comments

  • cwd
    cwd over 1 year

    I have several Amazon EC2 servers and I'm using Chef to manage the configuration. I'd like to set the hostname so that the default bash prompt is more helpful.

    Right now after launching a new server it's just set as:

    root@ip-10-123-123-123
    

    Since I'm using Ubuntu 12 on these boxes I consulted the corresponding man page for hostname. It has a lot of good information on how to set it, and talks a little about the hostname and the fqdn, but it doesn't really tell me what I want to know:

    What are the ramifications of setting the hostname?

    I'd like to assume that setting the hostname is mostly a convenience item for users and sysadmins, giving the box a face / nice-name so it can be more easily recognized internally (via the command prompt, e-mails that are sent, etc), but I'm not positive.

    I don't see the hostname listed in the /etc/hosts file, which appears to be a good sign that it won't affect anything negatively if changed:

    127.0.0.1 localhost
    # The following lines are desirable for IPv6 capable hosts
    ::1 ip6-localhost ip6-loopback
    fe00::0 ip6-localnet
    ff00::0 ip6-mcastprefix
    ff02::1 ip6-allnodes
    ff02::2 ip6-allrouters
    ff02::3 ip6-allhosts
    

    Am I on the right track? What are the ramifications of setting the hostname?

    Update

    I tried changing the hostname on my ec2 instance from ip-10-123-123-123 to webserver and hostname --fqdn no longer works. If I put it back then it works fine. Apache also gives me an error when starting that it can't reliably determine the fqdn. I suppose there must be some way to set the hostname without messing up the fqdn.

  • cwd
    cwd over 11 years
    This is a very important point. I would upvote more than once if I could. Thank you!
  • Stéphane Chazelas
    Stéphane Chazelas over 11 years
    It's not true that it is not known by other machine. That hostname is sent by many OSes to the DHCP server when requesting a DHCP lease, and many DHCP/DNS server use it to update the local DNS zone. The hostname is used by mDNS, is used by samba (in most default samba installations), does appear in the HTTP server...
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' over 11 years
    @sch Good point about mentioning DHCP. I don't get your point about httpd: it's a local process that may decide to send the host name over the network, but the host name is still not known to other machines unless the host has sent it.
  • cwd
    cwd over 11 years
    I think this is a good answer but after playing around a little more I'm not sure if it is complete. It seems that if I change my hostname (ip-10-123-123-123) to anything else then hostname --fqdn no longer works on an ec2 instance and apache gives a warning when starting up that it can't reliably determine the fqdn. I'm not sure where to look for more information about how all these things tie together. Thanks for getting me started.
  • bryant
    bryant over 9 years
    This actually does answer the question. If you change your hostname to something that actually resolves then the hostname --fqdn still works.
  • user2948306
    user2948306 over 7 years
    hostname --fqdn (DNS) does appear to be used in logging. unix.stackexchange.com/questions/319737/…