The ip route add
command is used to add a new route to the Linux kernel's routing table. It is typically used to specify the next hop for a particular network or host.
The basic syntax of the ip route add
command is:
ip route add [ options ] destination [ via gateway ] [ dev device ] [ metric n ] [ mtu n ] [ advmss n ]
destination
is the network or host that the route applies to. It can be specified in CIDR notation (e.g., 192.0.2.0/24
for a network or 192.0.2.1
for a host).via gateway
is the next hop for the route. It can be specified as an IP address or a hostname.dev device
is the name of the network interface that the route applies to.metric n
is the metric (or cost) of the route. A lower metric indicates a more preferred route.mtu n
is the maximum transmission unit (MTU) of the route.advmss n
is the maximum segment size (MSS) advertised to TCP connections over the route.Here are some examples of how the ip route add
command can be used:
192.0.2.0/24
through the gateway 192.0.2.1
:ip route add 192.0.2.0/24 via 192.0.2.1
192.0.2.1
through the gateway 192.0.2.2
:ip route add 192.0.2.1 via 192.0.2.2
192.0.2.0/24
through the gateway 192.0.2.1
using the eth0
network interface:ip route add 192.0.2.0/24 via 192.0.2.1 dev eth0