The ip route add
command in Linux is used to add a new route to the IP routing table. The syntax for the ip route add
command is as follows:
ip route add network/mask dev interface
where:
network/mask
: This is the IP address and netmask for the network you want to route.dev
: This is the name of the network interface through which you want to route the network.interface
: This is the IP address of the next hop router for the network.
For example, to add a route to network 192.168.100.0/24 through interface eth0
and next hop router with IP address 192.168.1.1
, you would run the following command:
ip route add 192.168.100.0/24 dev eth0 via 192.168.1.1
The ip route add
command is used to add static routes to the routing table. This can be useful in situations where you want to route traffic to a specific network through a different interface or next hop router than the default route.
Note: The ip route add
command is used with the ip
command, which is a versatile tool for managing network interfaces and routing in Linux. Before using the ip route add
command, it’s important to have a good understanding of IP networking and the routing table.