Wednesday, January 22, 2020

Prioritization of network interfaces

If we have more than one network interfaces and want to prioritize routing via one of them we can do the following:

Check the priorities in the routing table:

/home/nickapos [nickapos@nickapos-ThinkPad-P52] [8:44]
> ip route                    
default via 192.168.17.1 dev enp0s31f6 proto dhcp metric 100
default via 192.168.1.254 dev wlp0s20f3 proto dhcp metric 600



Here we can see that we have two interfaces with different metric values enp0s31f6 has higher priority than wlp0s20f3, if we want to swap them we need to install ifmetric with
sudo apt install ifmetric 
and do:

sudo ifmetric wlp0s20f3 99

After this if we check the routing table:

/home/nickapos [nickapos@nickapos-ThinkPad-P52] [8:45]
> ip route                 
default via 192.168.1.254 dev wlp0s20f3 proto dhcp metric 99
default via 192.168.17.1 dev enp0s31f6 proto dhcp metric 100




we can see that wlp0s20f3 has higher priority so routing will happen by default through it. Only packages that can not be served by it will be routed via enp0s31f6,