Steps to Edit Hosts File in Windows 10

Nov 04, 2021

Elvinas S.

3min Read

How to Edit Hosts File: A Beginner's Guide

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.

What is Hosts File?

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.

Why Modify the Hosts File?

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.

Edit the Hosts File in Windows 10

Before we begin, you'll need an IP address for your domain:

  1. Login to your hPanel, then on the left sidebar look for hosting plan, server, and IP address details.
  2. Copy the server IP address:
Hostinger hPanel dashboard with server IP address highlighted

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.

Change the File Manually

  1. Press Start and find Notepad. Right-click to Run as administrator.run Notepad as administrator on Windows 10
  2. Once in Notepad, go to File -> Open. Get to C:\Windows\System32\Drivers\etc and make sure to select All Files to find the hosts file.find and open hosts file in Windows' system
  3. Now you can edit the hosts file. Add the custom IP address you've made earlier, followed by a space, then your domain name.This picture shows how to edit hosts file in Windows 10
  4. When you're finished, don't forget to save your changes.

Using Hosts File Editor Tool

There's an easier way to edit the hosts file in Windows 10, and that's by using the Hosts File Editor.

  1. Once you're in the Hosts File Editor, fill your targeted IP address and the domain name under their columns.adding domains on the Hosts File Editor
  2. Save your 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 command below, then key in your admin password:
    sudo su
    enabling administrative rights on Ubuntu Terminal
  2. To open the hosts file using Gedit, type the following command and press Enter:
    sudo gedit /etc/hosts
    opening the hosts file through Ubuntu Gedit
  3. Add the targeted IP address followed by a space, then the domain name at the bottom of the hosts file, just like on the Windows 10 tutorial.
  4. Save your changes.

Edit the Hosts File in MacOS

If you're running macOS from Leopard (10.6) to its latest version, follow these steps to edit the hosts file:

  1. Click on the Launchpad and open Terminal.
  2. We'll be using the Nano Editor. To run it as an administrator, insert the statement below, and press Enter:
    sudo nano /private/etc/hosts
    enabling administrative rights on macOS
  3. Type in your password. You'll be directed to the hosts file.
  4. Add your chosen IP address, followed by the domain name, separated by a space.
  5. Make sure to save your changes using the Ctrl + O shortcut.

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

Followed by:

sudo killall -HUP mDNSResponder

Press Enter, and don't forget your password.

Conclusion

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:

  • Windows 10 ‒ use any text editor, like Notepad, to modify the file or use the Hosts File Editor.
  • Linux ‒ use either Gedit or any other text editor you prefer.
  • Mac ‒ resort to the Nano Editor via the Terminal.

Good luck!

Author

Elvinas is a senior server administrator at Hostinger. He monitors the infrastructure's well-being and keeps the uptime at a maximum. Besides server management, web development has always been one of his biggest passions.

Steps to Edit Hosts File in Windows 10

Source: https://www.hostinger.com/tutorials/how-to-emulate-edit-windows-hosts-file

0 Response to "Steps to Edit Hosts File in Windows 10"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel