在Linux系统中,双网卡或多网卡上网并不会同时使用两者同时上网,只会优先把请求发送到优先级高的默认网关(对应网卡的内网网段除外)。插入多个网卡的时候,路由表中就会存在多个默认网关,访问外部网络的时候,系统根据路由原则,Metric
值小的网卡优先级高,会优先使用该网卡上网。
Linux网卡优先级配置
使用route
命令查看路由表相关信息:
$ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default oraybox.com 0.0.0.0 UG 100 0 0 enx00e04c6801a0
default _gateway 0.0.0.0 UG 101 0 0 eth0
10.10.11.0 0.0.0.0 255.255.255.0 U 101 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 100 0 0 enx00e04c6801a0
使用route -n
可以查看Gateway相关IP信息:
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.8 0.0.0.0 UG