使用 VLAN 和 Bridge-Utils 将 ifupdown 转换为 Netplan

使用 VLAN 和 Bridge-Utils 将 ifupdown 转换为 Netplan

我需要将我们使用的 ifupdown 设置转换apt-get vlan and bridge-utils为 Netplan,但无法使用 Netplan 获得相同的设置。以下是/etc/network/interfaces需要转换的当前配置:

# The loopback network interface
auto lo
iface lo inet loopback

# Mainframe network interface
auto standard
iface standard inet static
        address 172.16.0.6
        netmask 255.255.254.0
        network 172.16.0.0
        broadcast 172.16.1.255
        dns-nameservers 10.0.0.244
        dns-search example.com
        bridge_ports eno1
        post-up route add default gw 172.16.0.1
        pre-down route del default

# Printers network interface
auto vlan5
iface vlan5 inet manual
        address 0.0.0.0
        vlan-raw-device eno1
auto printers
        iface printers  inet manual
        address 0.0.0.0
        bridge_ports vlan5

# Game network interface
auto vlan4
iface vlan4 inet manual
       address 0.0.0.0
       vlan-raw-device eno1
auto gaming
        iface gaming inet manual
        address 0.0.0.0
        bridge_ports vlan4

答案1

我相信此配置符合文件的意图/etc/network/interfaces。它与屏幕截图中显示的 VLAN 接口名称不匹配;不清楚为什么屏幕截图中的 VLAN 名为“vlan2”和“vlan3”,而 e/n/i 中名为“vlan4”和“vlan5”。

network:
    version: 2
    renderer: networkd
    ethernets:
         eno1:
            dhcp4: no
    bridges:
        # standard network 
        standard:
            interfaces: [eno1]
            addresses: [172.16.0.6/23]
            gateway4: 172.16.0.1
            nameservers:
                search: [example.com]
                addresses: [10.0.0.244]
        printers:
            interfaces: [vlan5]
        gaming:
            interfaces: [vlan4]
    vlans:
        vlan5:
            id: 5
            link: eno1
        vlan4:
            id: 4
            link: eno1

您应该仔细检查现有接口上的 VLAN ID ip -d link show vlan2 | grep 'vlan protocol'(对于 VLAN3 也是如此),然后调整id上述值以匹配每个接口的要求。

答案2

在 Ubuntu 18.04 中,目前在 Netplan 中创建匿名(无 IP)桥接时存在错误。您必须/etc/systemd/network/br{#}.network为每个桥接创建文件,例如:

[Match]
Name=gaming

[Network]
LinkLocalAddressing=no
IPv6AcceptRA=no

接下来,创建一个 netplan 文件,例如/etc/netplan/50-cloud-init.yaml,包含以下内容:

network:
    version: 2
    renderer: networkd
    ethernets:
         eno1:
                 dhcp4: no
                 dhcp6: no
    bridges:
        # standard network 
        standard:
                addresses:
                       - 172.16.0.6/23
                gateway4: 172.16.0.1
                routes:
                        - to: 0.0.0.0/0
                          via: 172.16.0.1
                nameservers:
                        search: [ example.com ]
                        addresses:
                                - 10.0.0.244
                interfaces: [ eno1 ]
        # gaming network
        gaming:
                interfaces: [ vlan4 ]
        # printers network
        printers:
                interfaces: [ vlan5 ]
    vlans:
        vlan4:
                id: 4
                link: eno1
        vlan5:
                id: 5
                link: eno1                                      

最后运行netplan apply

相关内容