hostnamectl; # tested on
Static hostname: workstation
Operating System: Debian GNU/Linux 13 (trixie) 
Kernel: Linux 6.12.30-amd64
Architecture: x86-64

# theoretical lowest possible value 0 (highest priority) and highest possible value 4294967295 (hex 0xffffffff, guint32 (unsigned 32-bit integer, lowest priority) for route metric

nmcli connection show
NAME              UUID                                  TYPE      DEVICE          
enp4s0            a126beef-91ee-47f5-aa48-xxxxxxxxxxxx  ethernet  enp6s0 <- the LAN connection
AndroidHotSpot    55a62192-5394-4b70-97bf-xxxxxxxxxxxx  wifi      wlx08beac29f632 <- EDIMAX the only USB WIFI dongle that works out of the box on 99% of all GNU Linux
lo                7db0dbdd-1e5b-4a5a-b8c9-xxxxxxxxxxxx  loopback  lo              
virbr0            d7ec5235-3cb9-472d-bc31-xxxxxxxxxxxx  bridge    virbr0 <- from kvm virtualization
vnet0             1d784698-2fed-4142-bf2f-xxxxxxxxxxxx  tun       vnet0           
vnet6             28c1cb32-755e-4c95-8d7d-xxxxxxxxxxxx  tun       vnet6           

# theoretically this should work, it gives no error
# but it also does not change anything (metric = priority stays the same = does not work)
nmcli connection modify AndroidHotSpot ipv4.route-metric 50; # the lower the value the higher the priority

route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         _gateway        0.0.0.0         UG    100    0        0 enp6s0 <- there are two default routes this one (LAN) has higher priority
default         _gateway        0.0.0.0         UG    800    0        0 wlx08beac29f632 <- this is the WIFI WLAN with higher metric = less prority
10.109.227.0    0.0.0.0         255.255.255.0   U     800    0        0 wlx08beac29f632
192.168.1.0     0.0.0.0         255.255.255.0   U     100    0        0 enp6s0
192.168.15.0    0.0.0.0         255.255.255.0   U     100    0        0 enp6s0

# get to know the ip of the new default router
# check what is the ip of the gateway 
traceroute 1.1.1.1
traceroute to 1.1.1.1 (1.1.1.1), 30 hops max, 60 byte packets
 1  _gateway (10.109.227.53)  5.543 ms  5.513 ms  5.605 ms <- it is this one

# also note that this system will most likely lose internet connection in the process!
ip route del default; # delete the default route (highest in list = highest priority will be deleted first)

route; # route with higher metric via enp6s0 is gone
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         _gateway        0.0.0.0         UG    800    0        0 wlx08beac29f632
10.109.227.0    0.0.0.0         255.255.255.0   U     800    0        0 wlx08beac29f632
192.168.15.0    0.0.0.0         255.255.255.0   U     100    0        0 enp6s0

ip route change default via 10.109.227.53 dev wlx08beac29f632; # complains with = does not work
RTNETLINK answers: No such file or directory 

ip route del default; # repeate until there is no more default route

ip route add default via 10.109.227.53 dev wlx08beac29f632 metric 50; # readds WIFI device as new default route with high priority (low metric value)

route; # this time changing metric worked
# please note that this is only temporarily (does not survive reboot)
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         _gateway        0.0.0.0         UG    50     0        0 wlx08beac29f632
10.109.227.0    0.0.0.0         255.255.255.0   U     800    0        0 wlx08beac29f632
192.168.1.0     0.0.0.0         255.255.255.0   U     100    0        0 enp6s0


liked this article?

  • only together we can create a truly free world
  • plz support dwaves to keep it up & running!
  • (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
  • really really hate advertisement
  • contribute: whenever a solution was found, blog about it for others to find!
  • talk about, recommend & link to this blog and articles
  • thanks to all who contribute!
admin