Change Your Hosts File on Windows, Mac, or Linux

how to change your hosts file

Looking to change your host file?

It is a complicated process, but not that difficult.

In this quick tutorial, I will show you how you can change your host files on Windows, macOS or Linux.

What does Host Files do?

Hosts file maps the domain names (hostnames) to the IP addresses. It is present in plain-text format and is used by all operating systems such as Linux, Windows, and macOS. You don’t have to make any changes to DNS settings if you are editing the host’s file.

Let’s understand this with an example-

  1. First, you enter serverguy.com into your browser tab and press enter.
  2. After that, the domain is translated to its corresponding IP address.
  3. The OS first checks the host file related to serverguy.com.
  4. If they found no entry for this domain in the host’s file.
  5. OS will then go to the DNS servers to the specified domain names.

Using this mechanism, you can change the DNS settings for a domain only on the machine you are working on.

Why do you need to edit the host’s file?

Modifying your host’s file enables you to test your website without the need for a DNS record. For example, you are migrating your website or ensuring it is functional before pointing it to the new server.  It can also be used to block certain websites from running on your computer. 

To modify your local host’s file you have to create an entry for the domain to which you want the IP address to point for the given website.

For example, adding the following line, to your host’s file, will point the records www.serverguy.com and serverguy.com to the IP address 1.2.3.4:

1.2.3.4 www.serverguy.com serverguy.com

When you add the information of the domain and save the changes, your computer will automatically send the domain to the specified IP address.

After you have done the migration or testing, remove the changes quickly as it can be difficult to understand why your DNS is not behaving as expected on different computers.

Let’s learn how to change your host’s file on the following operating systems:

  1. Windows® 10, Windows 8,
  2. Windows 7, and older versions
  3. Linux®
  4. MacOS® X versions 10.0 through 10.1.5

#1 Windows 10 or Windows 8

If you are working on Windows operating system, you have to use Microsoft Notepad as an administrator.

  • Press the Windows key and type in Notepad in the search bar.
  • After Notepad appears in the search result, right-click on it.
  • Select Run as administrator.
  • Go to File > Open.
  • Choose and open the following file: c:\Windows\System32\Drivers\etc\hosts
  • Make the desired changes to the file.
  • Click on File and then press Save.

#2 Windows 7, and older versions

  • Click Start > All Programs > Accessories.
  • Right-click on the Notepad
  • Select Run as administrator.
  • Go to File > Open.
  • Choose and open the following file:
 c:\Windows\System32\Drivers\etc\hosts
  • Make the desired changes to the file.
  • Click on File and then press Save.

#3 Linux

  • Open a terminal window.
  • Type in the following command in your favorite text editor:
sudo sensible-editor /etc/hosts 
  • Enter your sudo password.
  • Skip over the existing lines and make your modifications at the bottom of the file. Add your new mappings after the default mappings.
  • Make your changes to the file.
  • Press Control-X and then enter y.

#4 Mac OS X

  • Open a terminal window.
  • Open the /etc/hosts file by issuing the following command in the terminal prompt:
sudo nano /etc/hosts 
  • Type your sudo password when asked.
  • Edit the /etc/hosts file.
  • Skip over the existing lines and make your modifications at the bottom of the file. Add your new mappings after the default mappings.
  • Make your changes to the file.
  • Press Control-X and then enter y.
  • You can get the results of your changes quickly by flushing your MacOS DNS cache:
    dscacheutil -flushcache

Wrap Up

I hope you can safely change your host file in Windows, macOS, and Linux. However, if you encounter any issues, please leave them in the comment box.

ServerGuy offers customized and dedicated hosting services for eCommerce store owners to load the website in 2 seconds. You can contact us directly or leave a comment below. We will get back to you asap.

Latest Magento Tips, Guides, & News

Stay updated with new stuff in the Magento ecosystem including exclusive deals, how-to articles, new modules, and more. 100% Magento Goodness, a promise!

Leave a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top

We can help you. Right now.

Fast growing merchants depend ServerGuy for high-performance hosting. Experience counts. Let's get started.

Talk to a sales representative

USA / Worldwide

+1.714.2425683

India

+91.9852704704

Core Web Vitals Book COver

Is your website ready for Core Web Vitals?

Take this FREE book with you and optimize your store for speed.

Learn all about new Google new ranking factors and get that top ranking.