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

The hosts file is part of your operating system and works by mapping domain names to IP addresses, it’s can be used resolve domains, block websites or fix connection issues. This guide explains what the hosts file is, why it’s useful and how to edit it on Windows, macOS and Linux.

What is a Hosts File?

The hosts file is a system configuration that works like a local DNS server, it maps domain names to IP addresses. It takes precedence over external DNS servers, you can:

  • Resolve domains quickly during website setup.
  • Manually link hostnames to IPs if DNS cannot resolve them.
  • Block access to specific websites by assigning invalid IPs.
  • Fix unreachable websites by correcting DNS issues.

Changes only apply to the local machine, so others won’t see updates until DNS propagation completes.

How to Edit the Hosts File

Before you start, get the domain name and IP address you need.

For Windows

  1. Open File Explorer and go to C:\Windows\System32\Drivers\etc.
  2. Right click on the hosts file and Open with. Choose Notepad or similar text editor.
  3. Add the IP and domain at the end of the file:
   185.185.185.185 domain.com
  1. Save with Ctrl + S.

Use a hash (#) to disable an entry without deleting it, e.g., # 185.185.185.185 domain.com

For macOS

You can edit the hosts file in a few different ways both achieve the same end result but you may feel more comfortable using Finder of the Terminal.

Using Terminal

  1. Open Spotlight Search (Command + Space) and type Terminal then
  2. Using the terminal enter – sudo nano /etc/hosts
  3. Enter your password if prompted.
  4. Add the IP and domain at the bottom. Save with (Ctrl + X, Y), Enter.

Using Finder

  1. Open Finder and click “Go” then “Go to Folder” from the top menu.
  2. Go to /etc and find the hosts file.
  3. Open it with a text editor, edit and save (CMD+ S).

For Linux

  1. Open Terminal (Ctrl + Alt + T).
  2. Use Nano:
   sudo nano /etc/hosts

  1. Add the IP and domain at the bottom of the file. Save with Ctrl + X, Y, Enter.