macOS – Editing the Hosts File

KB ID 0001268 

Another guest post from Daniel Newton

Problem

I’ve had windows for years; I knew the OS inside out. Recently, I switched to Mac. But I wondered how to edit the hosts file for my VPN connections and my servers. After some research, I found out how to do it and thought I will document it on PeteNetLive! 🙂

Solution

Open a terminal session and type in the following command;

Sudo nano /etc/hosts

Sudo Nano

Note: I’m using nano for this but you can use vi to edit the document (sudo vi /etc/hosts).

You’ll be prompted to enter your password.

Nano Hosts

Then you will get this screen;

003-edit-hosts-mac-osx

Type in an entry for example (Note: This is not my IP or my company’s IP!);

004-host-file-mac

To Save, Press Control and O and Enter.

005-osx-add-host-to-hosts-file

To Exit, press Control and X.

 

Related Articles, References, Credits, or External Links

NA

Author: PeteLong

Share This Post On

2 Comments

  1. Great little article, it may be worth putting this command at the end to flush the DNS:

    dscacheutil -flushcache;sudo killall -HUP mDNSResponder

    Post a Reply
    • Hi Adam,

      Thanks for the feedback

      P

      Post a Reply

Leave a Reply to PeteLong Cancel reply

Your email address will not be published. Required fields are marked *