LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

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 with a specific metric (priority)
$ sudo ip route add [192.168.2.0/24] via [gateway_ip] metric [100]
copy
Add route to a specific routing table
$ sudo ip route add [10.0.0.0/8] dev [eth0] table [100]
copy
Add a route with a preferred source address
$ sudo ip route add [192.168.1.0/24] dev [eth0] src [192.168.1.5]
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 (static, boot, dhcp, etc.)
scope SCOPE
Scope of the route (global, link, host)
mtu NUM
Maximum Transmission Unit for the route
nexthop NEXTHOP
Define multipath route with multiple next hops

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), ip-address(8), route(8)

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid