Since the early days of the internet, computers have used host files to resolve names for resources on the internet. The first hosts files were created in the ARPANET era and were used to resolve hostnames. The size of these files increased as they were used to resolve network names.

Windows, macOS, and Linux all use a hosts file to map hostnames to IP addresses. The syntax is largely the same on all systems, with the exception of loopback entries. Loopback entries are used to test whether a hostname is available or not. ..

  1. Choose the destination to which you want your address to be redirected.
  2. Enter the address that you wish to reroute it to.
  3. Type a comment below the address, telling us what you think about the redirection.

How to Edit Linux Hosts Files

Window

Notepad is a free text editor that can be found in the Windows Start menu. ..

Right-click the Notepad icon and select Run as Administrator.

notepad_test.txt Click Open. In the File contents field, type the following text: This is a test. Click File, and then click Save As. In the Save As dialog box, type notepad_test.txt in the File name field, and then click Save. ..

Scroll down to the end of the file and add your new entries:

  1. The file has been updated with new information.
  2. Scroll down to the end of the file for more information.
  3. The file has been updated with new information. ..

Save the changes by clicking File > Save.

macOS

sudo nano /etc/hosts Add the following line to the file: 127.0.0.1 localhost Save the file and close it.

The following is a list of new entries for the “Fantasy” category.

  1. “The Chronicles of Narnia: The Lion, The Witch, and The Wardrobe” by C.S. Lewis
  2. “Harry Potter and the Philosopher’s Stone” by J.K. Rowling
  3. “The Hunger Games” by Suzanne Collins
  4. “The Lord of the Rings: The Fellowship of the Ring” by J.R.R. Tolkien
  5. “The Lord of the Rings: The Two Towers” by J.R-R Tolkien

Save the changes and flush the DNS cache:

  1. Open a command prompt and type “dnsmasq -flush-cache”.
  2. If you are using Windows, you may need to run “netstat -a” to see if there is a DNS cache issue. If there is, it will be flushed automatically.

Final Words

Every significant operating system (OS), including macOS, Windows, Linux, etc., includes a hosts file. The hosts file is a plain text file that converts hostnames to IP addresses. The hosts file was the primary source of information for each machine or local network before the advent of DNS.