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.
app01.example.test=192.0.2.20 app01Incorrect. /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.
nameserver 192.0.2.20 app01.example.testIncorrect. 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
Network interface
A host attachment whose link state and addresses can be managed.
Connection profile
Saved settings used to activate a persistent network connection.
Routing table
Rules that select the next hop for each destination network.