Edit Your Hosts File
Sometimes you don't have DNS entries pointing to your server, such as when you're moving a live site, or setting up something very new, but you need to test that things will work. In these cases you can add entries to your hosts
file, which is checked before looking for normal DNS entries.
You will need
- The domains you want to test, for example
www.example.com
andexample.com
- The IP address of your server (), or in the case of an IPv6-only configuration, the IP address of the proxy.
- Admin access to your computer/laptop running Windows, MacOS or Linux.
Eidting the Hosts File
Windows
Open Notepad as an Administrator, and open the file C:\Windows\System32\Drivers\etc\hosts
.
Add a new line for each hostname you want to override, with the IP Address, followed by spaces or tabs, then the hostname, for example:
198.51.100.62 www.example.com 198.51.100.62 example.com
Comments can be added by preceding them with a hash (#
).
Save the changes with File > Save.
MacOS & Linux
Use the command sudo nano /private/etc/hosts
to open the file.
Add a new line for each hostname you want to override, with the IP Address, followed by spaces or tabs, then the hostname, for example:
198.51.100.62 www.example.com 198.51.100.62 example.com
Comments can be added by preceding them with a hash (#
).
Save the changes by Pressing Ctrl-x and when prompted, confirm with y.
Reverting Changes
Remember that this will continue to override any changes to DNS, so you should revert these changes as soon as possible otherwise your view of the internet will be incorrect.
To do so, simply edit the file again, and remove (or comment out) the relevant lines.