How to Manage Multipath Routing Objects in Linux Using ip nexthop

In traditional Linux networking, routes and their associated gateway gateways (nexthops) were tightly coupled. If an enterprise network or data centre switch required Equal-Cost Multi-Path (ECMP) routing across multiple upstream links, each route entry had to define its full list of gateways. Whenever a physical link failed or a gateway changed, the kernel or routing daemon (such as BGP via FRRouting) had to iterate through and rewrite thousands of individual routing table entries, inducing high CPU overhead and transient packet loss.

To eliminate this bottleneck, Linux kernel 5.3 introduced the dedicated ip nexthop subsystem into the iproute2 suite. Nexthop objects decouple routing targets from forwarding paths. Administrators define nexthops—and multipath nexthop groups—as independent objects with unique numerical IDs. Routes simply reference these IDs. Updating a single nexthop immediately updates every associated route across the operating system instantaneously. If you manage advanced enterprise routing on Linux, you may also find our tutorials on configuring policy-based routing with ip rule and managing alternate network interface names with ip link valuable.

Verifying ip nexthop Support in Your Linux Kernel

Before creating nexthop objects, ensure your Linux distribution runs kernel 5.3 or later and has the CONFIG_IP_NEXTHOP kernel compile option enabled:

# Check kernel version
uname -r

# Verify iproute2 support by querying existing nexthops
ip nexthop show

If the command executes cleanly without returning an “Object \”nexthop\” is unknown” error, your operating system is fully equipped to use nexthop routing objects.

Creating Individual Nexthop Objects

Individual nexthops represent a specific next-hop gateway address and egress network interface. To create a nexthop, assign it a unique integer identifier:

# Create nexthop 1 via gateway 192.168.10.1 on eth0
sudo ip nexthop add id 1 via 192.168.10.1 dev eth0

# Create nexthop 2 via gateway 192.168.20.1 on eth1
sudo ip nexthop add id 2 via 192.168.20.1 dev eth1

# Create an IPv6 nexthop with a blackhole discard rule
sudo ip nexthop add id 3 blackhole

To inspect all configured nexthop definitions, execute:

ip nexthop show

The output lists the ID, gateway IP, associated device, carrier status, and reference counter indicating how many active routes point to the object.

Building ECMP Multipath Nexthop Groups

The true power of ip nexthop lies in creating multipath groups that distribute outbound network traffic across multiple physical uplinks:

# Combine nexthop 1 and nexthop 2 into an equal-weight ECMP group (ID 10)
sudo ip nexthop add id 10 group 1/2

# Create an unequal-weight group (ID 11) directing 2/3 of traffic to eth0 and 1/3 to eth1
sudo ip nexthop add id 11 group 1,2/2,1

Linux supports resilient hashing for multipath groups, which is particularly beneficial for consistent hashing across server load balancers and BGP routers when link states fluctuate:

# Create a resilient hashing nexthop group
sudo ip nexthop add id 20 group 1/2 type resilient buckets 32 idle_timer 60

Binding Routes to Nexthop Objects

Once your nexthop objects and groups are defined, assigning them to destination network routes requires passing the nhid parameter instead of traditional via clauses:

# Route a specific subnet using the ECMP nexthop group 10
sudo ip route add 10.50.0.0/16 nhid 10

# Set the default route using nexthop group 10
sudo ip route replace default nhid 10

Querying the routing table demonstrates the streamlined configuration:

ip route show 10.50.0.0/16

The output displays 10.50.0.0/16 nhid 10 proto boot metric 100, clearly denoting that forwarding resolution is offloaded to nexthop object 10.

Updating and Deleting Nexthop Objects Dynamically

If an upstream Internet service provider or gateway goes offline for scheduled maintenance, you do not need to touch your routing tables. Simply replace the nexthop group definition, and traffic reroutes immediately across remaining links:

# Dynamically remove nexthop 2 from group 10 without changing routes
sudo ip nexthop replace id 10 group 1

# Delete an obsolete nexthop object (routes referencing it must be modified first)
sudo ip nexthop del id 2

This decoupling provides enterprise network administrators with unmatched agility, rapid failover convergence, and simplified automation scripts across modern Linux infrastructure.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.