Linux
Apache
MySQL
PHP

CSS
XHTML1.1
XML/RSS

Creative Commons

2009-03-17 09:26:44

/etc/hosts Replacement In OSX

On all *nix hosts you can add an entry to the /etc/hosts file so that you don't have to remember an IP address, can force your machine to always hit a certain IP for a given hostname, or any other number of reasons. This, technically, will also work on OSX, however it's a little flaky and not all programs abide by the /etc/hosts entries like they do on other platforms.
Enter `dscl`, or the Directory Service Command Line. Users of older versions of OSX might remember the NetInfo Manager, where you could go to edit OSX's build in LDAP-style server to add/modify/delete users, server names, etc. The NetInfo Manager application no longer exists in Leopard, so if you want to add your own host entry, here is how to do it.
sudo dscl localhost -create /Local/Default/Hosts/yourHost.yourDomain.com IPAddress 1.1.1.1
That's all there is to it. The above command calls the dscl utility with root priviliges and adds an entry for the host yourHost.yourDomain.com to your machine's local directory. Now anytime you ping yourHost.yourDomain.com it will hit 1.1.1.1 instead of the previous location (whether that was nothing, because yourHost didn't exist, or another IP address, which you didn't want to hit).
If you'd like to list all of the host entries in your local directory along with their configured IP Address, you can use this command:
dscl localhost -list /Local/Default/Hosts IPAddress


Back


Post a comment!

Name:
Comment: