Help Center

How to Modify the Hosts File in Windows, Linux, and macOS

Introduction

This tutorial will guide you through the steps to modify the hosts file in Windows, Linux, and macOS to direct a domain to a specific IP address. This is a useful technique for web development testing, blocking websites, or redirecting network traffic.

What is the Hosts File?

The hosts file is a plain text file used by operating systems to map domain names to IP addresses.

Modifying the Hosts File in Windows

  1. Open Notepad as Administrator:

    • Right-click on the Notepad icon and select "Run as administrator."
  2. Open the Hosts File:

    • In Notepad, go to File -> Open.
    • Navigate to C:\Windows\System32\drivers\etc.
    • Select "All Files" as the file type and open the hosts file.
  3. Modify and Save:

    • Add the line desired_IP domain_name.com.
    • Save the changes.

Modifying the Hosts File in Linux

  1. Open a Terminal:

    • Use the shortcut Ctrl+Alt+T or search for "Terminal" in your applications.
  2. Edit with Privileges:

    • Type sudo nano /etc/hosts and press Enter (it may ask for your password).
  3. Modify and Save:

    • Add the line desired_IP domain_name.com.
    • Save with Ctrl+O and exit with Ctrl+X.

Modifying the Hosts File in macOS

  1. Open Terminal:

    • Go to Applications -> Utilities -> Terminal.
  2. Edit the File:

    • Type sudo nano /etc/hosts and press Enter (enter your password if prompted).
  3. Modify and Save:

    • Add the line desired_IP domain_name.com.
    • Save with Ctrl+O and exit with Ctrl+X.

Final Considerations

  • After modifying the hosts file, you may need to restart your browser or clear the DNS cache for the changes to take effect.
  • Be careful when modifying the hosts file, as mistakes can prevent access to certain websites.

Last updated: 11 de diciembre de 2023

Estimated reading time: 3 minutes

Did this article help you?
Let's Do It!

Start TODAY for only $2.45/month

Includes a web builder, 30GB of cloud storage, +200 Apps, and professional email.

Sign Up Now