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.
ip neighbor add default via 192.0.2.1 dev enp1s0Incorrect. 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.
ip route show default via 192.0.2.1 dev enp1s0Incorrect. 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
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.