具有两个物理接口和两个 VLAN 的 netplan 为互联网流量分配了错误的 VLAN

具有两个物理接口和两个 VLAN 的 netplan 为互联网流量分配了错误的 VLAN

我有以下配置:

network:
    version: 2
    renderer: networkd
    ethernets:
            enp2s0:
                    dhcp4: yes
                    dhcp4-overrides:
                            hostname: f42252vm
                    gateway4: 192.168.110.1
                    routes:
                            - to: 192.168.110.0/24
                              via: 192.168.110.1
                              metric: 100
                            - to: 192.168.109.0/24
                              via: 192.168.110.1
                              metric: 100
                            - to: 192.168.111.0/24
                              via: 192.168.110.1
                              metric: 100
                    routing-policy:
                            - from: 192.168.110.8/24
                    dhcp6: yes
                    dhcp6-overrides:
                            hostname: f42252vm
                    wakeonlan: true
            enp3s0:
                    dhcp4: yes
                    dhcp4-overrides:
                            hostname: f42252v8
                            use-routes: false
                    gateway4: 192.168.108.1
                    routes:
                            - to: 0.0.0.0/0
                              via: 192.168.108.1
                              metric: 200
                            - to: 192.168.108.0/24
                              via: 192.168.108.1
                              metric: 200
                    routing-policy:
                            - from: 192.168.108.0/24
                    dhcp6: yes
                    dhcp6-overrides:
                            hostname: f42252v8
                            use-routes: false
    bridges: {}
    vlans:
            enp2s0.110:
                    id: 110
                    link: enp2s0
            enp3s0.108:
                    id: 108
                    link: enp3s0

问题:从“192.168.110.8/24”向互联网发送内容时,会标有 vlan 108 - 这是错误的。但是,当将路由“0.0.0.0/0”添加到接口 enp2s0 时,整个网络都会出现错误,并且 vlan 110 完全被阻止。

我如何为 enp2s0 添加一条到互联网的路由(或某种类型的默认路由),然后它将使用 vlan 110 - 希望如此?

谢谢

问候 Karl-Heinz

答案1

根据您的配置,您尚未在任一 VLAN 上配置任何 IP 地址。因此,它们根本不用于路由流量。您应该从配置中删除它,因为您似乎在交换机上使用带有 VLAN 标记的端口,这些端口在交换机内部处理 VLAN,对主机透明。

此外,您在两个接口上都声明了网关,这几乎总是不正确的。这相当于一条to: 0.0.0.0/0没有路由策略的路由。

此外,我看到您在两个接口上都启用了 dhcp 和静态寻址。有时这可能是正确的,但如果不知道 DHCP 服务器发送了什么信息(特别是在 enp2s0 上,您没有声明)use-routes: false,就不可能知道这与静态声明的网络配置如何交互。

我建议以下配置可能更接近您正在寻找的配置:

network:
    version: 2
    renderer: networkd
    ethernets:
        enp2s0:
                dhcp4: yes
                dhcp4-overrides:
                        hostname: f42252vm
                routes:
                        - to: 0.0.0.0/0
                          via: 192.168.110.1
                          table: 110
                        - to: 192.168.109.0/24
                          via: 192.168.110.1
                        - to: 192.168.111.0/24
                          via: 192.168.110.1
                routing-policy:
                        - from: 192.168.110.8/24
                          table: 110
                        - to: 192.168.109.0/24
                          table: 253
                        - to: 192.168.111.0/24
                          table: 253
                dhcp6: yes
                dhcp6-overrides:
                        hostname: f42252vm
                wakeonlan: true
        enp3s0:
                dhcp4: yes
                dhcp4-overrides:
                        hostname: f42252v8
                        use-routes: false
                routes:
                        - to: 0.0.0.0/0
                          via: 192.168.108.1
                          table: 108
                        - to: 192.168.108.0/24
                          via: 192.168.108.1
                          table: 108
                routing-policy:
                        - from: 192.168.108.0/24
                          table: 108
                dhcp6: yes
                dhcp6-overrides:
                        hostname: f42252v8
                        use-routes: false

我假设您希望到 192.168.109/24 和 192.168.111/24 的流量始终通过 enp2s0 路由,因此table: 253为这些流量分配一个路由策略,这应该会导致对这些子网的请求在路由表中进行处理default(按照/etc/iproute2/rt_tables)。

答案2

我目前已经改为:

network:
    version: 2
    renderer: networkd
    ethernets:
            enp2s0:
                    dhcp4: yes
                    dhcp4-overrides:
                            hostname: f42252vm
                            use-routes: false
                    routes:
                            - to: 0.0.0.0/0
                              via: 192.168.110.1
                              metric: 100
                            - to: 192.168.110.0/24
                              via: 192.168.110.1
                              metric: 100
                            - to: 192.168.109.0/24
                              via: 192.168.109.1
                              metric: 100
                            - to: 192.168.111.0/24
                              via: 192.168.111.1
                              metric: 100
                    routing-policy:
                            - from: 192.168.110.8/24
                    dhcp6: yes
                    dhcp6-overrides:
                            hostname: f42252vm
                            use-routes: false
                    wakeonlan: true
            enp3s0:
                    dhcp4: yes
                    dhcp4-overrides:
                            hostname: f42252v8
                            use-routes: false
                    gateway4: 192.168.108.1
                    routes:
                            - to: 0.0.0.0/0
                              via: 192.168.108.1
                              metric: 200
                            - to: 192.168.108.0/24
                              via: 192.168.108.1
                              metric: 200
                    routing-policy:
                            - from: 192.168.108.0/24
                    dhcp6: yes
                    dhcp6-overrides:
                            hostname: f42252v8
                            use-routes: false
    bridges: {}
    vlans:
            enp2s0.110:
                    id: 110
                    link: enp2s0
            enp3s0.108:
                    id: 108
                    link: enp3s0

这似乎有效。至少它不再在我的路由器上产生任何错误消息。

我将更深入地研究表格设置 - 到目前为止我还不知道,仍然不知道这有什么用。我会查看文档。

感谢帮助。

相关内容