Host Files and MAc DNS

hartten

Registered
Hi,

I am a web developer. I just switched from XP to Mac OSX on a 20" - wow.

Ok here is the problem. I often start new ecommerce web sites before the DNS is changed to our servers. So I need a way to "fool" my mac browser into looking for DNS locally for a specific domain name - before it looks at the real DNS server.

In XP I used to just open the hosts file in c: \windows\system32\drivers\etc and add a link like"

192.113.23.112 www.swankmartini.com

I think that IE would look to the hosts file first before it goes to DNS. Works out nice. I can leave the old site up and work in the new server with just my computer.
Any idea on how I can do this with a MAC? I see a /etc/host file, but it does not work the same as on XP...

Thanks for any advice.

Ian Hartten
 
hartten said:
Any idea on how I can do this with a MAC? I see a /etc/host file, but it does not work the same as on XP...
What do you mean by "it does not work the same as on XP"? The /etc/hosts file is the file you want to edit, I believe.

Edit that file and add your entry:

192.113.23.112 www.swankmartini.com swankmartini.com

I add the second domain name so "www" and swankmartini.com would both work. :)

I did this the other day on a Mac mini I'm supporting as an interim solution while a DNS propopgation was taking place.

To confirm the hosts file was setup correctly, open a terminal window and ping the domain or host you defined. You should get replies back from the IP you specified.

What version of OS X are you using?

After updating /etc/hosts, you might have to restart your browser (exit completely and start it again) to make sure it's not using any cached addresses (if it does that).

At least, this is something to try. :)

Peace...
 
Hi there -

If your changes to /etc/hosts aren't being recognized, you can use /Applications/Utilities/Netinfo Manager as described in this article: http://docs.info.apple.com/article.html?artnum=88158 but I usually use the "niload" command (mentioned at the bottom of the article in the above link) since it's much quicker:

(1) create a hosts.txt file in your home directory (same format as /etc/hosts)

(2) open a terminal and issue the following command:
sudo niload hosts . < hosts.txt

(3) Done! Optionally you can use "nidump hosts ." to see what's in the hosts database. "man niload" and "man nidump" for more.

Hope that helps!
 
macbri said:
Hi there -

If your changes to /etc/hosts aren't being recognized, you can use /Applications/Utilities/Netinfo Manager as described in this article: http://docs.info.apple.com/article.html?artnum=88158 but I usually use the "niload" command (mentioned at the bottom of the article in the above link) since it's much quicker:
Thanks for that link. On that page, they reference /private/etc/hosts yet we've been discussing /etc/hosts above.

When giving paths like "/etc/hosts", is the "/private" assumed or is "/etc" actually located in a place other than "/private/etc"?

He might have been editing the wrong file.

Thanks!

Peace...
 
tomdkat said:
When giving paths like "/etc/hosts", is the "/private" assumed or is "/etc" actually located in a place other than "/private/etc"?

He might have been editing the wrong file.

Thanks!

Yeah, /etc is just a symlink to /private/etc so in theory "/etc/hosts" should be one and the same file. Same with /tmp and /var. Maybe it's done like that so they don't show up in the Finder, but who outside Apple really knows? ;)
 
macbri said:
Yeah, /etc is just a symlink to /private/etc so in theory "/etc/hosts" should be one and the same file. Same with /tmp and /var. Maybe it's done like that so they don't show up in the Finder, but who outside Apple really knows? ;)
Gotcha. Man, I'm learning a lot on this forum. :)

Thanks!

Peace...
 
I'm trying this to load some items into the hosts file. The "sudo niload hosts . < hosts.txt" command prompts me for the root password, I give it, and it sits there for a while before returning me to the prompt.

when I cat hosts it looks like nothing's changed. But when I "nidump hosts ." I get the list. Is this normal? Where is the list stored?
 
Back
Top