Add a running IPv4 default route via gateway 192.0.2.1 on enp1s0.
Use iproute2.
Which command is appropriate?
ip route add default via GATEWAY dev INTERFACE adds an IPv4 default route. Persistent configuration must be handled by the network manager as well.
Detailed explanation
ip address add default 192.0.2.1 dev enp1s0Incorrect. address configures local addresses, not default routes.
Incorrect. address configures local addresses, not default routes.
ip neighbor add default via 192.0.2.1 dev enp1s0Incorrect. neighbor manages the neighbor table, not a routed next hop.
Incorrect. neighbor manages the neighbor table, not a routed next hop.
ip route add default via 192.0.2.1 dev enp1s0Correct. It adds the default route through 192.0.2.1 on enp1s0.
Correct. It adds the default route through 192.0.2.1 on enp1s0.
ip route show default via 192.0.2.1 dev enp1s0Incorrect. show only inspects and does not add a route.
Incorrect. show only inspects and does not add a route.
Try it yourself
An example you can run in a temporary verification environment.
ip route help 2>&1 | sed -n '1,4p'Expected result
ip routeのadd、delete、showなどの構文概要Key points
- route add default
- via is the next hop
- dev selects the output interface
Notes
- Environment: iproute2 help / 状態変更なし
- 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.