How to set the route metric for IPv6 interfaces

My primary internet is through my cable provider, but I have a LTE USB stick as a backup for when the primary is down. I wrote a little script that constantly pings over both interfaces, and switches to the fallback if the primary is down. I do this by setting the route metrics of the two interfaces via uci network.$interface_name.metric=$new_metric. I set the metric of the interface I want active to 10, and the one that is inactive to 20.

This works fine for IPv4, but I recently got IPv6 working on the LTE connection (previously a software issue on the USB stick caused IPv4 only to work). Unfortunately, I immediately found that all IPv6 traffic started going over the LTE connection, while IPv4 traffic was going over the primary connection. It looks like setting the interface metric this way only sets it on the IPv4 default route, not the IPv6 default route.

Is there a way to easily do this for IPv6? I much prefer setting the metric via the uci command, as I don’t have to worry about parsing ip output to figure out the default route lines, and then crafting the proper ip command to update the route.

Side note: for such use cases I often heard of using [OpenWrt Wiki] mwan3 (Load balancing/failover with multiple WAN interfaces)

I did originally try mwan3 when I first was setting this up, but I just could not get it to actually work (after setting it up, I had no internet access at all, and could never figure it out).

Also, reading that page a bit, I’m not sure it will work right for me:

You will need to split your network interfaces if they are dual-stack. i.e. wan and wan6, wanb and wanb6 etc. You can create alias interfaces to achieve this requirement.

I’m not sure that’s possible for my setup; my LTE USB stick is an NCM interface. When it comes up, it creates virtual interfaces for IPv4 and (when enabled) IPv6. Not sure if that’s compatible with the approach mwan3 needs.

I think you can do with route or ip cmd.
First delete the existing one and then add new one.

adding example:

root@turris:~# route -A inet6 add default dev eth0 metric 1

root@turris:~# ip -6 route add default dev eth0 metric 1

I get that you can do that, but I’m hoping to avoid messy parsing of ip/route command output, because you can’t change routes without knowing the various parameters in them. I was hoping for something like the metric property at the OpenWRT interface level.

Don’t know if there is such setup in Luci.
I generally configure my system from cmd line.

I’m having a similar question specifically for IPv6 and metrics (although for OpenWrt generally). It would appear that the metric value only applies for static IPv6 or certain IPv6 interface types, it doesn’t work for something like DHCPv6 client.

The only way seems to be preventing the default route being added and then configuring static routes.

The documentation shows metric on the static IPv6 method, but for something like DHCPv6 client, it’s not there. Other IPv6 interface types may support the metric value, but not all.

Someone else flagged this, specifically with dhcpv6 interfaces

Thanks all! So it looks like my options are:

  1. Try to get mwan3 working again.
  2. Modify my script to keep the fallback interface disabled entirely, and only enable it if the primary goes down. (This isn’t ideal either, because I’ll have to keep the primary up all the time, even while down, in order to test its status, and then IPv6 traffic will 50/50 attempt that route, which won’t work.)
  3. Manually set the route metric on the IPv6 interface by parsing ip -6 route show dev wwan0 output, and then modify the routes as needed.

I’ll probably give mwan3 another look, on a day when it’s ok for the WAN connection to be down for a while as I inevitably have to troubleshoot :slight_smile: