LinuxCommandLibrary

ip-route

TLDR

Show routing table

$ ip route
copy
Add default gateway
$ sudo ip route add default via gateway_ip
copy
Add default via interface
$ sudo ip route add default dev eth0
copy
Add static route
$ sudo ip route add destination_ip via gateway_ip dev eth0
copy
Delete route
$ sudo ip route delete destination_ip dev eth0
copy
Change route
$ sudo ip route change destination_ip via gateway_ip dev eth0
copy
Get route to destination
$ ip route get destination_ip
copy
Show specific table
$ ip route list table 100
copy

SYNOPSIS

ip route [command] [OPTIONS]

DESCRIPTION

ip route manages the kernel routing table. It can add, delete, and modify routes, as well as query which route the kernel will use for a specific destination.

PARAMETERS

list (or no command)

Display the routing table
add
Add a new route
delete
Remove a route
change
Modify an existing route
replace
Change or add if not exists
get address
Show route for a specific destination
default
Default gateway route
via gateway
Specify next-hop gateway
dev interface
Specify output interface
table id
Work with a specific routing table

CAVEATS

Routes added are not persistent; use network configuration files for persistence. Multiple routing tables can be used with policy routing. The default table is "main".

HISTORY

ip route is part of iproute2, replacing the deprecated route command.

SEE ALSO

ip(8), ip-address(8), routel(8)

Copied to clipboard