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.
Question
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)- A4% (2)
- C2% (1)
- D91% (41)
- E2% (1)
Why each option
The /etc/hosts file maps IP addresses to hostnames and aliases, with the IP address listed first.
This entry places the alias 'localhost' first, which is incorrect as the IP address must precede hostnames and aliases.
This entry places the FQDN 'localhost.localdomain' first, which is incorrect as the IP address must precede hostnames and aliases.
This entry places the alias 'localhost' first, which is incorrect as the IP address must precede hostnames and aliases.
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.
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
Community Discussion
No community discussion yet for this question.