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
Each line in the hosts file follows a specific format
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.
2. We need to open the Linux Terminal.
3. We need to switch to the root user to run the necessary commands.
4. 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.
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
It allows us to set up local web servers, test websites, or simulate network environments
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
6. Now we can exit the Vi text editor using the ':q' command and shut down our Alpine Linux system using the 'poweroff' command.
Well, that was fun. See you in the next tutorial! #linux