Add an IPv4 default route through gateway 192.0.2.1 using enp1s0.
The gateway is reachable through enp1s0.
Which command is appropriate?
ip route add default via GATEWAY dev DEVICE adds a default destination, next hop, and egress interface to the runtime routing table.
Detailed explanation
ip route add 192.0.2.1 dev defaultIncorrect. The values and positions do not form a default-route command.
Incorrect. The values and positions do not form a default-route command.
ip route add default via 192.0.2.1 dev enp1s0Correct. It specifies the default destination, gateway, and interface.
Correct. It specifies the default destination, gateway, and interface.
ip address add default via 192.0.2.1 dev enp1s0Incorrect. address add operates on addresses, not routes.
Incorrect. address add operates on addresses, not routes.
ip link set default gateway 192.0.2.1 dev enp1s0Incorrect. link set changes link properties, not routing.
Incorrect. link set changes link properties, not routing.
Try it yourself
An example you can run in a temporary verification environment.
printf '%s
' 'default via 192.0.2.1 dev enp1s0'Expected result
default via 192.0.2.1 dev enp1s0Key points
- default is the destination
- via is the next hop
- dev is the egress interface
Notes
- Environment: route表現の表示のみ
- 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.