Changing NetworkManager route metrics

If you use NetworkManager with more than one interface, you probably want to control the metric of their routes. Here’s one way you can do it.

Background

I got a PCI Express WiFi card (wlan0) and a USB WiFi dongle (wlan1). On my system, NetworkManager will activate both at the same time. Then it gives metric 600 to the first one to be activated, and 601 to the second one.

What I wanted was to say: hey, NetworkManager, use metric 500 for wlan1 and 600 for wlan0. It doesn’t look like this is supported, though. Also, DuckDuckGo and Google didn’t help me much.

Digging through the nm-settings(5) man page, though, I found the route-metric option.  It’s not ideal because it’s applied to a connection, not to a device.  But it works fine for my use case as each WiFi interface is connected to a different WiFi network.

Step 1: Find out which are your connections

Use the nmcli helper to list your connections:

$ nmcli connection
NAME       UUID                                  TYPE             DEVICE
Network 1  f0ed603c-f3c3-4acb-b54b-bb857bd9c5b5  802-11-wireless  wlan0       
Network 2  2b4b7240-36bd-407a-a3aa-169abb0ce6c4  802-11-wireless  wlan1

As you can see here, each interface is using a different connection.

Step 2: Set the connection’s default route metric

For example, to set the wlan1 interface’s default route metric to 500, just change its connection:

$ nmcli connection modify uuid 2b4b7240-36bd-407a-a3aa-169abb0ce6c4 ipv4.route-metric 500
$ nmcli connection modify uuid 2b4b7240-36bd-407a-a3aa-169abb0ce6c4 ipv6.route-metric 500
$ nmcli connection show   uuid 2b4b7240-36bd-407a-a3aa-169abb0ce6c4 | grep route-metric
ipv4.route-metric:                      500
ipv6.route-metric:                      500

Step 3: Check that your routing table is correct

NetworkManager should automatically change the route’s metric:

$ ip route
default via 192.168.25.1 dev wlan1  proto static  metric 500 
default via 192.168.0.1 dev wlan0  proto static  metric 600 
192.168.0.0/24 dev wlan0  proto kernel  scope link  src 192.168.0.111  metric 600 
192.168.25.0/24 dev wlan1  proto kernel  scope link  src 192.168.25.69  metric 500

If it didn’t, try restarting NetworkManager.

8 thoughts on “Changing NetworkManager route metrics”

  1. Nice summary & good (if hidden) tip!

    In one of my use cases, on a Raspberry Pi 2 running a Debian (jessie) based distro on armhf architecture, NetworkManager 0.9.10.0-7 does not offer the route-metrics option. So YMMV if using older NM versions.

    Thanks again,

    Adam.

  2. Thanks from me, too. This lets me setup my network routing rules the way I really need them much easier 🙂

    1. How can I make these changes persistent? Do you have an example boot script or systemd service?

      1. The changes are persistent. They get applied to the applicable connection profile in /etc/NetworkManager/system-connections/

  3. This has been irritating me for months: My lab network connection was always getting a lower routing metric than the corporate connection, so my ritual on every logon has been disconnecting the two connections and then reconnecting them in the order I want them in. Now I can concentrate on drinking my coffee. Thanks!

  4. The best in class, Depoxito come up with the money for you
    high-end experience that focus on the look and atmosphere of
    legal VIP standarts, we have enough money you the best glamorous
    to high-level experience of VIPs expect in any summit end casino, grand rouse casino royale present
    you the other studio design element including the grand blackjack, offering our VIP Customer the best experience
    of a Salon privee table.
    New style table also feature across the room following grand roulette upgraded on our
    provider playtechs mini prestige roulette which delivering more engaging and richer
    playing experience. The new experience contains a total of seven tables including five blackjack tables, one roulette table and
    one baccarat table. Grand flesh and blood casino royale has been high hand-engineered to fit the needs of our customer to using it, and contains unique elements that is specially designed to
    maximize the impact value we got from our customers and diversify it to the existing network.

    Soon, Depoxito will manufacture an better reality technology upon bring to life casino for our VIP
    member, these most ahead of its time technology ever seen in stir casino
    including this bigger reality. Which permit players to experience products on an entire further level which is never seen before literally leaping out of the game and
    taking the blackjack, baccarat, roulette and further game into the summative entire level.

    Depoxito VIP Baccarat, we offer you the categorically exclusive stimulate VIP Baccarat that is played later than occurring to 7 players at the thesame table and our severely trained lovely conscious baccarat dealer.

    And of course our VIP fanatic will environment as if they were essentially sitting at one of the summit
    casino baccarat table. This immersive gaming experience creates a hugely
    looking for excitement circulate that our VIP
    players will locate hard to surpass.
    Here is the list of flesh and blood casino game that depoxito provide, we meet the expense of the widest
    range of bring to life casino games on the broadcast including : blackjack unlimited, blackjack prestige,
    roulette, baccarat, poker, hi-lo, sic bo, and grand breathing casino royale such as Grand
    Baccarat, Grand Blackjack and Grand Roulette for our VIP member.
    And of course as a fanatic of Depoxito you can enjoy every the games that we manage to pay
    for to you, all you compulsion to complete is just visit our site depoxito and register it by yourself takes up
    to 3 minutes and next youre customary to action any
    game that you want.
    Be our VIP, visceral our VIP aficionado of course established
    you the best give support to you can acquire from
    us all you need to be a VIP enthusiast is unquestionably easy.

    every you infatuation is just keep playing upon our site,
    addition and work afterward a VIP following the amount that our company had written, keep playing and our customer support will gate you
    that you are promoted to become a VIP zealot on our site.

Leave a Reply

Your email address will not be published. Required fields are marked *