Add & remove route with low priority in Linux

Posted on

Problem :

For a VPN network, to use non-VPN route as default, the article Wireguard Split Tunnel By Adding Low Metric Route describes how to run a command in PowerShell to achieve this behaviour.

In PowerShell, it is required to run the following command to add a route with a low priority (interface metric)

route add mask IF $wgInterface.ifIndex metric 9999; Set-NetIPInterface -InterfaceIndex $wgInterface.ifIndex -InterfaceMetric 9999;

And once finished / VPN is de-activated run:

route delete mask if $wgInterface.ifIndex metric 9999; Set-NetIPInterface -InterfaceIndex $wgInterface.ifIndex -InterfaceMetric 9999;

What is the equivalent of these commands in Linux please?

Solution :

To add the route:

sudo ip route add default metric 9999 via

To remove it again:

sudo ip route delete default metric 9999 via

where default corresponds to your mask while the via corresponds to your third (the next-hop address), so adapt accordingly if you don’t really want to route everything to the all-zeroes address.

See man ip-route for details.

Leave a Reply

Your email address will not be published.