How to use the Windows "hosts" file to access a site Print

  • hosts, website access without DNS, accesso al sito senza DNS
  • 5

The hosts file is used to map domain names to IP addresses.

With hosts files you can change the IP address to which a certain domain name resolves. This change will only be made to your computer without changing how it resolves the domain in the rest of the world.

This is particularly useful for viewing or working on a site while it is hosted on a server other than the one that the authoritative DNS points to. To change the pointing of the domain name to its IP just edit the HOSTS file of the operating system used.  

The location of the hosts file depends on the operating system you are using:

Windows - registry> system32> drivers> etc> hosts
By default the registry is C: Windows, so if you are using Windows, your hosts file will most likely be: C: \ Windows \ System32 \ drivers \ etc \ hosts
Linux - / etc / hosts
Mac OS X - / private / etc / hosts
Let's say you want to resolve "domain.com" at IP address 1.2.3.4. In this case you will need to open the hosts file with a text editor and add the following line:

1.2.3.4 yourdomain.com domain.com


This will "tell" your computer to resolve domain.com as IP 1.2.3.4. Once this is done you may need to clear your browser cache, after which if you try to reach your domain in your browser it will show the site hosted on the server with IP 1.2.3.4.

You can find more detailed information on how to locate and edit the hosts file in different operating systems below:

Windows 8 and 10

Press the Windows key (formerly called the Start menu).
Use the Search and Search Notepad option.
Right click on Notepad and select Run as administrator.
From Notepad, open the hosts file from: C: \ Windows \ System32 \ drivers \ etc \ hosts
Add and save changes.

Linux

Open the Terminal.
Use the command line text editor nano or one of your choice that you have available and open the hosts file. The command with nano is as follows (the command will ask for your Linux user password): sudo nano / private / etc / hosts
Add the appropriate changes in the hosts file.
Use the Control and X combination to save the changes.

Mac OS X 10.6 to 10.12
You must be logged in with a username with administrator privileges on your MAC.

Open Applications -> Utilities -> Terminal.
Edit the hosts file with a command line text editor such as nano by typing the following line in the terminal (the command will ask for your Mac user password): sudo nano / private / etc / hosts
Add your changes at the bottom of the file.
Use the Control and X combination to save the changes.


Was this answer helpful?

« Back