The hosts configuration file on Linux
This is the content of the hosts file opened in the vi text editor.

The hosts configuration file on Linux

The hosts configuration file provides a convenient way to manage local hostname-to-IP mappings and override DNS resolutions on a Linux system.

The full path is '/etc/hosts' and it is a plain text file that maps hostnames to IP addresses.?

It is a system file and requires root or administrative privileges to modify.


The file allows us to define custom hostname-to-IP mappings for our local system.

Each line in the hosts file follows a specific format. It consists of an IP address followed by one or more hostnames separated by whitespace. The IP address is typically followed by the associated hostname(s).

The hosts file can also handle IPv6 addresses as well as IPv4 addresses.


Let us take a look at our hosts file found on our Alpine Linux system:

1. Once our Alpine Linux virtual machine execution environment has fully booted we are ready to begin the process – system ready.

Login to our Alpine Linux Virtual machine
Login to our Alpine Linux Virtual machine.

2. We need to open the Linux Terminal.

Open the Linux Terminal
Open the Linux Terminal.

3. We need to switch to the root user to run the necessary commands.

Use the root account
Use the root account.

4. We can read the contents of the hosts file using the 'cat' command.

We can read the contents of the hosts file using the 'cat' command
We can read the contents of the hosts file using the 'cat' command.

5. We can open the hosts configuration file for editing using the vi text editor.

We can open the hosts configuration file for editing by using the vi text editor
We can open the hosts configuration file for editing by using the vi text editor.

Let's look at the first entry.

In the hosts file, the IP address "127.0.0.1" is a special address that refers to the loopback interface of the local machine. It is often associated with the hostname "localhost" and is used to refer to the current system itself.?

The loopback interface is a virtual network interface that allows a network device to communicate with itself.?

It is commonly assigned the IP address "127.0.0.1" for IPv4 or "::1" for IPv6.

The hostname "localhost" is a standard way to refer to the local machine and is often used in various network services and applications.

By mapping "127.0.0.1" to "localhost" in the hosts file, we ensure that any network requests made to "localhost" are directed to the loopback interface of the local machine. This allows the testing of network services locally without the need for an external network connection.

It allows us to set up local web servers, test websites, or simulate network environments without affecting external systems.

Please look at my other articles where I did precisely this. I ran web servers on localhost just to teach.?


The entry "localhost.lan" in the hosts file is a custom hostname defined by the system administrator. It is used to associate the IP address "127.0.0.1" (loopback address) with the hostname "localhost.lan".

The purpose of using "localhost.lan" in the hosts file can vary depending on the specific configuration or requirements of the system.

In most cases, "localhost.lan" is used as an alternative to the default "localhost" hostname to differentiate the local machine within a local network environment.?

System administrators might choose to define "localhost.lan" to mimic a domain or local network setup. It allows us to simulate network interactions and test applications that rely on specific hostnames or domain configurations.

The entry "localhost.localdomain" in the hosts file is another variation of the "localhost" hostname. It is used to associate the IP address "127.0.0.1" (loopback address) with the hostname "localhost.localdomain".

Some Linux distributions or network setups use "localhost.localdomain" as a default fallback hostname when a specific hostname or domain name is not provided during system setup.

It's important to note that the specific usage and significance of "localhost.localdomain" in the hosts file can vary depending on the system configuration and the intentions of the system administrator.

In other words, it can be used to serve many purposes.

Finally, we must remember that "127.0.0.1" for IPv4 = "::1" for IPv6.

Also, remember that modifications to the hosts file only affect the local system where the file is modified and does not propagate to other systems on the network.


6. Now we can exit the Vi text editor using the ':q' command and shut down our Alpine Linux system using the 'poweroff' command.

Now we can exit the Vi text editor using the ':q' command and shutdown our Alpine Linux system using the 'poweroff' command
Now we can exit the Vi text editor using the ':q' command and shutdown our Alpine Linux system using the 'poweroff' command

Well, that was fun. See you in the next tutorial! #linux

要查看或添加评论,请登录

Razvan Alexandru Ionica的更多文章

  • Updating Rocky Linux 9.4 packages

    Updating Rocky Linux 9.4 packages

    Rocky Linux was founded by Gregory Kurtzer, one of the original founders of CentOS, in December 2020. The project was…

  • Installing GUI on Oracle Solaris 11 (sol-11_4-text-x86.iso)

    Installing GUI on Oracle Solaris 11 (sol-11_4-text-x86.iso)

    Sun Solaris, now known as Oracle Solaris, is a Unix operating system originally developed by Sun Microsystems. Oracle…

    6 条评论
  • Updating Rocky Linux 9.4 Kernel

    Updating Rocky Linux 9.4 Kernel

    Rocky Linux is a free and open-source enterprise operating system designed to be fully compatible with Red Hat…

    8 条评论
  • Updating Rocky Linux 9.4 Multimedia Codecs

    Updating Rocky Linux 9.4 Multimedia Codecs

    Rocky Linux is an open-source enterprise operating system designed to be a downstream, community-supported…

  • Setting up OpenSolaris 2009.06 (osol-0906-x86.iso) for a virtual machine

    Setting up OpenSolaris 2009.06 (osol-0906-x86.iso) for a virtual machine

    UNIX is a powerful, multiuser, multitasking operating system originally developed in the 1960s and 1970s at AT&T's Bell…

    13 条评论
  • OpenSolaris 2009.06

    OpenSolaris 2009.06

    OpenSolaris was an open-source operating system based on the Solaris kernel and associated tools. It was initiated by…

    32 条评论
  • Force RHEL 7 to set the date 2 years in the past

    Force RHEL 7 to set the date 2 years in the past

    Here is a question from one of our fellow UNIX Europe group members: How can he force RHEL 7 to set the date 2 years in…

    12 条评论
  • Setting up RHEL 7 (rhel-server-7.9-x86_64-dvd) for a virtual machine

    Setting up RHEL 7 (rhel-server-7.9-x86_64-dvd) for a virtual machine

    RHEL 7, or Red Hat Enterprise Linux 7, was a major release of the RHEL operating system that was introduced in June…

    8 条评论
  • Update Rocky Linux from 9.3 to 9.4

    Update Rocky Linux from 9.3 to 9.4

    Rocky Linux is an exciting development in the world of Linux distributions. It was created as a direct response to the…

    2 条评论
  • Install LibreOffice on Rocky Linux 9.3

    Install LibreOffice on Rocky Linux 9.3

    Rocky Linux was created as a community-driven, enterprise-focused Linux distribution. It aims to be a downstream…

社区洞察

其他会员也浏览了