Host files predate the Domain Name System and can still be found in popular operating systems such as Windows and macOS. They are an effective way to address the same issues as a DNS. But how can you edit a hosts file and locate it?
For answers to these questions, keep reading. In this blog, you will find a comprehensive guide on how to edit a hosts file. You will learn what a hosts file is, what it does, and whether you should edit it or not.
The hosts file works similarly to a DNS. It is a directory that stores the IP addresses of various websites. When you visit a website, your computer will first check the IP address in the hosts file and match it with the relevant hostname.
But if the IP address is not found in the hosts file, the computer will then turn to the DNS to look up the website's IP address based on its hostname. The hosts file is present in most operating systems.
Editing a hosts file is generally considered safe, as it's a simple text file that can be opened and modified using any basic text editor.
The most common reason for editing a hosts file is to change a website's domain name. When moving your website from one hosting provider to another, your site may be temporarily unavailable while the domain name propagates, which can take up to 48 hours.
However, by modifying the hosts file on your computer, you can access your website immediately using the new domain name
You can edit the hosts file using the two methods below.
You can use any text editor but we are using Notepad which is the default text editor on Windows.
- Search for Notepad in the Search menu and open it by pressing Run as administrator. This option will be visible if you right-click on the icon.
- Click on File and then Open.
- Use the C:\Windows\System32\Drivers\etc to locate the hosts file. Once you find it, tap on it to open it.
- Make the changes as per your needs.
- Hit Save or press Ctrl+S. Do not save it as a text file otherwise, the changes won’t be applied.
Another effective way to make the changes on the hosts file is through the online hosts editor. You will need to download it for it set up. Once it has been installed on your system, you can launch it to make the changes as needed. Add as many IP addresses and domains as you like through the editor.
Here are the steps to edit a hosts file if you have the latest version of the operating system. In this case, it is the Leopard.
- Open the Terminal.
- Locate and open Nanoeditor by running it as administrator. You can do so by entering sudo nano /private/etc/hosts.
- Type in your password.
- Make the changes and hit save.
To edit a hosts file on Linux, you will need an editor. You can choose anyone you like. A couple of them are the gedit editor or the Vim editor. Here, we are using the gedit editor.
- Open the Terminal.
- Type the command, sudo su.
- This will ask you for your admin password. Type that in.
- Type, sudo gedit /etc/hosts.
- This will open up the host file and you can make the desired changes. Hit save once you are done.
All things considered, you can access and modify the hosts file on any platform using the methods outlined in the blog. Hopefully, these methods will grant you access to your hosts file within minutes. While there are several ways to do it on Windows, there are only a few methods for other operating systems. Nevertheless, they are all effective and can assist you in completing your task quickly.
No, the changes are made automatically once you hit the save button. There is no need to restart the system.
No, there is no such risk in editing a host file without a hosting provider. However, we do suggest not using it to override websites that may invade your personal information.