Edit the local hosts file

30 August 2016 / Published in:  from Ivan Messina
No comments

What's the purpose of the hosts file on your computer and why to edit it?

Every website is hosted on a remote computer (server) and reachable with an IP address. To navigate a website is not convenient to write a complex url using an IP address, as it would be too hard to remember. The it has been created an association between a domain name and the IP address.

When you move a domain from one server to another what we do is to move the files from one server to another, and when the process is completed we update the dns, so we tell the domain to point to a different Ip address.

What if we want to check our website before changing the domain dns, to avoid errors? To solve this we can use our local hosts file. This is nothing more than a text file that contains a list of ip addresses linked to a domain.

For example if we add the row:

127.0.0.1  www.google.com

and try to visit google.com I will get an error since my computer will try to look for google somewhere where it is not present.

When you get a new hosting account the provider also gives you the server IP.

How to edit the hosts file on your computer

Once we have an understanding of how the hosts file works, let's see how to use it for our needs

Windows Vista and Windows 7

Vista and windows 7 use User Account Control (UAC), then you have to launch Notepad ad admin.

  1. Right click on Notepad and select run as admin
  2. Click on continue on the permission window
  3. once the Notepad click on File -> open
  4. in the name insert C:\Windows\System32\Drivers\etc\hosts
  5. Click open

Windows NT/2000/XP

  1. open Notepad
  2. click on File -> open
  3. in the name insert C:\Windows\System32\Drivers\etc\hosts
  4. Click on open
  5. edit the file

Linux

  1. Open the terminal
  2. Digit: sudo vi /etc/hosts (you can use another editor)
  3. insert the password
  4. edit the file and save

Mac OS X 10.6 - 10.1.8

  1. Open Application -> utility -> terminal
  2. Open the hosts file using the command: sudo nano /private/etc/hosts
  3. insert the password
  4. edit the hosts file
  5. Save using Control+x
  6. to apply the editing you need to flush the dns cache with the command: dscacheutil -flushcache
  7. the new setting should be active

On Mac you can also use a free software: gasmask

Android

To edit the hosts file on Android you need root permission, then you can just use an app like Hosts Editor.

 

The file hosts format is the same for all platforms, the syntax is:

IP    domain_name

Leave a Reply

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