IP mapping in OS X

I know that in windows, the HOSTS file located in c:/WINDOWS/system32/DRIVERS/etc/HOSTS is used to map ip address to host names. Is there a similar file in mac OS X? if so, where is it located?

12" iBook G4, Mac OS X (10.4.7), 512Mb RAM upgrade

Posted on Jul 25, 2006 2:35 PM

Reply
9 replies

Jul 27, 2006 9:12 AM in response to never_more

One other thought - are you trying to read or write to this file?

If you're trying to write to it (which is an unusual thing to do), it's owned by root so your application will need to run with elevated privileges in order to change it.

If you're just reading it, there shouldn't be any need - the standard system resolver should reference /etc/hosts when you try to resolve any hostname.

Jul 31, 2006 12:45 AM in response to Camelot

im actually trying to write a completely new application, a joke application to give to my friend. I wrote the file for windows, and got it to work just fine with the absolute directory. Now im trying to port it to the mac. The problem is that when i put in the absolute path for the /etc/hosts it does nothing. Someone earlier back said it was because of the permissions. I dont think im using vi or pico to edit it, just the application itself to rewrite the file. Im wondering if it would be easier to just have the modified hosts file bundled in the application, then replace the old with the new. would this be possible. Oh and I think I should tell you, I am using the allegro game library when im programming in xcode.

Jul 31, 2006 9:29 AM in response to never_more

Well, there's one of the reasons why Mac OS X is considered more secure than Windows.

The hosts file has the potential to compromise a user's system and therefore there are restrictions on the file. Your app can't touch it without some kind of input from the user.

Having a copy of the file won't help (and is actually a bad idea since you don't know what the user has in their /etc/hosts and you risk losing it). You'd still need root permissions to overwrite the file.

You still need to either run your app as root or prompt the user at runtime for elevated privileges to touch the file.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

IP mapping in OS X

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.