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
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 :)
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?
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.
gcostanzo@euclid:~$ uname -a
Darwin euclid.local 10.4.0 Darwin Kernel Version 10.4.0: Fri Apr 23 18:28:53 PDT 2010; root:xnu-1504.7.4~1/RELEASE_I386 i386
gcostanzo@euclid:~$ cat /etc/host
tv 192.168.1.115
joshua 192.168.1.113
gcostanzo@euclid:~$ sudo dscacheutil -flushcache
gcostanzo@euclid:~$ ping tv
PING tv (192.168.1.100): 56 data bytes