Resolving hostnames on Linux servers

To be able to resolve Internet hostnames on a Linux machine, you have to add the DNS servers that are authoritative for that particular domain in the config files of the server. There are two ways in which you can bind IPs to hostnames on a CentOS machine:
Edit /etc/hosts
To map a server to an IP add an extra line containing the IP address, a space and the hostname for that particular server. This file will be checked when a naming resolution request is needed by the server.
Edit /etc/resolve.conf
All DNS servers must be specified in this file. To add a new server simply type nameserver ip_address on a new line:
The search statement is used to inform the machine to look for hostnames under this domain when trying to resolve hostnames. There is a comment section that specifies that the file was generated by /sbin/dhclient-script. This tells us that my machine is using a DHCP server to obtain network configuration (IP, subnet mask, default gateway and DNS servers). Type dhclient interface_name:
Dhclient uses /var/run/ to store its process ID and /var/lib/dhclient/dhclient.leases to store DHCP lease information:
The /etc/nsswitch.conf is used to specify the search order when looking for hostnames.
hosts:      files dns specifies that the machine should look in the /etc/hosts file first before sending requests to the DNS servers:
Linux server

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s