If you moved your website to a new server and you want to test it before it completes propagation of DNS records or just develop a site that is not yet publicly available, you can do so by modifying the local host file.
Entering IP address of a new server in the host file on your computer, you can force the browser to access the desired location. This is possible because the record in the local host file has priority over DNS records.
We will describe how to modify the host file on Windows, Linux and OSX operating systems.
Windows
- Run Notepad as an administrator (right click on the icon and select “Run as administrator”). This is necessary to be able later to save the changes.
- Open the host file with File > Open … Select “All files” in the field for the extension. Host file is located at:
C:\WINDOWS\system32\drivers\etc\hosts
- At the end of the file, type the IP address of the server and web address of a site. For example:
10.11.126.18 mojdomen.com
- Save the changes File > Save
- It is necessary to delete the local cache from the computer. Start a command prompt, Start> Run> CMD and enter the following command:
ipconfig /flushdns
- Restart your browser and, if necessary, delete the cache of the browser.
When finished testing site, you can restore the host file to the old state.
Linux / OSX
Change the file
etc/hosts as root.
In OSX you can find the Terminal.app in Applications > Utilities > Terminal.
Type the IP address of the server and web address of a site. For example:
10.11.126.18 mojdomen.com
Restart the nscd daemon by entering the following in a terminal window:
1 |
/etc/rc.d/init.d/nscd restart |
On OSX enter the following command
OSX prior to 10.5:
lookupd -flushcache
OSX 10.5 or later:
dscacheutil -flushcache