OS X equivalent of "hosts" file on Windows?

Discussion in 'Web Design and Development' started by EssentialParado, Sep 3, 2009.

  1. EssentialParado macrumors 65816

    Joined:
    Feb 17, 2005
    #1
  2. ChrisA macrumors G4

    Joined:
    Jan 5, 2006
    Location:
    Redondo Beach, California
    #2
    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.
     
  3. EssentialParado thread starter macrumors 65816

    Joined:
    Feb 17, 2005
    #3
    Me neither… but it's their servers so I'll just have to do it their way I suppose.

    Cheers.
     
  4. SrWebDeveloper macrumors 68000

    SrWebDeveloper

    Joined:
    Dec 7, 2007
    Location:
    Alexandria, VA, USA
    #4
    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
     
  5. kilowattradio macrumors regular

    kilowattradio

    Joined:
    May 11, 2009
    Location:
    Oregon
    #5
    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.

    Code:
    ##
    # 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
    
    
     
  6. EssentialParado thread starter macrumors 65816

    Joined:
    Feb 17, 2005
    #6
    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.
     
  7. Consultant macrumors G5

    Consultant

    Joined:
    Jun 27, 2007
  8. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #8
    A couple options

    1.) Edit through Terminal
    Code:
    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.
    Code:
    sudo open /etc/hosts
    Both options will ask for your password.
     
  9. EssentialParado thread starter macrumors 65816

    Joined:
    Feb 17, 2005
    #9
    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.
     
  10. lanky macrumors newbie

    Joined:
    Sep 18, 2009
    #10
  11. sl1200mk2 macrumors 6502

    Joined:
    Oct 17, 2006
    #11
    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/
     
  12. EssentialParado thread starter macrumors 65816

    Joined:
    Feb 17, 2005

Share This Page