Skip to main content
edit the hosts file

How to Edit The Hosts File Of Your Local System

The hosts file on your computer allows you to bypass the DNS. This means, by editing the hosts file on your computer, you can actually map a domain name to any IP address in the Internet. So, in this article, we will discuss how to edit the hosts file to override the DNS for a website.

Why and How to Edit The Hosts File?

This is useful when you want to test your site without a temporary URL ( like http://IP/~username ), prior to DNS changes, before going live with SSL or for any other DNS-related reasons.

You need to add the following entries to your systems hosts file in order to resolve the website to a particular IP Address:

  1. The IP Address
  2. The website name

So, if you want to point the websites domain.com and www.domain.com to your new hosting server IP Address 1.2.3.4, edit the hosts file of your local system with the following entries.

1.2.3.4      domain.com        www.domain.com

Let’s have look at accessing the hosts files in the different operating systems:

Windows

  1. Click Start.
  2. Enter Notepad in the Start menu search text box.
  3. Right-click Notepad and select Run as Administrator.
  4. From the Notepad, open the following file:
    C:\Windows\System32\Drivers\etc\hosts 
    It will looks like the screenshot below:

  5. Now, add the above entry, i.e, the destination server’s IP address and the domain name details at the end of the file.(Do not include the # at the beginning of the entry)
  6. Save the changes

MacOS and Linux

  1. Access the terminal/console on your system
  2. Switch to the root user/sudo user
  3. Open the /etc/hosts file with a text editor.
    It will looks like the screenshot below:

  4. Now, add the destination server’s IP address and domain name at the end of the file. (Do not include the # at the beginning of the entry)
  5. Save the changes

Thats all!!. You have done the mapping between domain name and IP locally on your system. You can access the domain on your favorite web browser and it will resolve from the mentioned IP address in the hosts file.

How to Edit The Hosts File Of Your Local System
5 (100%) 3 vote[s]

Vipin Haridas

Vipin Haridas is a Linux and Open Source enthusiast who loves to share knowledge on the Internet.