What Is A Hosts File?




Editorial Standards

At Your Simple Hosting, we adhere to our editorial standards to provide accurate and trustworthy information. As an affiliate, we may earn a commission from qualifying purchases – Read our editorial standards for more details.

The DNS, known as a domain name system, helps people surf the internet more easily. It lets people link to webpages with domain names, which is easier than trying to remember lengthy IP addresses.

If you attempt to look at a website, the browser you use will first search for DNS data in your computer’s DNS cache. When the browser locates the data, it will link the website through the DNS cache.

It will search for it across online DNS servers if it cannot.

A hosts file from a DNS client’s cache is a type of computer file that maps IP addresses and hostnames. If you’ve ever wondered what a hosts file is or what it does, we’ll cover more about it in this post.

You’ll discover how a host file works, the advantages of using it, and how to use a hosts file with your operating system.

What Is A Hosts File

Host File: The Basics

All computers, whether they use Windows or Mac software, have a hosts file. These files are in plain text and were originally used as a type of name resolution.

Initially, internet use was guided to target servers through the files. This process was replaced when the DNS (Domain Name System) was invented, which remains in operation today.

In the modern age, the DNS system informs internet traffic where it needs to travel.

If you type a website’s address into a browser, the browser uses the DNS system to search for the location of the website’s host server.

This appeal begins at the hosts file on your local computer. If the necessary details, “which are the server’s IP address or location”, aren’t found on it, the request carries on to outside DNS servers until it finds the address.

This lets the browser link with the website and show the content you’re searching for. This all occurs in a few milliseconds, which is incredibly fast.

A hosts file consists of domains and IP addresses with a space between them. Each entry is written on a new line.

For example:

  • google.com
  • domain.com

With this in mind, we can assume that editing the hosts file can let us sidestep the DNS. This means that any domain can resolve any IP address as we use our browser. This has a few advantages, which we’ll cover below.

Before we get into editing a hosts file, please note that a hosts file is often a hotspot for attacks. This is why it’s best to modify its properties to ‘read only’ after you’ve made any changes.

Advantages Of Editing A Hosts File

Here are some of the reasons why you may want to edit a hosts file:

Trialing A Website’s Development

Say that you are creating a new version of a client’s webpage, newcompany.com, on WordPress. This involves making modifications to a local version of a website, which would be saved on your computer.

The issue here is that any reference in the domain ‘newcompany.com’ code will make the browser send you to the website’s live version instead of the site’s local version.

This makes it a lot harder to trail any modifications you’ve changed.

If this is the case, there are a few things you can do:

  • Purchase a temporary domain and direct it to the IP address where the development version is situated.
  • Post the live website to a staging server.
  • Have the hosts file temporarily direct newcompany.com to a different server/IP address.

The hosts file method can help you avoid spending money on interim domains. This involves entering the IP address of the server you’re dealing with and its domain name.

For instance, if the IP address is, you’d change the hosts file to display: newcompany.com

This is also the case if you want to use a www domain. Simply add another line as follows: newcompany.com www.newcompany.com

You can also use both domains in one line as follows: newcompany.com www.newcompany.com

Remember that using a hosts file to direct to your local files will increase your browsing speed.

This is because the computer can bypass asking a DNS server for an IP address, directly requesting a local file instead. This means it won’t need to wait for the DNS server to send its response.

Modifying a hosts file like this is good for developers trialing in-development sites. It’s also useful when you need to overturn DNS servers to control access to network traffic and sites.

Blocking A Website

The internet is home to a great number of websites that aren’t suitable for young children. If you’re a parent or want to restrict access to certain websites, you can route a particular site’s request to your local host IP address.

However, please note that HTTPS websites won’t be blocked unless you type ‘www’ in the site’s address bar.

Additionally, as these changes take place, you’ll need to clear the browser cache to have these modifications take place.

Editing A Hosts File

Now let’s look at how you can change your hosts file on Mac and Windows.

Editing Windows 10 Hosts File

You can find the file at – C:\Windows\System32\drivers\etc

As you open a hosts file with an application like Notepad, you’ll notice a page with several numbered lines of text. Remember to select ‘Run as administrator’.

You can type the intended IP address underneath the existing lines. Type in the address, followed by a space, then the domain’s title.

For example: thisdomain.com

Press Files > Save to save the modifications.

Editing Mac Hosts File

You can find the hosts file on a Mac OS through the route /etc/hosts. You’ll need administrator privileges to make these changes.

  1. Launch Terminal on your Mac device with the actions Applications > Utilities > Terminal.
  2. Use this action to launch your Mac’s hosts file: sudo nano/private/etc/hosts
  3. Edit the hosts file as described in the Windows steps above.
  4. Once you’re done with your chances, save the file by pressing Control-O.


A hosts file is a computer file that interprets domain names into IP addresses.

You can modify a hosts file to override the DNS for a particular domain on your computer.

This has several advantages related to greater control over your machine, like blocking a website or testing a developing webpage.

About the author

Leave a Reply

Your email address will not be published. Required fields are marked *

Share via
Copy link
Powered by Social Snap