
In 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.
Enter the command below “sudo vim /etc/hosts
– Here I am using VIM which is a Text Editor in Unix Systems

How to locate and edit the host file on macOS
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.

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

That is all you need to know on How to locate and edit the host file on macOS.