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:
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
- Edit /etc/hosts
- sudo niload -v -d hosts . < /etc/hosts
- If on Firefox, go to Tools > Clear Private data and clear things.
- lookupd -flushcache
Comments:
Links to this post:
<< Home
Is this really necessary? I find new additions to /etc/hosts are usually available right after editing the file.
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 :)
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 :)
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?
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?
@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.
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).
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)
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.
Post a Comment
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.
Links to this post:
<< Home
Subscribe to Posts [Atom]