Tip: Start typing to get instant search results.
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:
- Press the Windows key on your keyboard.
- Type Notepad in the search.
- In the search results, right-click and run as administrator.
- From Notepad, open the file
C:\Windows\System32\Drivers\etc\hosts - Make your changes to the file.
- Finally, save the file.
Windows 7 & Windows Vista:
- Click Start > All Programs > Accessories.
- Right-click and open as administrator.
- Windows will need your permission to open Notepad, click Continue
- In Notepad, click File > Open.
- In the File name field, paste
C:\Windows\System32\Drivers\etc\hosts - And click Open.
- Make your changes to the file.
- Finally, save the file.
Linux:
- Open a new Terminal
- Type the command
sudo nano /etc/hosts - Type your user password
- Make your changes to the file.
- Press Control – X
- Finally, press Y to save the file
MacOS X (10.6+):
- Go to the Applications > Utilities folder and open Terminal
- Type the command
sudo nano /private/etc/hosts. - Type your user password.
- Make your changes to the file.
- Press Control – X
- Press Y to save the file.
- 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.