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

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/what-is-etc-hosts-file-and-how-to-create-and-edit-it/
PINTEREST
PINTEREST
INSTAGRAM

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.

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

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

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.

LEARN MORE  Linux Network Administration with ping and ip Commands

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

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/what-is-etc-hosts-file-and-how-to-create-and-edit-it/
PINTEREST
PINTEREST
INSTAGRAM

You may also like...

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)