How to add Equal Cost Multipath Route [ECMP] to IP Routing?

You can add ECMP routes with the following command.

ip route add 172.16.0.0/24 
    nexthop via 10.0.1.1 dev ethX weight 1 
    nexthop via 10.0.2.1 dev ethY weight 1

Alternatively, you can use two separate commands, the second of which appends to the existing route.

ip route add 172.16.0.0/24 nexthop via 10.0.1.1 dev ethX weight 1
ip route append 172.16.0.0/24 nexthop via 10.0.2.1 dev ethY weight 1

You can either add all the nexthops at once or append them to an existing route to create an ECMP route.

The above steps show how to use CONFIG_IP_ROUTE_MULTIPATH if it is enabled in the kernel.

Note: You can use the above steps if adding two routes results in an error as below.

# ip route add DESTINATION via GATEWAY1 dev NET1 metric 1000
# ip route add DESTINATION via GATEWAY2 dev NET2 metric 1000
RTNETLINK answers: File exists

Leave a Reply