
sudo nano /etc/hostsĪfter typing in this command, you will be required to enter the password for your account ( 2.). We use the nano text editor as it is one of the most straightforward terminal text editors to use. You can begin editing the hosts file by using the following command within the terminal ( 1.). With the terminal open on macOS, we can now edit the hosts file. With Spotlight open, you will need to type in “ terminal” and then press the ENTER key.Ģ. Press COMMAND + SPACEBAR to open Spotlight. The easiest way to open the terminal is by using Spotlight. First, you will want to open the terminal on your macOS device.

This file can only be edited by an administrator.ġ. You can find the hosts file on Mac within the “ /etc/” directory at “ /etc/hosts“. With an understanding of how entries in the hosts file are formatted, we can move on to editing the file on Mac. You can specify multiple hostnames for the one IP address, separate each with a single space and keep them on the same line. All values specified after the IP Address are the hostnames ( HOSTNAME) that you want to be pointed to the specified IP.The first value must always be the IP address ( IPADDRESS) you want the following hostname’s directed.You must specify two values when defining a new host within the hosts file.

Every new hostname you want to be overridden needs to be on a separate line. Format of the Hosts File on macOSīefore editing the hosts file on Mac, you should understand how each line is formatted.īelow, you can see how each line within this file should be formatted. Please note you will need to be an administrator on your Mac device to be able to edit this file. Over the following sections, you will learn where to find the hosts file on your Mac and how to edit it using the terminal. Using this file is helpful in many cases, such as giving a local web server a hostname. If a domain name is present within the hosts file, Mac will use the IP defined within that file.

This file maps a hostname to an IP address without the system having to perform a DNS lookup. The hosts file is used by macOS when it performs a DNS lookup on your device. This tutorial will show you how to edit the hosts file on macOS.
