What are the rules that decide what goes into the initial /etc/hosts file of a a server with these characteristics?

  1. It has a internal IP address for the internal subnet. which is in the 172.20.x.x range

  2. It has a public facing IP address which has a 1 to 1 mapping with the internal IP address

ifconfig only shows the internal IP address, which is 172.20.x.x,which doesn't seem to be part of the range reserved for internal networks (which is what has me somewhat confused)

  • 4
    FWIW, RFC1918 covers 172.16.x.x->172.31.x.x (amongst others) and so your 172.20.x.x is definitely inside the private range; tools.ietf.org/html/rfc1918 – Stephen Harris Jul 17 '16 at 10:31
  • What goes in it initially is whatever your distro decided. Usually an entry for and for the primary address on the first interface you configured during installation, if you chose a static address. What distro are you using? – Mark Plotnick Jul 17 '16 at 21:18
  • first rule

    syntactically correct

  • second rule

    logically true

  • third rule

    depends on your distro.

I'd expect an entry for localhost and possibly for the system's hostname. localhost may be an ipv6 entry (::1) in which case there may be an additional entry for ipv4-localhost

What you should you put in the hosts file is any IP address to domain name relations that you do not want to rely on DNS to determine. This is not default, this is customisation.

  • Fourth, site specific rules, e.g. to use configuration management to enforce the contents of hosts so that stray debug or test entries are less likely to end up backstabbing you X months down the line. Fifth, a ruthless devotion to the ... – thrig Jul 17 '16 at 15:09

172, 192 and 10 are the IPv4 first-octets used for private networks. The standard specifies ranges of values for the second octet. For 172, that's 16 through 31.

The usual practice for /etc/hosts is to provide a loopback address, which is apparently your 172 address. If you have both IPv4 and IPv6 configured, a separate address/hostname is needed for each loopback.

Often (but not required, and strongly dependent on other parts of your network configuration) people add the fully-qualified domain-name and hostname in /etc/hosts.

How the public IP address shows (or does not) depends on what devices you have configured. AWS does not normally show public addresses, as noted in discussion why does ipconfig not sure elastic ip? , but you may be configuring for some other system (even a standalone server).

Further reading:

  • 1
    Massive over simploification (to the extent that it's wrong) also does not answer the question. – Jasen Jul 17 '16 at 10:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.