Add the canonical name app01.example.test and alias app01 for 192.0.2.20 to /etc/hosts.
Which line is appropriate?
/etc/hosts lines start with an IP address followed by the canonical hostname and optional aliases separated by spaces. It is not an assignment file.
Detailed explanation
app01.example.test app01 192.0.2.20Incorrect. The address must be the first field.
Incorrect. The address must be the first field.
app01.example.test=192.0.2.20 app01Incorrect. /etc/hosts does not use assignment syntax.
Incorrect. /etc/hosts does not use assignment syntax.
192.0.2.20 app01.example.test app01Correct. The address, canonical name, and alias are in the correct order.
Correct. The address, canonical name, and alias are in the correct order.
nameserver 192.0.2.20 app01.example.testIncorrect. nameserver is a resolver configuration directive.
Incorrect. nameserver is a resolver configuration directive.
Try it yourself
An example you can run in a temporary verification environment.
printf '%s
' '192.0.2.20 app01.example.test app01' | awk '{print $1, $2, $3}'Expected result
192.0.2.20 app01.example.test app01Key points
- Address comes first
- Canonical name then aliases
- Use whitespace separators
Notes
- Environment: POSIX awk / 一時標準入力のみ
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.