Mapping Names to IP Addresses with the /etc/hosts File

We need a way for hostnames to map to IP addresses. Normally, this is done with DNS, but we don't have DNS set up yet. In the meantime, we can provide mappings for hosts we know about—such as hosts on our local network—with the /etc/hosts file.

/etc/hosts allows you to build a table in which each entry lists an IP address, its most common (or “official”) hostname, and any aliases (additional names that map to the same IP address), separated by spaces or tabs. This table is consulted before any DNS queries are made, so /etc/hosts acts both as a backup to DNS (if it's not available) and an override (if it's not serving correct information). The aliases can even be used as a shorthand for favorite ...

Get FreeBSD® Unleashed 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.