Results 1 to 7 of 7

Thread: /etc/hosts vs. /etc/hostname

  1. #1
    Join Date
    Mar 2010
    Beans
    46

    /etc/hosts vs. /etc/hostname

    What is the difference between /etc/hosts and /etc/hostname?

    I think the /etc/hosts file stores all ip address associated with this computer, but what about /etc/hostname?

    It sounds almost like the computer name, but what is it used for?

    Help would be much appreciated for a beginner.

  2. #2
    Join Date
    Apr 2006
    Location
    Fresno CA
    Beans
    2,790
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: /etc/hosts vs. /etc/hostname

    /etc/hostname is the where the hostname is set. It can be changed by editing the file. Normally /etc/hosts will reference the hostname as well as IP's.
    Thank a veteran -- George 8)
    Internet Coach & Writer
    Personal Blog -- 3 Joes' Blog

  3. #3
    Join Date
    Mar 2010
    Beans
    46

    Re: /etc/hosts vs. /etc/hostname

    But you can have multiple hostnames in the hosts file, but only one hostname in the hostname file?

  4. #4
    Join Date
    Apr 2006
    Location
    Fresno CA
    Beans
    2,790
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: /etc/hosts vs. /etc/hostname

    Quote Originally Posted by leesiulung View Post
    But you can have multiple hostnames in the hosts file, but only one hostname in the hostname file?
    Correct -- hostname sets your hostname, hosts relates hostnames to IP addresses.
    Thank a veteran -- George 8)
    Internet Coach & Writer
    Personal Blog -- 3 Joes' Blog

  5. #5
    Join Date
    Mar 2010
    Beans
    46

    Re: /etc/hosts vs. /etc/hostname

    So basically what is that hostname set in /etc/hostname used for in relation to

    a) apache?

    b) mail server?

    Does it have any effect at all?

  6. #6
    Join Date
    May 2008
    Location
    SoCal
    Beans
    Hidden!
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: /etc/hosts vs. /etc/hostname

    Quote Originally Posted by leesiulung View Post
    So basically what is that hostname set in /etc/hostname used for in relation to

    a) apache?

    b) mail server?

    Does it have any effect at all?
    The hostname is the name the OS recognizes as its name. At one time this was all you needed to identify one host from another. For example I have 3 hosts in my LAN. They are:
    • oak
    • elm
    • pine


    These are defined in the /etc/hostname file. There are routines in Linux that refer to the name in the hostname file.

    With TCP/IP you have an interface (NIC) that connects you to your local network. It has an IP address.

    You can communicate with these hosts using either the IP address or a more memorable alias. The easiest would be to use the hostname. This mapping of the alias originally was done with the /etc/hosts file. A logical extension of this is what is used with DNS.

    Just as you can have nicknames for your friends (i.e Bob for Robert or Bill for William) you can do the same for the machines in your network. You can have multiple entries in the /etc/hosts file. See below for an example
    Code:
    192.168.1.10  elm woody
    192.168.1.100  robert bob
    Note that these names are referring to a mapping of IP a name. You could ping the host "elm" with ping elm or you could ping the same host with the name "woody" as in ping woody. They will both resolve to the same IP address (192.168.1.10).

    This will work on a LAN but not in a WAN (internet) situation. For that you would need a DNS name (FQDN (Fully Qualified Domain Name). This usually a combination of the hostname and the domain name, as in hostname.domainname.com. If you had a domain such as tree.com you might have a FQDN like this elm.tree.com. This would be the A name record in DNS server and it would basically provide the the same IP to name mapping as a hosts file entry. You can add aliases (i.e woody) using a C name record.

    If you are running a web server (apache) or a mail server that is public facing you would need a DNS server to provide the IP to name mapping.

    I believe that you can use just the hostname mapping (no domain name) If you are running these servers only on a LAN.
    -BAB1

  7. #7
    Join Date
    Apr 2006
    Location
    Fresno CA
    Beans
    2,790
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: /etc/hosts vs. /etc/hostname

    On your LAN you can use {hostname}.local instead of an IP address. For example my hostname is Geo and it can be addressed as Geo.local
    Thank a veteran -- George 8)
    Internet Coach & Writer
    Personal Blog -- 3 Joes' Blog

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •