$linuxjunkies
>

ip-route(8)

Show and manipulate IP routing tables.

UbuntuDebianFedoraArch

Synopsis

ip route { add | del | replace | show | flush | get } ROUTE

Description

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

FlagWhat it does
addAdd a new route to the routing table
delDelete a route from the routing table
replaceReplace an existing route
showDisplay routes (default action if no command specified)
dev DEVICESpecify the network interface for the route
via GATEWAYSet the next-hop gateway address
metric NUMBERSet the route metric (cost/priority)
table TABLESpecify routing table (main, local, or numeric ID)
defaultAdd/show default route (0.0.0.0/0)
src IPSet preferred source address for packets using this route

Examples

Display all routes in the main routing table

ip route show

Add 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.1

Add a route specifying both gateway and network interface

ip route add 192.168.2.0/24 via 192.168.1.1 dev eth0

Set default route with metric 100 (lower metric = higher priority)

ip route add default via 192.168.1.1 metric 100

Delete the route to 192.168.2.0/24 network

ip route del 192.168.2.0/24

Show which route would be used to reach 8.8.8.8

ip route get 8.8.8.8

Display routes from all routing tables

ip route show table all

Replace existing route or add if not present

ip route replace 10.0.0.0/8 via 192.168.1.254 dev eth1

Related commands