How to edit hosts file on mac?

Run terminal and open file with nano;

sudo nano /private/etc/hosts

To edit the file, you’ll add your own lines like:

When you’re done making changes, press Control-X to exit the editor, and Y to save.

Finally you may need to flush your DNS cache:

dscacheutil -flushcache