2021-04-10 21:17:47 +02:00
|
|
|
# ip route
|
|
|
|
|
|
|
|
> IP Routing table management subcommand.
|
|
|
|
> More information: <https://manned.org/ip-route>.
|
|
|
|
|
2025-03-21 14:34:11 +02:00
|
|
|
- Display the `main` routing table:
|
2021-04-10 21:17:47 +02:00
|
|
|
|
2025-03-09 14:01:49 +02:00
|
|
|
`ip {{[r|route]}}`
|
2021-04-10 21:17:47 +02:00
|
|
|
|
|
|
|
- Add a default route using gateway forwarding:
|
|
|
|
|
2025-03-09 14:01:49 +02:00
|
|
|
`sudo ip {{[r|route]}} {{[a|add]}} default via {{gateway_ip}}`
|
2021-04-10 21:17:47 +02:00
|
|
|
|
|
|
|
- Add a default route using `eth0`:
|
|
|
|
|
2025-03-09 14:01:49 +02:00
|
|
|
`sudo ip {{[r|route]}} {{[a|add]}} default dev {{eth0}}`
|
2021-04-10 21:17:47 +02:00
|
|
|
|
|
|
|
- Add a static route:
|
|
|
|
|
2025-03-09 14:01:49 +02:00
|
|
|
`sudo ip {{[r|route]}} {{[a|add]}} {{destination_ip}} via {{gateway_ip}} dev {{eth0}}`
|
2021-04-10 21:17:47 +02:00
|
|
|
|
|
|
|
- Delete a static route:
|
|
|
|
|
2025-03-09 14:01:49 +02:00
|
|
|
`sudo ip {{[r|route]}} {{[d|delete]}} {{destination_ip}} dev {{eth0}}`
|
2021-04-10 21:17:47 +02:00
|
|
|
|
|
|
|
- Change or replace a static route:
|
|
|
|
|
2025-03-07 13:05:55 +02:00
|
|
|
`sudo ip {{[r|route]}} {{change|replace}} {{destination_ip}} via {{gateway_ip}} dev {{eth0}}`
|
2021-04-10 21:17:47 +02:00
|
|
|
|
|
|
|
- Show which route will be used by the kernel to reach an IP address:
|
|
|
|
|
2025-03-09 14:01:49 +02:00
|
|
|
`ip {{[r|route]}} {{[g|get]}} {{destination_ip}}`
|
2025-03-21 14:34:11 +02:00
|
|
|
|
|
|
|
- Display a specific routing table:
|
|
|
|
|
2025-03-23 11:22:03 +02:00
|
|
|
`ip {{[r|route]}} {{[l|list]}} {{[t|table]}} {{table_number}}`
|