What is Windows "hosts" file alternative for OSX?

Solution 1:

OSX does have a /etc/hosts file but it first uses directory services to find hosts. These are maintained via the dscl command

This web page provides examples of use to maintain the lookups.

Essentially, you just need to run the following command in Terminal:

sudo dscl localhost -create /Local/Default/Hosts/sitename.com IPAddress 127.0.0.1

Solution 2:

There's a hosts file in /etc/, a path you can access in Finder using the Go » Go to Folder menu item.

Right-click it and Get Info to change its permissions at the bottom, so you can edit it. You might also need to temporarily give yourself permissions for the parent folder /etc so saving works. It's a bit tricky with some GUI editors.


Alternatively, sudo vim /etc/hosts in Terminal, if you're comfortable with vim (or any other CLI editor).

enter image description here

The file itself works like you'd expect it to.