“ip route add” – Add Route In Linux

Linux provides the ip route command in order to manage the routing table. The routing table is used to set routes for different destination IP addresses. Even there is a default route in most of the cases which are used to sent IP packets to the other networks we may need to add new routes via the command-line interface by using the ip route add command.

List Current Routes/Routing Table

Before starting to add new routes current routes or routing table can be checked to prevent collussions with exitsting routes. The ip route command can be used to list current routes.

$ ip route
default via dev ens33 proto dhcp metric 100 dev ens33 scope link metric 1000 dev ens33 proto kernel scope link src metric 100 

The first line starting with the default is the default route where all unmatched IP packets are sent through this route or default gateway.

Add New Default Gateway Route

Generally, Linux distributions use helper tools that add default gateway according to the DHCP server. But in some cases, this may not work or we may need to add a new route or default gateway. First of all, in order to change a Linux system routing table, we require root privileges that can be provided with the sudo command or by elevating to the root user. In the following example, we add the “” as the default route.

$ sudo ip route add default via

Add New Route Specifying Destination IP Address

A new route can be added for the specified network range by specifying gateway address. In the following example we add the “” as gateway for the network “”. This means when a IP packate with the destiantion adress with the “” is processed the first hop is “”.

$ sudo ip route add via

Add New Route Specifying Destination Network Interface/Device

The ip route add command can be used with a device name as destiantion gateway. The specified network interface or network device gateway address is used automatically as the gateway. In the following example we set the eth1 network interface as destiantion device for the network “”. If an IP packet is processed the next hop is the “eth1” network device gateway.

$ sudo ip route add dev eth1

Leave a Comment