OSX Hosts File – Windows Hosts File Alternative for OSX

hosts-filemacos

I just got a Mac computer (OSx v10.6) to test my web site design. Web site is running on the local network, and in windows computers I use "hosts" file to map its network IP address to domain name, like

192.168.1.7 www.sitename.com

How can I do that on Mac?

Best Answer

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
Related Question