ip-route(8)
Show and manipulate IP routing tables.
Synopsis
ip route { add | del | replace | show | flush | get } ROUTEDescription
The ip route command is used to display and modify the kernel's IP routing table. Routes determine how packets are forwarded from one network to another based on their destination IP address.
Common operations include adding static routes, deleting routes, and displaying the current routing table. Routes can be added to specific interfaces, with custom metrics, and for different types of traffic (unicast, multicast, blackhole, etc.).
Common options
| Flag | What it does |
|---|---|
add | Add a new route to the routing table |
del | Delete a route from the routing table |
replace | Replace an existing route |
show | Display routes (default action if no command specified) |
dev DEVICE | Specify the network interface for the route |
via GATEWAY | Set the next-hop gateway address |
metric NUMBER | Set the route metric (cost/priority) |
table TABLE | Specify routing table (main, local, or numeric ID) |
default | Add/show default route (0.0.0.0/0) |
src IP | Set preferred source address for packets using this route |
Examples
Display all routes in the main routing table
ip route showAdd a route to reach 192.168.2.0/24 network through gateway 192.168.1.1
ip route add 192.168.2.0/24 via 192.168.1.1Add a route specifying both gateway and network interface
ip route add 192.168.2.0/24 via 192.168.1.1 dev eth0Set default route with metric 100 (lower metric = higher priority)
ip route add default via 192.168.1.1 metric 100Delete the route to 192.168.2.0/24 network
ip route del 192.168.2.0/24Show which route would be used to reach 8.8.8.8
ip route get 8.8.8.8Display routes from all routing tables
ip route show table allReplace existing route or add if not present
ip route replace 10.0.0.0/8 via 192.168.1.254 dev eth1