在多个网卡上配置默认路由度量

在多个网卡上配置默认路由度量

我的网络设置如下:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 74:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
    inet 10.10.1.201/24 metric 100 brd 10.10.1.255 scope global dynamic enp2s0
       valid_lft 9012sec preferred_lft 9012sec
    inet6 fe80::0000:0000:0000:0000//64 scope link 
       valid_lft forever preferred_lft forever
3: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 74:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
    inet 10.10.1.202/24 metric 100 brd 10.10.1.255 scope global dynamic enp3s0
       valid_lft 9012sec preferred_lft 9012sec
    inet6 fe80::0000:0000:0000:0000/64 scope link 
       valid_lft forever preferred_lft forever

我的 Netplan 如下所示:

# This is the network config written by 'subiquity'
network:
  ethernets:
    enp2s0:
      dhcp4: true
    enp3s0:
      dhcp4: true
  version: 2

我的路线如下:

default via 10.10.1.1 dev enp2s0 proto dhcp src 10.10.1.201 metric 100 
default via 10.10.1.1 dev enp3s0 proto dhcp src 10.10.1.202 metric 100 
10.10.1.0/24 dev enp2s0 proto kernel scope link src 10.10.1.201 metric 100 
10.10.1.0/24 dev enp3s0 proto kernel scope link src 10.10.1.202 metric 100 
10.10.1.1 dev enp2s0 proto dhcp scope link src 10.10.1.201 metric 100 
10.10.1.1 dev enp3s0 proto dhcp scope link src 10.10.1.202 metric 100 

我希望 enp2s0 作为我的默认网卡来访问互联网和家庭网络。

我该在哪里更改它以便即使重新启动或更新后它仍然保留并且不会恢复为默认值。

谢谢

答案1

找到了解决方案:

只需添加到我的 netplan 并应用:

dhcp4-overrides:
    route-metric: 10

这是我更新的 netplan 版本:

# This is the network config written by 'subiquity'
network:
  ethernets:
    enp2s0:
      dhcp4: true
      dhcp4-overrides:
        route-metric: 10
    enp3s0:
      dhcp4: true
      dhcp4-overrides:
        route-metric: 100
  version: 2

**** 值较低的将优先考虑**

现在显示“ip a”命令:

2: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 74:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
    inet 10.10.1.201/24 **metric 10** brd 10.10.1.255 scope global dynamic enp2s0
       valid_lft 10562sec preferred_lft 10562sec
    inet6 fe80::7a8c:b5ff:fe84:58d6/64 scope link 
       valid_lft forever preferred_lft forever
3: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 74:86:e2:2b:28:50 brd ff:ff:ff:ff:ff:ff
    inet 10.10.1.202/24 **metric 100** brd 10.10.1.255 scope global dynamic enp3s0
       valid_lft 10558sec preferred_lft 10558sec
    inet6 fe80::0000:0000:0000:0000/64 scope link 
       valid_lft forever preferred_lft forever

相关内容