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.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access