hosts file

CentOS uses the hosts file to resolve hostnames locally before trying to resolve them from a dns server in /etc/resolv.conf.

Traditionally, I preferred to not setup much in /etc/hosts and primarily use DNS for name resolution. But with the growing popularity of configuration management tools like puppet and chef, it isn’t difficult to maintain a consistent hosts file across an environment which helps lighten the load on DNS servers.

The format is simply ip address, followed by hostnames per line.

For example:

# we want the localhost ip address 127.0.0.1 to resolve as localhost
127.0.0.1 localhost
# we also want this server websrv01.centoshowtos.org to resolve to its RFC1918 address 10.66.6.25
10.66.6.25 websrv01 websrv01.centoshowtos.org

With websrv01 entered into hosts, we can resolve it a few different ways.

ping websrv01
ping websrv01.centoshowtos.org


Both of these will resolve 10.66.6.25

(Comments)

Comments