LinuxCommandLibrary

ip-route-add

adds new routes to the kernel routing tables

TLDR

Add a default route via gateway

$ sudo ip route add default via [gateway_ip]
copy
Add a default route via interface
$ sudo ip route add default dev [eth0]
copy
Add a static route
$ sudo ip route add [192.168.1.0/24] via [gateway_ip] dev [eth0]
copy
Add route to a specific routing table
$ sudo ip route add [10.0.0.0/8] dev [eth0] table [100]
copy

SYNOPSIS

ip route add destination [options]

DESCRIPTION

ip route add adds new routes to the kernel routing tables. Routes determine how packets are forwarded to their destinations based on the destination address.
A route specifies either a gateway (next-hop router) to forward packets to, or an interface for directly connected networks. Multiple routing tables can be used for policy routing.

PARAMETERS

default

Default route (0.0.0.0/0 or ::/0)
via GATEWAY
Next-hop gateway address
dev DEVICE
Output device name
table TABLE
Routing table (number or name)
metric NUM
Route preference (lower = preferred)
src ADDRESS
Preferred source address
proto PROTOCOL
Routing protocol identifier

CAVEATS

Requires root privileges. Routes are not persistent across reboots without additional configuration. Adding conflicting routes may fail or create unexpected behavior.

HISTORY

The ip route command is part of iproute2, which replaced the older route command from net-tools. iproute2 provides unified management of all Linux networking features.

SEE ALSO

ip(8), ip-route(8), ip-route-list(8), ip-rule(8)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community