The domain name system (DNS) is one reason we can browse the internet with ease. It allows people to connect to websites with easy-to-remember domain names instead of their IP addresses—the unique numeric ID assigned to every website.
When you try to visit a website, your browser looks for the DNS information first in your computer DNS cache. If it finds the information, the browser uses the DNS cache to connect the website; otherwise, it looks it up on DNS servers across the internet.
The DNS client cache’s hosts file helps map hostnames to their specific IP addresses. What is a hosts file, and how can you use it?
What’s a Host File
A hosts file is a system files that translates domain names into IP addresses. The local computer and operating system use the hosts file to map a connection between IP addresses and domain names.
It contains IP addresses and the domains with space in-between, with each entry sitting on a separate line. And here’s how the entries look on a host file.
You can add the space between the IP address and the domain name using the Tab key on your keyboard. The hosts file also lets users change the IP address a domain name resolves to.
For instance, you could edit your local host file to test whether a transfer to another host is successful before pointing the domain to the new server. Changes to your host file only apply to your local computer without affecting how the domain resolves worldwide. The hosts file is an alternative name resolution mechanism.
The Benefits of Using the Hosts File
The hosts file improves users’ browsing experiences by speeding up name resolutions and blocking annoying ads. Visiting a website in your hosts file resolves faster than it would if your browser looks up the IP address on DNS servers. A hosts file resolution can save up to 50 percent of the DNS lookup time, helping improve user experience and seamless browsing.
The hosts file also lets you block ads, malicious websites, and tracking sites by preventing your computer from connecting to them.
You could do this by listing the domain on the hosts file and giving it the loopback IP address of 127.0.0.1 for IPv4 network standard or ::1 for IPv6 addressing.
Using the Hosts File for the Various Operating Systems
Let’s quickly examine how to use the hosts file for some of the top operating systems in use.
Windows 8 and 10
Windows is an operating system (OS) from Microsoft to run personal computers. Take these steps to use the hosts file on a Windows computer. Open the Windows search and type Notepad into the search bar.
Click the drop-down arrow under Open to access a drop-down menu, then select Run as administrator.
You could also right-click the app to run as administrator.
To open the hosts file on Notepad, click File, then choose Open > Windows > System32. Scroll to the drivers folder and open it.
In the drivers folder, locate and open etc, then hosts.
In case you didn’t see the hosts file in the etc folder, which often happens if you’re opening the file for the first time, then switch the file type from “Text Documents (*.txt) to “All Files.”
Open the hosts file, add your entries below the last entry and save the changes.
Remember to use the Tab key to space the IP address and the domain name and the Enter key to begin a new entry.
Click Files > Save to apply the changes.
Follow these quick steps to use the hosts file on Linux computers:
- Open the Terminal by pressing CTRL + ALT + T on your keyboard.
- Run this nano command on the command line sudo nano /etc/hosts and enter your password when prompted.
- Make your entries in the host file; of course, one entry per line.
- Save the changes using the Control and X key combination.
Editing the hosts file on Mac requires the user to have administrator privileges. When you log in, take these steps to use the hosts files.
- Open Terminal on Mac with the navigation path Applications > Utilities > Terminal
- Run this command to open the hosts file on your Mac computer sudo nano /private/etc/hosts
- Make your desired changes or entries in the file.
- Use the Control and X key combination plus Y and Enter to save the changes.
Wrapping It Up?
Hosts file helps resolve domain names locally.
You could disable an entry by putting the hashtag sign “#” before the line, for example:
# 184.108.40.206 google.com.
Adding the hashtag sign makes the hosts file ignore the entry and resolve the name via the domain name system (DNS). Using website address designations like “/” or http:// also invalidates an entry.
If you have questions regarding using the hosts file, reach out to our support. We’re always available to help.