Sun

Editing a hosts file

Editing a hosts file

The hosts file is used by the operating system to link domains to IP addresses. This file is very convenient to adjust when a site is moved to a new server but your domain is still directed to the old server. In cases like that, you can edit Hosts file on your computer and see how the website is working on a new server. All other visitors will be redirected to the old server but you will be able to see the website from the new server on your computer.

Typically, this file records in the following format:

IP_ADDRESS (SUB)DOMAIN

IP_ADDRESS: The server from which the site will be loaded
(SUB) DOMAIN: subdomain or domain to be temporarily (locally) directed to the specified IP address

Suppose the site my-site.com, which runs on server 62.77.153.100, is required to be loaded from the server for testing purposes 198.7.58.222. The following lines should be added to the Hosts file:

198.7.58.222 www.my-site.com
198.7.58.222 my-site.com

File editing

On each OS hosts file is stored and edited in slightly different ways. Major OS:

Windows 7, 8, 10:

Catalog: %systemic%\32\system\drivers (most often C:\windows\system32\drivers\etc\)
Title: hosts
Spec. Requirements: Must be edited as administrator.

Apple Mac OS X 10.2 and higher:

Catalog: /etc/ or /private/etc/
Title: hosts
Spec. Requirements: Must be edited as administrator.

Most Linux versions:

Catalog: /etc/
Title: hosts
Spec. Requirements: Must be edited with root privileges

You can find a common list here https://en.wikipedia.org/wiki/Hosts_(file)#Location_in_the_file_system

Was this article helpful?

Related Articles