Resolve a name - like Windows does with Host file

Discussion in 'macOS' started by askywalker, Aug 14, 2008.

  1. askywalker macrumors regular

    Joined:
    Aug 18, 2007
    #1
    I need to resolve a name to an IP address... I do this on Vista (bootcamp) via the host file. I can't seem to find a way to do this on my Mac.

    I saw some other threads where Bonjour was recommended, but I don't really see that working for me. In my situation the domain resolves on the Internet - but at our office IT has funkiness where the name does not resolve (without editing the Host file).. When in the office I can change my mail servers and it will work - but this quickly gets tiring...

    My IT people do not approve of my Mac. Since I went rogue they are not able to help ...
     
  2. Mindflux macrumors 68000

    Mindflux

    Joined:
    Oct 20, 2007
    Location:
    Austin
    #2
    toss it in /etc/hosts

    you'll need to use a shell and sudo.
     
  3. r0k macrumors 68040

    r0k

    Joined:
    Mar 3, 2008
    Location:
    Detroit
    #3
    Perhaps "toss it in /etc/hosts" might not be quite enough for a windows user. The first question might be "where the heck is notepad or edit?"

    If I wanted to add an entry to my hosts file on my Mac, I would do the following because I am familiar with the rather primitive editor known as "vi"...

    1 - start a terminal and type the following (more or less verbatim)...
    2 - cd /etc
    3 - sudo vi hosts
    4 - [enter your normal login password for sudo when prompted]
    Now you are in the "vi" editor, do the following...
    5 - O
    Now you are in "insert mode" and you can enter your changes...
    6 - 111.222.333.444 hostname{cr}
    7 - 111.222.333.555 anotherhost{cr}
    8 - {esc}
    Now you are in command mode and you can write and exit vi...
    9 - :wq
    Now let's make sure it looks right, a list of ip addresses on the left with host names in the next column(s)
    10 - cat hosts
    11 - close the terminal you are all set

    You should see the lines you inserted when you view the file using "cat"

    "vi" can be frustrating because it is "stateful". There are 2 modes. Command and Insert mode. The capital O gets you into insert mode on a blank line. Escape gets you out of insert mode. ":wq", when entered in command mode writes the changed file and quits. "sudo" is needed to "vi" a file that you do not own. If there is a friendlier editor available to edit vi, I don't know what it is because I never bother to look.

    Why do I use vi? I've used it for years on Solaris, Linux and now OS X. It's almost always available on any *nix machine you sit down to use so I got used to it and it has come in handy more than once. For a simple task like a host file change, vi is good enough. More here.
     
  4. Makosuke macrumors 603

    Joined:
    Aug 15, 2001
    Location:
    The Cool Part of CA, USA
    #4
    Just a note:

    If you're going to use a terminal-based editor (instead of a graphical one intended for more technical use, like the free TextWrangler), I'd highly recommend using pico instead of vi unless you're already familiar with tha latter.

    vi is a lot more powerful, but Pico is drastically easier to use and has the most commonly used commands displayed at the bottom of the screen, so you can probably get it to do what you need without any instructions.

    r0k's instructions are otherwise fine, just type "sudo pico hosts" instead of "sudo vi hosts" and enter the suggested lines, then close the file and tell Pico to save changes when it asks.
     
  5. iShater macrumors 604

    iShater

    Joined:
    Aug 13, 2002
    Location:
    Chicagoland

Share This Page