为什么我的 VLan 具有与 netplan 的底层物理连接相同的 IP 地址?

为什么我的 VLan 具有与 netplan 的底层物理连接相同的 IP 地址?

我正在尝试使用 netplan 在我的计算机上配置 vlan。

在我的路由器(Synology SRM)上我定义了两个网络。

Primary Network
Subnet: 192.168.200.1/24
Gateway: 192.168.200.1
Primary DNS: 192.168.200.5
DHCP v4: Enabled
DHCP Start: 192.168.200.154
DHCP End: 192.168.200.254
VLAN ID: Not set / doesn't show the field in the UI.

Network 2
Subnet: 192.168.60.1/24
Gateway: 192.168.60.1
Primary DNS: 192.168.60.1
DHCP v4: Enabled
DHCP Start: 192.168.60.2
DHCP End: 192.168.60.254
VLAN ID: 60

我的主机正在运行带有 Netplan 0.99 的 Ubuntu 18.04。

我的 /etc/netplan/50-cloud-init.yaml 看起来像这样

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      match:
        macaddress: 48:b0:2d:2e:63:b8
      critical: yes
      addresses: [192.168.200.202/24 ]
      nameservers:
        addresses: [192.168.200.5]
      routes:
      - to: 0.0.0.0/0
        via: 192.168.200.1
      mtu: 1500
  vlans:
    vlan60:
      id: 60
      link: eth0
      addresses:
      - 192.168.60.20/24
      nameservers:
        addresses: [192.168.60.1]
      mtu: 1500

输出ip a如下:

greg@jetson01:~$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    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: dummy0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 56:94:93:66:7b:09 brd ff:ff:ff:ff:ff:ff
3: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 48:b0:2d:2e:63:b8 brd ff:ff:ff:ff:ff:ff
    inet 192.168.200.202/24 brd 192.168.200.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::4ab0:2dff:fe2e:63b8/64 scope link
       valid_lft forever preferred_lft forever
4: l4tbr0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether f2:54:e5:8e:23:d1 brd ff:ff:ff:ff:ff:ff
5: rndis0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast master l4tbr0 state DOWN group default qlen 1000
    link/ether f2:54:e5:8e:23:d1 brd ff:ff:ff:ff:ff:ff
6: usb0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast master l4tbr0 state DOWN group default qlen 1000
    link/ether f2:54:e5:8e:23:d3 brd ff:ff:ff:ff:ff:ff
7: vlan60@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 48:b0:2d:2e:63:b8 brd ff:ff:ff:ff:ff:ff
    inet 192.168.200.202/24 brd 192.168.200.255 scope global vlan60
       valid_lft forever preferred_lft forever
    inet6 fe80::4ab0:2dff:fe2e:63b8/64 scope link
       valid_lft forever preferred_lft forever
8: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
    link/ether 02:42:8e:c3:11:42 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever

如果您查看该列表中的第 7 位,vlan60@eth0则其inet 192.168.200.202/24与第 3 位相同eth0

为什么我的vlan60@eth0接口与底层接口具有相同的 IP 地址eth0

答案1

问题在于 Ubuntu 18.04 上的 netplan.io 有一个错误,它会意外地将 eth0 应用于 vlan60@eth0。幸运的是,有一个简单的修复方法。使用以下命令匹配以太网接口name: eth0

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      match:
        name: eth0 # Work around for eth0's IP overwriting vlan60's IP
        macaddress: 48:b0:2d:2e:63:b8
      critical: yes
      addresses: [192.168.200.202/24 ]
      nameservers:
        addresses: [192.168.200.5]
      routes:
      - to: 0.0.0.0/0
        via: 192.168.200.1
      mtu: 1500
  vlans:
    vlan60:
      id: 60
      link: eth0
      addresses:
      - 192.168.60.20/24
      nameservers:
        addresses: [192.168.60.1]
      mtu: 1500

Ubuntu 20.04 上的 netplan.io 已修复此问题,可以正确生成包含关键行的部分/run/systemd/network/10-netplan-eth0.*。我上面的解决方案模拟了相同的效果。[Match]Type=!vlan bond bridgeOriginalName=enp1s0

相关内容