This is my personal blog. The views expressed on these pages are mine alone and not those of my employer.

Wednesday, May 21, 2008

Changing Mac OS X Hosts File

This is more for me so I don't forget it, but other folks might find it useful. If you want to add or delete an entry from the Mac OS X /etc/hosts file, its a bit more involved than on Windows. Here's the steps you need to do.

To add an entry:
  • Edit /etc/hosts
  • sudo niload -v -m hosts . < /etc/hosts
  • If on Firefox, go to Tools> Clear Private data and clear things.
  • lookupd -flushcache
To remove the entry:
  • Edit /etc/hosts
  • sudo niload -v -d hosts . < /etc/hosts
  • If on Firefox, go to Tools> Clear Private data and clear things.
  • lookupd -flushcache
Notice the -d for deletion.
// posted by Brad Neuberg @ Wednesday, May 21, 2008
Comments:
Is this really necessary? I find new additions to /etc/hosts are usually available right after editing the file.
# posted by Blogger Ole Begemann : 1:29 PM
There's a way to avoid this.... you just have to set a system property to tell it to go to the hosts file first.

But I forget the property :)

I always google for it when I do an OS X re-install which is like once every year and half.

For example:

sh-3.2# echo "127.0.0.1 fake.server.com">> /etc/hosts
sh-3.2# ping fake.server.com
PING fake.server.com (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.058 ms

worked fine on my machine.

Anyway... maybe that helps save you a step.

It bothers me that OS X isn't really Unix.... it's more like an insane unix than anything else.

I'm thinking about going back to Linux myself :)
# posted by Blogger burtonator : 4:32 PM
This seems like its a bit of overkill...all I do is:

sudo vi /etc/hosts
[enter password]
[make my changes]
:wq

I do this a lot, especially since I do almost all my dev using virtual machines with assigned IP addresses, and to test on the host OS (OS X) I need to ensure that the IP address matches the host name I'm looking for.

I've never had to stop any services to do this.

Maybe that will help?
# posted by Blogger ttrenka : 12:53 PM
@Tom: Hi Tom, I started by doing that but Firefox doesn't always reliably pick up the addition or removal of an address. _Sometimes_ it does but not always. The extra steps ensure that Firefox picks up the changes. Otherwise its looking into an IP cache that might be stale.
# posted by Blogger Brad Neuberg : 11:46 AM
You can also get FF to clear its IP cache by hitting File> Work Offline twice (once to go offline, once to go back online).
# posted by Blogger Mark : 7:12 PM
What version of OS X are you guys using... i tried to use niload and it said command not found (i'm on 10.5.3)
# posted by Blogger SkinnyBoy : 8:45 PM
niload is a thing of the past.. (10.4.x, OS X Tiger)
In Leopard /etc/hosts work just like on any other unix so there is nothing else that needs to be done on newer os X machines.
# posted by Blogger Joachim : 4:10 AM
Post a Comment

Links to this post: See links to this post
<$blogbacklinktitle$>
<$blogbacklinksnippet$>
<$i18npostedbybacklinkauthor$> @ <$blogbacklinkdatetime$>


<< Home

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]

AltStyle によって変換されたページ (->オリジナル) /