Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

How can I do that on Mac?

share|improve this question
up vote 3 down vote accepted

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/ IPAddress
share|improve this answer
Added the most important information from the web page to your answer so it will still work even if that web site goes down or changed. Hope you don't mind. – Daniel Beck Feb 13 '11 at 19:27
Actually, directory services reads both /var/db/dslocal/nodes/Default/computers/* (which DS calls /Local/Default/Hosts, and is where these instructions put host entries) and /etc/hosts (which DS calls /BSD/local/Hosts), so doing this is equivalent to making an entry in /etc/hosts. (Although it checks dslocal before /etc/hosts, so if there's a conflict, that'll take precedence.) – Gordon Davisson Feb 14 '11 at 2:46

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 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.

share|improve this answer
Ugh. Those colors. Sorry about that. – Daniel Beck Feb 13 '11 at 18:44
You're fired :-) – user3463 Feb 13 '11 at 19:11
You might also need to give yourself permissions for the parent folder /etc so saving works. No, just no. That's the worst advice you can ever give to anyone. – Lie Ryan Dec 13 '14 at 11:41
@LieRyan I'd have expected it's obvious that any permissions users give themselves here should be taken away after everything works. Isn't it? – Daniel Beck Dec 13 '14 at 11:54

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.