configuration

/etc/hosts — Static hostname mappings

Maps names to IPv4 or IPv6 addresses. Whitespace separates fields; # begins a comment. The file is consulted according to the system resolver and NSS policy, not necessarily before DNS. It does not configure routes, listening services or TLS certificates. Keep mappings minimal and avoid overriding unrelated names. Some applications cache or bypass system resolution.

Formal Syntax & Structure

linux syntaxlinux
IP_ADDRESS CANONICAL_NAME [ALIAS ...]

Parameters & Attributes

NameTypeDescription
IP_ADDRESSfieldIPv4 or IPv6 address
CANONICAL_NAMEfieldPrimary name
ALIASfieldAdditional names

Return Value

configuration or inspection

Name/address mapping. getent hosts NAME queries the configured lookup mechanisms; it does not prove network reachability.

Working Example

Example Snippetlinux
printf '%s\n' '192.0.2.10 app.example app # synthetic' | awk '{sub(/#.*/, ""); if (NF>=2) print $1, $2, $3}'
Linux Reference