Skip to main content
TrustServers Knowledge Base

Tip: Start typing to get instant search results.

Table of Contents

Hosts file modifications for testing your website

During the development or migration of a website, it is often useful to be able to test it on a new server before making changes to the actual DNS servers. This is possible with a simple modification to your local hosts file.

What is the hosts file?

The hosts file functions as a local “DNS server”. When your computer tries to translate a domain name (such as mydomain.gr) into an IP address, it first checks the hosts file locally on your computer. If it finds a match there, it uses that and does not query external DNS servers.

Example usage:

Let’s assume your website mydomain.gr is hosted on the old server, but you want to test it on a new server with IP address 12.34.56.78, without changing anything for other visitors.

Simply add the following two lines to the hosts file on your computer:

12.34.56.78 www.mydomain.gr
12.34.56.78 mydomain.gr

This way, only you will see the page from the new server, while other users will continue to see the old one.

Instructions for different operating systems:

Below you will find information on how you can make the change on different operating systems.

Windows 11, 10 & Windows 8:
  1. Press the Windows key on your keyboard.
  2. Type Notepad in the search.
  3. In the search results, right-click and run as administrator.
  4. From Notepad, open the file C:\Windows\System32\Drivers\etc\hosts
  5. Make your changes to the file.
  6. Finally, save the file.
Windows 7 & Windows Vista:
  1. Click Start > All Programs > Accessories.
  2. Right-click and open as administrator.
  3. Windows will need your permission to open Notepad, click Continue
  4. In Notepad, click File > Open.
  5. In the File name field, paste C:\Windows\System32\Drivers\etc\hosts
  6. And click Open.
  7. Make your changes to the file.
  8. Finally, save the file.
Linux:
  1. Open a new Terminal
  2. Type the command sudo nano /etc/hosts
  3. Type your user password
  4. Make your changes to the file.
  5. Press Control – X
  6. Finally, press Y to save the file
MacOS X (10.6+):
  1. Go to the Applications > Utilities folder and open Terminal
  2. Type the command sudo nano /private/etc/hosts.
  3. Type your user password.
  4. Make your changes to the file.
  5. Press Control – X
  6. Press Y to save the file.
  7. Finally, type the command dscacheutil -flushcache.

After your tests or when the DNS is officially updated to have this new IP, you must edit again to remove these lines you temporarily added.

Was this article helpful?
Please Share Your Feedback
Πώς μπορεί να βελτιωθεί το άρθρο;
Tags:
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.