## 3.9. Managing Hostnames and IP Addresses

Mac OS X 10.1 (and earlier versions of Mac OS X) only consulted /etc/hosts in single-user mode and stored hostname/IP address mappings in the /machines portion of the NetInfo database. As of Mac OS X 10.2, you can use the /etc/hosts file to map hostnames to IP addresses. For example, the following entry would map the hostname xyzzy to 192.168.0.1:

>     192.168.0.1   xyzzy

### 3.9.1. Creating a Host with niload

If you are using Mac OS X 10.1.5 (or an earlier version of Mac OS X), you'll need to use NetInfo to maintain the hosts database. 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 uses a here document instead of a separate file to add the host xyzzy:

>     # niload hosts . <<EOF
>     ? 192.168.0.1 xyzzy
>     ? EOF

If you add an entry that already exists, it will not be changed or overwritten. Instead, niload will silently ignore your command. (To override this behavior, see the -m option under "niload" in Section 3.6, earlier in this chapter.)

Copyright © 2003 O'Reilly & Associates. All rights reserved.