New comers to the Linux generally asks for what is the purpose and usage of the
/etc directory holds system and service related configuration.
hosts file is used to store host name or DNS to IP address resolution. It provides easy way to match a host or DNS name with an IP address.
List Current Host or DNS to IP Address Resolutions
We can easily read and print current content of the
/etc/hosts file. Its structure is very easy to read as we will examine it below.
$ cat /etc/hosts
FQDN is structured naming of hosts in computer networks. You can read following tutorial to get more details about FQDN.
We can use FQDN is
hosts file but providing host and domain name like below. In this case we add host
test which is under
lab.com domain with IP address
As a system administrator we generally prefer to use practical ways. If the host is in the same domain with us or domain is not important we can just provide the alias like below. In this example we will provide alias
test to the IP address
Alias with Hostname
hosts file also provides the ability to use both single
alias or hostname. We will add them for the same IP address. Syntax is like below.
IPADDRESS HOSTNAME ALIAS
In this example the IP address is
192.168.1.100 alias is
test and hostname is
#IPADDRESS HOSTNAME ALIAS
192.168.1.100 test.lab.com test