PDA

View Full Version : OS X equivalent of "hosts" file on Windows?




EssentialParado
Sep 3, 2009, 11:29 AM
I was directed to read the following instructions, but they're for a Windows machine it seems:

http://www.000webhost.com/forum/faq/7613-howto-view-your-site-before-dns-update.html

Anyone have any clue how to perform the same technique under OS X?



ChrisA
Sep 3, 2009, 11:45 AM
I was directed to read the following instructions, but they're for a Windows machine it seems:

http://www.000webhost.com/forum/faq/7613-howto-view-your-site-before-dns-update.html

Anyone have any clue how to perform the same technique under OS X?

The filename on Mac OS X and all other Unix systems is "/etc/hosts"

But I don't know why anyone would need to edit an /etc/hosts file if the names are already on a DNS server.

EssentialParado
Sep 3, 2009, 11:47 AM
Me neither… but it's their servers so I'll just have to do it their way I suppose.

Cheers.

SrWebDeveloper
Sep 3, 2009, 12:09 PM
It is possible to define LOCAL hostnames that only resolve on that computer. Developers use this to create fake domain names for sandboxes (development platform). This isn't common because it's just as easy to access a local web site sandbox using 127.0.0.1 or localhost as the hostname, duh. But if you wanted to setup say port 82 on your web server with a virtual host pointing to myfakedomain.com mapped to 127.0.0.2 and be able to locally browse to it via http://myfakedomain.com:82 for example - you could. Not though you would go through all that trouble...

-jim

kilowattradio
Sep 3, 2009, 12:22 PM
I was directed to read the following instructions, but they're for a Windows machine it seems:

http://www.000webhost.com/forum/faq/7613-howto-view-your-site-before-dns-update.html

Anyone have any clue how to perform the same technique under OS X?

You just put the references in /etc/hosts
Here is my /etc/hosts I use for local network and to block adds by referring some advertisers to my routers web page instead 127.0.0.1 to prevent error messages about no server.


##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
192.168.0.100 c5.zedo.com
192.168.0.100 mac
192.168.0.101 winvista
192.168.0.102 linux
192.168.0.1 d-link
192.168.100.1 cable-modem
192.168.100.1 a248.e.akamai.net
192.168.100.1 cdn.optmd.com

EssentialParado
Sep 3, 2009, 05:30 PM
What's the easiest way to edit the file?

I can open it into text edit but I can't save because of the permissions on it.

Is there a way to temporarily override the permissions to edit a file? Or would you edit it via Terminal? Or is the simplest way of doing it to change all folder permissions?

The web host is changing the FAQ to include Mac and Linux users so I'm trying to figure out the simplest instructions. Cheers.

Consultant
Sep 3, 2009, 05:44 PM
google: osx hosts file

angelwatt
Sep 3, 2009, 06:00 PM
What's the easiest way to edit the file?

A couple options

1.) Edit through Terminal
sudo pico /etc/hosts
Hit ctrl+x to exit after done editing, then hit y to save on exit.

2.) Edit in TextEdit and get it there through Terminal.
sudo open /etc/hosts

Both options will ask for your password.

EssentialParado
Sep 3, 2009, 06:29 PM
Thanks for the tip.

Sudo open was able to open the file in textedit but still wouldn't save it from textedit. Sudo pico did work though.

lanky
Sep 18, 2009, 09:16 PM
I was directed to read the following instructions, but they're for a Windows machine it seems:

http://www.000webhost.com/forum/faq/7613-howto-view-your-site-before-dns-update.html

Anyone have any clue how to perform the same technique under OS X?

I wrote my own guide at http://wiki.lankyland.com/Hosts_File#Mac_OSX

sl1200mk2
Sep 25, 2009, 10:21 AM
If you don't like editing files via Terminal, there's a freeware app that makes it dead simple to do via a nice little GUI:

http://www.clockwise.ee/gasmask/

EssentialParado
Sep 25, 2009, 11:02 AM
Cool! Thanks for that :)