What Is /etc/hosts File and How To Create and Edit It?
  • Post category:Programming
  • Post comments:0 Comments
  • Post author:
  • Post published:14/04/2021
  • Post last modified:14/04/2021

New comers to the Linux generally asks for what is the purpose and usage of the /etc/hosts file. /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
List Current Host or DNS to IP Address Resolutions
List Current Host or DNS to IP Address Resolutions


FQDN is structured naming of hosts in computer networks. You can read following tutorial to get more details about FQDN.

What is FQDN (Fully Qualified Domain Name) with Examples?

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       test.lab.com


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       test

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.


In this example the IP address is alias is test and hostname is test.lab.com

#IPADDRESS      HOSTNAME         ALIAS   test.lab.com     test
LEARN MORE  What Is A DNS Server?

Leave a Reply