View Full Version : Using NetInfo Manager Instead of the Hosts File
mishka
Nov 16, 2003, 08:59 PM
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.
daveL
Nov 17, 2003, 06:05 PM
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.
Doctor Q
Nov 17, 2003, 06:15 PM
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.
Doctor Q
Nov 18, 2003, 11:29 AM
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:niutil -create / /machines/poobah
niutil -createprop / /machines/poobah ip_address 11.12.13.14I wrote this little shell script to make it even easier:#!/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 0If 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:sudo add_a_host poobah 11.12.13.14
mishka
Nov 19, 2003, 06:14 PM
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
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.