Quantcast
Channel: Bit Melt Blog
Viewing all articles
Browse latest Browse all 25

/etc/hosts and Mac OS X 10.5 Leopard

$
0
0
Instead of using /etc/hosts on Mac OS Leopard, the proper way to add hosts is using the dscl utility. First, let's list the hosts already there:
$ dscl localhost -list /Local/Default/Hosts
$
Nothing. Let's add one. I want to be able to access localhost as me.blogger.com. Right now that doesn't work:
$ ping -q -c 1 me.blogger.com
ping: cannot resolve me.blogger.com: Unknown host
$
Create an entry for it and try again:
$ sudo dscl localhost -create /Local/Default/Hosts/me.blogger.com \IPAddress 127.0.0.1
$ ping -q -c 1 me.blogger.com
PING me.blogger.com (127.0.0.1): 56 data bytes

--- me.blogger.com ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.077/0.077/0.077/0.000 ms
You can list the hosts you have set up, where they point, and you can delete them:
$ dscl localhost -list /Local/Default/Hosts
me.blogger.com
$
$ dscl localhost -read /Local/Default/Hosts/me.blogger.com
AppleMetaNodeLocation: /Local/Default
IPAddress: 127.0.0.1
RecordName: me.blogger.com
RecordType: dsRecTypeStandard:Hosts
$
$ sudo dscl localhost -delete /Local/Default/Hosts/me.blogger.com
$ dscl localhost -list /Local/Default/Hosts
$

Viewing all articles
Browse latest Browse all 25

Trending Articles