nerdexam
Linux_Foundation

LFCS · Question #261

Which of the following looks like a correct entry in the /etc/hosts file?

The correct answer is D. 127.0.0.1 localhost.localdomain localhost. The /etc/hosts file maps IP addresses to hostnames and aliases, with the IP address listed first.

Submitted by marco_it· Apr 18, 2026Networking

Question

Which of the following looks like a correct entry in the /etc/hosts file?

Options

  • Alocalhost 127.0.0.1 localhost.localdomain
  • Blocalhost.localdomain localhost 127.0.0.1
  • Clocalhost localhost.localdomain 127.0.0.1
  • D127.0.0.1 localhost.localdomain localhost
  • Elocalhost.localdomain 127.0.0.1 localhost

How the community answered

(45 responses)
  • A
    4% (2)
  • C
    2% (1)
  • D
    91% (41)
  • E
    2% (1)

Why each option

The /etc/hosts file maps IP addresses to hostnames and aliases, with the IP address listed first.

Alocalhost 127.0.0.1 localhost.localdomain

This entry places the alias 'localhost' first, which is incorrect as the IP address must precede hostnames and aliases.

Blocalhost.localdomain localhost 127.0.0.1

This entry places the FQDN 'localhost.localdomain' first, which is incorrect as the IP address must precede hostnames and aliases.

Clocalhost localhost.localdomain 127.0.0.1

This entry places the alias 'localhost' first, which is incorrect as the IP address must precede hostnames and aliases.

D127.0.0.1 localhost.localdomain localhostCorrect

A correct /etc/hosts entry starts with the IP address, followed by the fully qualified domain name (FQDN) or canonical hostname, and then any aliases. Option D correctly places the IP 127.0.0.1 first, followed by the FQDN localhost.localdomain and the alias localhost.

Elocalhost.localdomain 127.0.0.1 localhost

This entry places the FQDN 'localhost.localdomain' first, which is incorrect as the IP address must precede hostnames and aliases.

Concept tested: /etc/hosts file format

Source: https://man7.org/linux/man-pages/man5/hosts.5.html

Topics

#hosts file#name resolution#IP addressing#networking configuration

Community Discussion

No community discussion yet for this question.

Full LFCS Practice