By editing the hosts file, you can locally associate a domain with a different IP address. This allows you to, for example, test the functionality of a website without actually using the registered domain. The local hosts file overrides the addresses provided by DNS services. More information can be found here: https://en.wikipedia.org/wiki/Hosts_(file)
The hosts file can be found in different locations depending on the operating system:
Windows
C:\Windows\System32\drivers\etc\
You can edit the file by double-clicking on it and selecting a text editor from the list (e.g., Notepad).
Mac
/private/etc/hosts
You can edit the file by opening Finder, selecting Go --> Go to Folder, and entering the above file path. Open the file by double-clicking on its icon.
Linux
You can edit the file by entering the following command in the terminal:
sudo vim /etc/hosts
Adding an entry to the hosts file and testing the address
At the end of the hosts file (after lines starting with #), add the desired entry in the following format
IP-address domain
For example:
185.55.85.4 exampledomain.fi
The IP address and the domain should be separated by at least one space or a tab.
After adding the line, save the file.
NOTE: You need to be logged in to the operating system with administrator privileges to save the changes you made.
You can now open the added domain in your browser, and the site should load from the redirected server.
NOTE: Remember to remove the added line from the hosts file when you no longer need the local redirection.
To remove the redirection, simply delete the line or comment it out by placing a # character in front of it.
Clearing DNS cache
If the website doesn't load as expected, you can try clearing the DNS cache of your system. Here's how to do it:
Windows
Press the Windows key (or open the Start menu) and type "cmd" to search for Command Prompt.
Right-click on the Command Prompt icon and select "Run as administrator." If prompted, select "Yes" to allow changes to the device.
Enter the following command:
ipconfig /flushdns
The DNS cache is now cleared. A successful flush will result in the following message:
Windows IP Configuration
Successfully flushed the DNS Resolver Cache.
You can now try opening the address again in your browser.
Mac OS X 10.11 and later
Open the Terminal application (e.g., press cmd + space and search for "terminal").
Enter the following command:
sudo killall -HUP mDNSResponder
NOTE: The system may prompt you to enter your macOS password to execute the command.
The DNS cache is now cleared. You can try opening the address again in your browser.
Linux (systems using systemd)
Open the terminal.
Enter the following command:
sudo systemd-resolve --flush-caches
The DNS cache is now cleared. You can try opening the address again in your browser.