7.11. Creating the /etc/hosts File

If a network card is to be configured, decide on the IP address, FQDN, and possible aliases for use in the /etc/hosts file. The syntax is:

<IP address> myhost.example.org aliases

Unless the computer is to be visible to the Internet (i.e., there is a registered domain and a valid block of assigned IP addresses—most users do not have this), make sure that the IP address is in the private network IP address range. Valid ranges are:

    Class Networks
        B through
        C through

A valid IP address could be A valid FQDN for this IP could be www.linuxfromscratch.org (not recommended because this is a valid registered domain address and could cause domain name server issues).

Even if not using a network card, an FQDN is still required. This is necessary for certain programs to operate correctly.

Create the /etc/hosts file by running:

cat > /etc/hosts << "EOF"
# Begin /etc/hosts (network card version) localhost
[] [<HOSTNAME>.example.org] [HOSTNAME]

# End /etc/hosts (network card version)

The [] and [<HOSTNAME>.example.org] values need to be changed for specific users or requirements (if assigned an IP address by a network/system administrator and the machine will be connected to an existing network).

If a network card is not going to be configured, create the /etc/hosts file by running:

cat > /etc/hosts << "EOF"
# Begin /etc/hosts (no network card version) [<HOSTNAME>.example.org] [HOSTNAME] localhost

# End /etc/hosts (no network card version)