ubuntu 22.04 使用 netplan 进行路由

ubuntu 22.04 使用 netplan 进行路由

你好,我有一个新的 ubuntu 服务器,有 2 个接口,我为它编写了一个 netpaln 配置,如下所示:

network:
 version: 2
 renderer: networkd
 ethernets:
   ens160:
     dhcp4: no
     addresses:
       - 192.168.1.2/24
     routing-policy:
       - from: 192.168.1.0/24
         table: 160
     routes:
       - to:  0.0.0.0/0
         via: 192.168.1.1
       - to: 172.10.10.10
         via: 192.168.1.1
         on-link: true
         metric: 100
         table: 160
     nameservers:
       addresses:
         - 8.8.8.8
         - 4.2.2.4
     accept-ra: no
   ens192:
     dhcp4: no
     addresses:
       - 172.31.99.2/24
     routing-policy:
       - from: 172.31.99.0/24
         table: 192
     routes:
       # - to:  0.0.0.0/0
       #  via: 172.31.99.1
       - to:  172.22.22.22
         via: 172.31.99.1
         on-link: true
         metric: 100
         table: 192
     accept-ra: no 

我有两个问题:

  1. 如果我取消注释 ens192 的默认网关,我会收到以下警告:
** (generate:2260): WARNING **: 20:34:27.603: Problem encountered while validating default route consistency.Please set up multiple routing tables and use `routing-policy` instead.
Error: Conflicting default route declarations for IPv4 (table: main, metric: default), first declared in ens192 but also in ens160

** (process:2258): WARNING **: 20:34:28.411: Problem encountered while validating default route consistency.Please set up multiple routing tables and use `routing-policy` instead.
Error: Conflicting default route declarations for IPv4 (table: main, metric: default), first declared in ens192 but also in ens160

** (process:2258): WARNING **: 20:34:28.427: Problem encountered while validating default route consistency.Please set up multiple routing tables and use `routing-policy` instead.
Error: Conflicting default route declarations for IPv4 (table: main, metric: default), first declared in ens192 but also in ens160

** (process:2258): WARNING **: 20:34:28.970: Problem encountered while validating default route consistency.Please set up multiple routing tables and use `routing-policy` instead.
Error: Conflicting default route declarations for IPv4 (table: main, metric: default), first declared in ens192 but also in ens160

** (process:2258): WARNING **: 20:34:28.971: Problem encountered while validating default route consistency.Please set up multiple routing tables and use `routing-policy` instead.
Error: Conflicting default route declarations for IPv4 (table: main, metric: default), first declared in ens192 but also in ens160

为什么会发生这种情况?第二个问题:如果我想 ping 路由表 160 或 192 上的目的地,则不会传输任何数据包:

ping 172.20.20.20
4 packets transmitted, 0 received, 100% packet loss
ping 172.20.20.20 -I ens192
4 packets transmitted, 0 received, 100% packet loss

有什么解决办法?谢谢您的关注。

答案1

你每个接口上的默认路由也需要指定该表。

在您的示例中,您正在 ping 一个当前在 ens192 上没有路由的 IP。

相关内容