Managing Hostnames and IP Addresses
Mac
OS X consults both the
/etc/hosts
file and the
/machines
portion of the local directory. For
example, the following entry in /etc/hosts
maps
the hostname xyzzy
to 192.168.0.1:
192.168.0.1 xyzzy
Creating a Host with niload
The niload
utility understands the flat-file format used by
/etc/hosts
(ip_address
name
). See the
hosts(5)
manpage for a description of each field.
To add a new host, create a file using that format and
load it with niload
. This example adds the host
xyzzy
:
$sudo niload hosts . <<EOF
>192.168.0.1 xyzzy
>EOF
If you add an entry that already exists, it will be overwritten.
The /etc/hosts
file takes precedence over the
local directory, so if you enter the same hostname with different IP
addresses in both places, Mac OS X uses the one in
/etc/hosts
.
Get Mac OS X Panther in a Nutshell, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.