What Is /etc/hosts File and How To Create and Edit It? – POFTUT

What Is /etc/hosts File and How To Create and Edit It?


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

Hostname

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 192.168.1.100

192.168.1.100       test.lab.com

Alias

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 192.168.1.100

192.168.1.100       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.

IPADDRESS      HOSTNAME     ALIAS

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

#IPADDRESS      HOSTNAME         ALIAS

192.168.1.100   test.lab.com     test

LEARN MORE  How To Setup FortiOS or FortiGate For The First Time By Setting Static IP For The Management Port?

Leave a Comment