How to Use the “Hosts” File?

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 addressesthe 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 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.

How to Use the “Hosts” File?, Windows 8 and 10

Click the drop-down arrow under Open to access a drop-down menu, then select Run as administrator.

How to Use the “Hosts” File?, Windows 8 and 10 2

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.

How to Use the “Hosts” File?, Windows 8 and 10 3

In the drivers folder, locate and open etc, then hosts.

How to Use the “Hosts” File?, Windows 8 and 10 4

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.”

How to Use the “Hosts” File?, Windows 8 and 10 5

Open the hosts file, add your entries below the last entry and save the changes.

How to Use the “Hosts” File?, Windows 8 and 10 6

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.

Mac OS

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: 


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.

Was this helpful?

What’s your goal today?

1. Find the right Managed VPS solution

If you’re looking for industry-leading speed, ease of use and reliability Try ScalaHosting with an unconditional money-back guarantee.

2. Make your website lighting fast

We guarantee to make your WordPress site load in less than 2 seconds on a managed VPS with ScalaHosting or give your money back. Fill out the form, and we’ll be in touch.

Please enter a valid name
Please enter a valid website
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

3. Streamline your clients’ hosting experience

If you’re a web studio or development agency hosting more than 30 websites, schedule a call with Vlad, our co-founder and CTO, and see how we can deliver unmatched value to both your business and your clients.


Need a custom cluster or professional advice?

Book a meeting and get a free 30-minute consultation with Vlad, co-founder & CTO of Scala Hosting, who will help you select, design and build the right solution - from a single data center cluster to a multi-region & multi-datacenter high availability cluster with hundreds of servers.

Book a free consultation

4. Learn how to grow your website in 2024

An all-star team of SEO and web influencers are sharing their secret knowledge for the first time in years. Learn about the future of SEO, Web Design best practices and the secrets to getting the foundation for your website to thrive. Watch the exclusive webinar.

An Exclusive Insiders Look Behind The SEO and Web Development Curtain


Working in the web hosting industry for over 13 years, Rado has inevitably got some insight into the industry. A digital marketer by education, Rado is always putting himself in the client's shoes, trying to see what's best for THEM first. A man of the fine detail, you can often find him spending 10+ minutes wondering over a missing comma or slightly skewed design.