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

January 29, 2025 / Tutorial

In this guide, you will discover how to easily edit the host file across Windows, macOS, and Linux, unlocking the power to manage your system’s domain and IP address mappings!

Your computer’s host file is a system configuration file that maps domain names to IP addresses. If you encounter issues accessing certain websites or want to block a site, editing the host file can be a helpful solution. Beforehand we dive into the steps, let’s first understand what a host file is and why you may need to edit it.

What is a Hosts File?

A hosts file is a local file on your computer that links domain names (like sample.com) with their respective IP addresses. It works like a DNS (Domain Name System) server but is prioritized by your operating system.
When your computer wants to access a website, it checks the hosts file first. If the IP address is not found there, it inquiries the DNS server to resolve the address. By modifying this file, you can:

  • Block websites: Redirect certain domains to local addresses to block access.
  • Resolve domains: Swiftly make a site available without waiting for DNS propagation.
  • Fix website access issues: If DNS is down, manually setting the correct IP can restore access.
How to Edit the Hosts File in Windows

Follow these steps to edit the hosts file in Windows 10/11:

  1. Open File Explorer: You can do this by clicking the File Explorer icon on the taskbar or pressing Windows + E.
  2. Navigate to the Hosts File: Go to C:\Windows\System32\Drivers\etc\.
  3. Open the File: Right-click the hosts file and select Open with. Select Notepad (or any text editor).
  4. Edit the Hosts File: At the bottom of the file, add a new line with the IP address and domain. For example:
    185.185.185.185 domain.com
  5. Save Your Changes: Press Ctrl + S to save the file.
    Tip: To disable an entry, add a # before the line (e.g., # 185.185.185.185 domain.com). This lets you quickly reactivate it later.
How to Edit the Hosts File in macOS
  1. Method 1: Using Terminal (Command Line):
    1. Open Terminal: Press Command + Space, type Terminal, and press Enter.
    2. Edit the Hosts File: Type the following command:
      sudo nano /etc/hosts
    3. Enter Password: You will be prompted for your password to grant administrative privileges.
    4. Add Your Domain and IP: Scroll down to the bottom of the file and add the following line:
      185.185.185.185 domain.com
    5. Save the File: Press Ctrl + X, then press Y to confirm and enter to save.
  2.  Method 2: Using Finder (Graphical Interface):
    1. Open Finder: Click the Finder icon in your dock.
    2. Go to Folder: In the top menu, click Go > Go to Folder, and type /etc.
    3. Open the Hosts File: Find and right-click hosts, then select a text editor to open it.
    4. Edit and Save: Add the domain and IP at the bottom, then save the file by pressing Command + S.
How to Edit the Hosts File in Linux
  1. Open Terminal: Press Ctrl + Alt + T or find Terminal in your application launcher.
  2. Edit the Hosts File: Run the command:
    sudo nano /etc/hosts
  3. Enter Your Password: If prompted, enter your administrator password.
  4. Add Domain and IP: Add the following at the end of the file:
    185.185.185.185 domain.com
  5. Save and Exit: Press Ctrl + X, then Y to confirm, and Enter to save.

Conclusion:

Editing the hosts file on your system can be useful for various tasks like blocking websites, resolving domains, or troubleshooting network issues. The process is fairly simple in Windows, macOS, and Linux.

• In Windows, navigate to C:\Windows\System32\Drivers\etc and edit the hosts file using Notepad.
• In macOS, use Terminal and the sudo nano /etc/hosts command to modify the file.
• In Linux, edit the file using the same method as macOS through the Terminal.

You can edit the hosts file and make changes to your system’s network configuration when needed.

Wasn’t that easy? Explore our latest web hosting plans today and start enjoying the benefits!

Learn How to Remove Multiple Files Using the Command Line, streamlining file deletion tasks with speed and accuracy for better file management.

Leave a Reply

Your email address will not be published. Required fields are marked *