As we all know, DNS (Domain Name System) is the rubric 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 modify it in Windows 10, Linux and Mac to emulate DNS change.

Let’s get started.

Table of Contents hide
What is the hosts file?
Why edit the hosts file?
Edit the hosts file Windows 10
Edit the windows hosts file manually
Using the hosts file editor tool
Editing the hosts file in Linux
Editing the hosts file Mac
Conclusion
What is the hosts file?
In short, a hosts file is a local file that contains domain names and their corresponding IP addresses. It is found in all common operating systems and acts as a map, identifying and locating hosts on IP networks.

Whenever you visit a website, your computer will first check the hosts file to see what IP address it connects to. If the information is not there, your Internet service provider will look in the DNS for resources to load the site.

Why change the hosts file?
You can take advantage of the above situation when you have just purchased a domain. Or, when you migrate your Web site to a different hosting provider and your domain needs to point to the new server. It usually takes 24 to 48 hours for your domain to start working, and during this time you will not be able to access your site.

By modifying the hosts file , specifically by adding a custom IP address pointing to your domain, you will be able to open your Web site. This is useful if you want to edit your site after migration and see how it will look on the new server

The hosts file is written in plain text format. Therefore, you can use any text editor such as Notepad, for example, to edit it.

However, keep in mind that the changes will only affect the system where the hosts file is located.

Editing the hosts file Windows 10
Before you begin, you will need an IP address for your domain:

1.Log into your cPanel, then look up the details of your hosting plan, server, and IP address.
2.Copy the IP address of the server:

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.

Edit the windows hosts file manually
Press Start and find Notepad . Right-click Run as administrator .

Once in Notepad, go to File -> Open . Go to C:\Windows\System32\Drivers\etc and be sure to select All Files to find the hosts file .

Now you can edit the hosts file . Add the custom IP address you created earlier, followed by a space, then your domain name.

When finished, do not forget to save your changes.

Using the hosts file editor tool
There is an easier way to edit the hosts file in Windows 10, and that is by using the hosts file editor .

1.Once you are in the hosts file editor , enter your target IP address and domain name under their columns.
2.Save the changes.

Edit the Hosts file in Linux
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 .

1.Type the following command, then type the administrator password: sudo su
2.To open the hosts file using Gedit , type the following command and press Enter: sudo gedit/etc/hosts
3.Add the destination IP address followed by a space, then the domain name at the bottom of the hosts file , just like in the Windows 10 tutorial.
4.Save the changes.

Edit the Mac hosts file
If you are using macOS from Leopard (10.6) to its most recent version, follow these steps for editing the Mac hosts file :

1.Click on Launchpad and open Terminal .
2.We will use the Nano Editor . To run it as an administrator, enter the following instruction and press Enter : sudo nano /private/etc/hosts
Type in your password. You will be directed to the hosts file .
3.Add your chosen IP address, followed by the domain name, separated by a space.
4.Be sure to save your changes using the shortcut Ctrl + O.

Conclusion
You have just learned how to edit the hosts file on three different operating systems.

However, keep in mind that these changes require administrative rights on each system and will only take effect on the computer where the hosts file is located.

Here is a brief summary:

  • Windows 10 use any text editor, such as Notepad, to edit the file or use the Hosts file editor .
  • Linux – use Gedit or any other text editor you prefer.
  • Mac use Nano Editor via Terminal.