Problem background

I recently built multiple subnets for my data center. And I connected two interfaces of a Linux device to two subnets at the same time.


When I run ifconfig, below networks are shown:


Only the Green network has Internet access. The blue network is pure internal network.

However, when I try to access the Internet, it may fail with message: destination host unreachable.

This is so confusing...


Finally when I run ip route list, I found that Blue network has a higher priority. That is the root cause.


To view your current routing table:

ip route list

You need to delete the existing default:

# Caution: This may make you offline.
ip route del default

Then add a new default with lower metric:

sudo ip route add default via dev ens160 proto dhcp metric 102

The result may be like (with ip route list)

default via dev ens160 proto dhcp metric 100
default via dev ens192 proto dhcp metric 101 dev ens160 proto kernel scope link src metric 100 dev ens192 proto kernel scope link src metric 101

Finally, you can ask Linux which interface will be used to send a packet to a specific ip address:

ip route get

Or try Internet connection:


If you have multiple 'default' routes, you can prioritize one by removing and re-adding it with a lower metric.