October 11, 2019
October 11, 2019
As we all know, the DNS (Domain Name System) is the phone book of the internet. However, did you know that the hosts file on your computer can also be used as a directory for domain names? This article will explain what the hosts file is and how to edit it in Windows 10, Linux, and Mac to emulate DNS change.
In short, a hosts file is a local file that contains domain names and their matching IP addresses. It’s found in all common operating systems and acts as a map, identifying and locating hosts on IP networks.
Every time you visit a website, your computer will check the hosts file first to see which IP address it connects to. If the information is not there, your internet service provider will look into the DNS for the resources to load the site.
You can take advantage of the situation above when you’ve just purchased a domain. Or, when you’re migrating your website to a different hosting provider and your domain needs to point to the new server. Usually, it’ll take 24 to 48 hours for your domain to start working, and during that time, you won’t be able to access your site.
By editing the hosts file, specifically adding a custom IP address that points to your domain, you’ll be able to open your website. This is useful if you want to modify your site after migrating and see how it’ll look on the new server
The hosts file is written in plain-text format. Hence, you can use any text editor like Notepad, for example, to edit it.
However, do keep in mind that the changes will only affect the system that the hosts file is in.
Before we begin, you’ll need an IP address for your domain:
Now let’s edit the hosts file. There are two methods for Windows 10 – manually or using the Hosts File Editor tool. Generally, you can use the guides below in any version of Windows.
There’s an easier way to edit the hosts file in Windows 10, and that’s by using the Hosts File Editor.
In Linux, you can use your favorite text editor to do the job. Here, we will use Gedit in Ubuntu. Open the Terminal by pressing Ctrl+Alt+T.
sudo gedit /etc/hosts
If you’re running macOS from Leopard (10.6) to its latest version, follow these steps to edit the hosts file:
sudo nano /private/etc/hosts
In some cases, it can take some time for the changes to apply. You might want to flush the DNS for the changes to take effect.
To do that, open the Terminal, type in the command:
sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder
Press Enter, and don’t forget your password.
You’ve just learned how to edit the hosts file on three different operating systems.
However, do keep in mind that these changes require administrative rights on every system, and it will only take effect on the computer that the hosts file is in.
Here’s a quick recap:
December 10 2020
Editing hosts file is no problem, but I don't quite understand how making up IP by myself - straight from my head - will lead my browser to find unpublished site on Hostinger servers. What am I missing?
Replied on February 09 2021
Hi, Andrius! The IP used in hosts should be that of your hosting plan - that's where your content is. Then when this IP is added to your hosts file, you'll see the website locally (what's uploaded to the server by the IP you indicated). Then to make it visible to the world, you should point your domain name to this IP. You'll find how to do that here :)