Skip to content

TechDirectArchive

Hands-on IT, Cloud, Security, Veeam & DevOps

  • Home
  • About
  • Advertise With US
  • Reviews
  • Contact
  • Toggle search form

How to locate and edit the host file on macOS

Posted on 06/04/202015/09/2026 Christian By Christian No Comments on How to locate and edit the host file on macOS
  1. Home
  2. Mac
  3. How to locate and edit the host file on macOS
locate host file

In this article, we shall discuss how to locate and edit the host file on macOS. The hosts file on a Mac is a plain text file that maps hostnames to IP addresses. It’s a crucial part of the operating system’s networking configuration. This file allows you to override DNS settings for specific domains. Please see how to Run or Edit and Delete Tasks via Windows Task Scheduler, and How to Back Up and Restore the Windows Registry.

On macOS, accessing the hosts file is via the terminal. You can use your desired editor. I will be using the iTerm terminal as shown below.

Also, see How to locate and edit the host file on Windows, How to fix Computer Policy could not be updated successfully, and how to “‘Fix the request to add or remove features on the specified server failed“

Locate and edit the host file on macOS

Enter the command below “sudo vim /etc/hosts. Here I am using VIM which is a Text Editor in Unix Systems

edit host file

You will be prompted to enter your password as shown above and when the right credential is entered, the host database will be opened as seen below.

macOS host file
Be careful when editing the hosts file, as incorrect entries can disrupt your network access. Always make a backup before making changes. You can copy the original file to another location

To manipulate this file, use the “I” button on your keyboard in order to modify this field. This will let you enter a new host entry.

When you are done, you can hit the “Esc” button on your keyboard

  • Following by a semicolon “:”
  • For by “w” to save and
  • Followed by “q” to quit as shown below
Screenshot of a terminal window showing the Vim text editor with a configuration file for the host database, including localhost and Docker settings.

Note: Editing the hosts file on a Mac is a powerful way to control domain resolution on your system. Whether you want to block websites, test local development, or override DNS settings, the hosts file offers a straightforward method for managing hostname resolution.

I hope you found this article very useful. Please feel free to leave a comment below.

Thank you for reading this post. Kindly share it with others.

  • Share on X (Opens in new window) X
  • Share on Reddit (Opens in new window) Reddit
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Facebook (Opens in new window) Facebook
  • Share on Pinterest (Opens in new window) Pinterest
  • Share on Tumblr (Opens in new window) Tumblr
  • Share on Telegram (Opens in new window) Telegram
  • Share on WhatsApp (Opens in new window) WhatsApp
  • Share on Mastodon (Opens in new window) Mastodon
  • Share on Bluesky (Opens in new window) Bluesky
Mac Tags:DNS, DNSRecord, Terminal

Post navigation

Previous Post: How to locate and edit the host file on Windows
Next Post: How to move a computer object from one container (OU) to another

Related Posts

  • next cloud desktop
    How to install Nextcloud Desktop client on Mac Mac
  • safari 1
    How to clear cookies history and cache in Safari Mac
  • unabletouninstallonedriveonmac
    Cannot Uninstall the OneDrive App: The item “OneDrive” canot be moved to the Bin because it is open JIRA|Confluence|Apps
  • Ping commands
    Ping from Source IP Address from all environments Mac
  • Root
    Change your root password: Manage the root user on your macOS Mac
  • zoom 2
    How to stop Zoom App from launching automatically at startup on Mac Mac

More Related Articles

mac456789oijh Turn off calls from iPhone: How to unlink FaceTime from Mac Mac
Root Change your root password: Manage the root user on your macOS Mac
Teams How to install Microsoft Teams on a macOS Mac
ztre23fsas Grant or Deny Microphone Access on Mac Mac
veeam agent for mac backup Backup Mac with Veeam Agent for Mac to Synology DS923+ NAS Backup
banner Fix npm install hangs on “sill idealTree buildDeps” Linux

Leave a Reply Cancel reply

You must be logged in to post a comment.

Microsoft MVP

vexpert-badge-stars-5

Virtual Background

VEEAMLEGEND

Categories

Top 30 Sysadmin blog

veeaam100

Veeam Vanguard

  • Auto Update Upgrade issues
    Fix Microsoft Office Showing “Upgrade Required” in AutoUpdate JIRA|Confluence|Apps
  • create a Lenovo USB Recovery key
    Windows 10 Yoga Recovery: Download the files needed to create a Lenovo USB Recovery key Windows
  • Encapsulationset to Auto
    Error – Command rejected: An interface whose trunk encapsulation is “Auto” can not be configured to “trunk” mode Network | Monitoring
  • Vmware workstation player and devicecredential guard not compatible
    Fix VMware Workstation and Credential Guard are not compatible Virtualization
  • fast user switching in windows 10 2
    To enable or disable fast User Switching in Windows Windows
  • WinRM and Kerberos Delegation troubleshooting
    Troubleshooting WinRM and Kerberos Delegation for WAC Windows Server
  • Trellix BitLocker and fileVault Recovery
    Selfservice Recovery: Trellix BitLocker and fileVault Recovery Security | Vulnerability Scans and Assessment
  • hero windowsserver hyperv scaled
    Pass-Through Authentication Authentication and ADFS environment setup on Hyper-V for Hybrid Identity integration Virtualization

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,746 other subscribers
  • RSS - Posts
  • RSS - Comments
  • About
  • Authors
  • Write for us
  • Contact
  • Advertise with us
  • General Terms and Conditions
  • Privacy policy
  • Feedly
  • Telegram
  • Youtube
  • Facebook
  • Instagram
  • LinkedIn
  • Tumblr
  • Pinterest
  • Twitter
  • mastodon
  • Bsky

Tags

Active Directory Azure Bitlocker Microsoft Windows PowerShell WDS Windows 10 Windows 11 Windows Deployment Services Windows Server 2016

Copyright © 2026 TechDirectArchive

Loading Comments...

You must be logged in to post a comment.