Using HOSTS file on OS X...? Need Unix expert!

Diomedes

macrumors 6502
Original poster
Oct 5, 2004
250
0
San Francisco
In my environment, I often have to access servers who are not in the common DNS server. Normally, communication between servers on my subnet and their is no problem, since they have static IP addresses and explicit configurations to allow connectivity. However, workstation access to them is another issue - their host name does not resolve (although the IP address itself returns a ping.)

On my Windows PC, I just have a HOSTS table that maps the IP address with the host name of the server I am trying to access. However, without my WAN team assigning me a static IP address and creating static routes to those servers, I seemingly can't access them from my Mac (to do an FTP transfer, for example). Is it possible to use a HOSTS file on OS X? I would think with its Unix foundation, the answer is yes, but I haven't found any information on it. Any help would be much appreciated.
 

Jalexster

macrumors 6502a
Jun 8, 2004
668
0
You can. But I forgot how. Try Apple's support database. It's got a ****load of information.
 

GeeYouEye

macrumors 68000
Dec 9, 2001
1,652
6
State of Denial
You can and, sadly, I don't remember how. But here's how not to do it: edit /etc/hosts, something that's atypical for a UNIX. OS X uses /etc/hosts only when booted into single-user mode. I think the file you want might be /etc/hosts.equiv, but I could be wrong.
 

wrc fan

macrumors 65816
GeeYouEye said:
You can and, sadly, I don't remember how. But here's how not to do it: edit /etc/hosts, something that's atypical for a UNIX. OS X uses /etc/hosts only when booted into single-user mode. I think the file you want might be /etc/hosts.equiv, but I could be wrong.
OS X uses the /etc/hosts file as a last resort so editing it is an acceptable way. All you have to do is put the ip address on the left and the name you want to point to that ip address to the right of it. Sometimes if I change an ip address it doesn't get the change till I do a `lookupd -flushcache`, but after that it works fine.
 

jim.

macrumors 6502
Dec 22, 2004
308
0
C-ville, VA
oaklandbum is right. OSX does use the /etc/hosts file. I don't even think it is a last resort. I define custom IPs in mine for blocking ad sites, and surprisingly I see no ads or popups. By definition most UNIX and NIX systems use the hosts file as the very first resource for lookup information.

Now for your question... It is easy to edit the hosts file. Using your favorite editor (with root access) simply add on to the end of the file:

ip address hostname

So if I want to define www.cnn.com as 1.2.3.4 then I would add:

1.2.3.4 www.cnn.com

to my hosts file. It's that easy. Just, whatever you do, do not get rid of the loopback entry: which is typically 127.0.0.1 localhost. I know in other *nix systems doing this will cause general unresponsiveness in most programs as the system tries to figure out what it is called.

Hope this helps

Jim
 

emw

macrumors G4
Aug 2, 2004
11,177
0
cubist said:
You are supposed to use Applications - Utilities - Netinfo Manager. It's not hard.
Then perhaps you can shed some light on this thread.

Doctor Q and I have had some issues with system log errors that are a little confusing.
 

Diomedes

macrumors 6502
Original poster
Oct 5, 2004
250
0
San Francisco
jim. said:
oaklandbum is right. OSX does use the /etc/hosts file. I don't even think it is a last resort. I define custom IPs in mine for blocking ad sites, and surprisingly I see no ads or popups. By definition most UNIX and NIX systems use the hosts file as the very first resource for lookup information.

Now for your question... It is easy to edit the hosts file. Using your favorite editor (with root access) simply add on to the end of the file:

ip address hostname

So if I want to define www.cnn.com as 1.2.3.4 then I would add:

1.2.3.4 www.cnn.com

to my hosts file. It's that easy. Just, whatever you do, do not get rid of the loopback entry: which is typically 127.0.0.1 localhost. I know in other *nix systems doing this will cause general unresponsiveness in most programs as the system tries to figure out what it is called.

Hope this helps

Jim
Thanks. I ws just going to use the hosts file from my PC. I guess my questin was how/where do I put it in OS X? And should applications like Transmit automatically recognize it?
 

wrc fan

macrumors 65816
Diomedes said:
Thanks. I ws just going to use the hosts file from my PC. I guess my questin was how/where do I put it in OS X? And should applications like Transmit automatically recognize it?
The host file for you PC I don't believe contains the loopback info in the current on, so I'd suggest just editing /etc/hosts to have the same domains (you can probably just copy and paste). Then all applications will be able to use the names.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.