Using NetInfo Manager Instead of the Hosts File

Discussion in 'General Mac Discussion' started by mishka, Nov 16, 2003.

  1. mishka macrumors newbie

    Joined:
    Oct 8, 2003
    #1
    A forum I visit broke on the weekend (and is still broken) such that it's address was no longer configured to any website. PC users avoided this problem by adding a new line to their hosts file containing the ip address and web address of the forum. However I understand that hosts file in Mac osx aren't used in that way and that the Netinfo Manager is supposed to replace its function. In Netinfo Manager I added a new subdirectory under machines, named it as the web address and added its ip address as a new property. However that hasn't worked to solve the problem. Is this the wrong approach or are there additional things I need to do?

    Thanks for any help you can offer.
     
  2. daveL macrumors 68020

    daveL

    Joined:
    Jun 18, 2003
    Location:
    Montana
    #2
    You only have to use netinfo with OS X 10.1.5 or earlier. As of 10.2, you can use /etc/hosts. I just added an entry to /etc/hosts and could then ping the host name. Otherwise, check out the man pages for niload, nicl, and nidump. Also, you might find "Mac OS X for Unix Geeks" interesting.
     
  3. Doctor Q Administrator

    Doctor Q

    Staff Member

    Joined:
    Sep 19, 2002
    Location:
    Los Angeles
    #3
    If you'd like to do it the Netinfo way (so it'll work on any Mac OS X release), don't bother reading the man (manual) pages, because I already did it for you. I'm not at the correct machine right now to look it up, but by tomorrow I'll post the exact commands you can use to add a hostname and IP address to Netinfo, and a little add-a-host shell script I wrote to make it very convenient to use.
     
  4. Doctor Q Administrator

    Doctor Q

    Staff Member

    Joined:
    Sep 19, 2002
    Location:
    Los Angeles
    #4
    Here are the commands I promised to post. If you want to add hostname poobah with IP address 11.12.13.14 to the local machines identified in the Netinfo database, become superuser (using sudo for each command, using su, or by logging in as root) and type these commands:
    Code:
    niutil -create / /machines/poobah
    niutil -createprop / /machines/poobah ip_address 11.12.13.14
    I wrote this little shell script to make it even easier:
    Code:
    #!/bin/sh
    if [ $# -ne 2 ] ; then
        echo "Usage: add_a_host hostname ipaddress"
        exit 1
        fi
    USERNO=`id | cut -d= -f2 | cut -d\( -f1`
    if [ "$USERNO" != "0" ] ; then
        echo "You must be superuser to use the add_a_host command."
        exit 1
        fi
    NEWHOST="$1"
    NEWIP="$2"
    ALLHOSTS=`niutil -list / /machines | awk '{print $2}'`
    for ONEHOST in $ALLHOSTS ; do
        if [ "$ONEHOST" = "$NEWHOST" ] ; then
            echo "Host $NEWHOST is already defined."
            exit 1
            fi
        done
    niutil -create / /machines/$NEWHOST
    niutil -createprop / /machines/$NEWHOST ip_address $NEWIP
    exit 0
    If you put this script, as file add_a_host, somewhere in your execution path and give it execute permissions, you can add a host with a command like this:
    Code:
    sudo add_a_host poobah 11.12.13.14
     
  5. mishka thread starter macrumors newbie

    Joined:
    Oct 8, 2003
    #5
    Thanks for all your help. The web page got fixed before I got to try it out, but I'll keep all this info for future reference.

    :) mishka
     

Share This Page