Support 24/7
Shared hostingManaged WordPressReseller hostingOpenClaw hostingVPS hostingDedicated serversManaged serversAbout usHow we compareRegionsKnowledge baseSupportDomainsSSLBlogClient area
General
Knowledge base / General

How to change .hosts file on Windows and MacOS systems

Point a domain at a server on your machine only — the hosts file on Windows and macOS, so you can test a site before switching DNS.

Last updated: September 16, 2026

How to Edit the Hosts File on Windows and macOS

The hosts file is a crucial system file that maps domain names to IP addresses. Editing this file allows you to control the mapping of hostnames, making it a useful tool for various purposes. In this guide, we’ll walk you through the process of editing the hosts file on both Windows and macOS.

  1. 1Open the hosts file with administrator rightsNotepad as administrator on Windows, sudo nano in Terminal on macOS.
  2. 2Add the mappingOne line per entry, in the form IP_address domain_name.
  3. 3Save and closeChanges take effect immediately.
  4. 4Flush the DNS cache if the browser disagreesOn macOS, sudo killall -HUP mDNSResponder.
The same four moves on both systems — only the file path and the editor change.

Editing the Hosts File on Windows

The hosts file on Windows is located at C:\Windows\System32\drivers\etc\hosts.

Follow these steps to edit the file:

  1. Open Notepad or any text editor with administrator privileges.
  2. Go to File > Open, and navigate to the hosts file location.
  3. Add or modify entries in the following format: IP_address domain_name.
  4. Save the file and close the text editor.

Editing the Hosts File on macOS

The hosts file on macOS is located at /private/etc/hosts.

Follow these steps to edit the file:

  1. Open Terminal.
  2. Type sudo nano /private/etc/hosts and press Enter.
  3. Enter your administrator password when prompted.
  4. Add or modify entries in the following format: IP_address domain_name.
  5. Press Ctrl + X to exit, press Y to confirm changes, and press Enter.

After editing the hosts file, changes take effect immediately. This allows you to locally override DNS settings and control access to specific websites. Remember to save a backup of the original hosts file before making changes for safety.

If your changes aren’t reflecting in your browser after editing the hosts file, flushing your DNS cache can resolve the issue. This process removes saved IP records and allows your browser to reflect the updated IP address from the edited hosts file.

To update your browser’s DNS records, enter the following command into the Terminal application:

sudo killall -HUP mDNSResponder

This step ensures that your changes go live within your browser. You have now successfully edited your Mac hosts file!

Whether you’re configuring a local development environment or blocking access to certain sites, understanding how to edit the hosts file empowers you with more control over network resolutions.