loading...

How to set metric in OS moderated with NetworkManager

emamirazavi profile image S.Mohammad Emami Razavi ・2 min read

Sometimes we want to have several connections at the same time, one to the ethernet (wired lan) and one other to the wireless router, with two different gateways. In this documentation i describe how to make wireless connection prior to ethernet connection in each linux OS using NetworkManager service to moderate network connections. I've tested these instruction in fedora 31 already.

List your connections

 [m.emami@home ~]$ nmcli connection 
 NAME        UUID                                  TYPE      DEVICE               
 sample1     a16d1a96-2833-4876-a6c2-************  vpn       wlp0s20f0u11 
 bevaght     f46ba9ff-1114-4e79-9c8a-************  wifi      wlp0s20f0u11
 eth1        7648e3eb-c03f-46e9-b24e-************  ethernet  enp2s0

Edit the wireless connection

[m.emami@home ~]$ nmcli connection edit bevaght

===| nmcli interactive connection editor |===

Editing existing '802-11-wireless' connection: 'bevaght'

Type 'help' or '?' for available commands.
Type 'print' to show all the connection properties.
Type 'describe [<setting>.<prop>]' for detailed property description.

You may edit the following settings: connection, 802-11-wireless (wifi), 802-11-wireless-security (wifi-sec), 802-1x, ethtool, match, ipv4, ipv6, tc, proxy
nmcli> set ipv4.route-metric 10
nmcli> save
nmcli> quit

Edit the ethernet connection

[m.emami@home ~]$ nmcli connection edit eth1

===| nmcli interactive connection editor |===

Editing existing '802-3-ethernet' connection: 'eth1'

Type 'help' or '?' for available commands.
Type 'print' to show all the connection properties.
Type 'describe [<setting>.<prop>]' for detailed property description.

You may edit the following settings: connection, 802-3-ethernet (ethernet), 802-1x, dcb, sriov, ethtool, match, ipv4, ipv6, tc, proxy
nmcli> set ipv4.route-metric 2000
nmcli> save
nmcli> quit

Restart NetworkManager service

[m.emami@home ~]$ sudo systemctl restart NetworkManager

Congratulation! routes related to the WiFi connection (named bevaght) are prior to routes related to the Ethernet connection (named eth1)

[m.emami@home ~]$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.0.1     0.0.0.0         UG    10     0        0 wlp0s20f0u11
0.0.0.0         192.168.1.1     0.0.0.0         UG    2000   0        0 enp2s0

Discussion

pic
Editor guide