无效的 YAML:缩进不一致:地址:

无效的 YAML:缩进不一致:地址:

在我的主机 Ubuntu 22.04 Desktop 中,我为 eth0-br0 和 eth1-br1 创建了 2 个网桥。br1 需要从主机 192.168.1.120/24 到客户机 192.168.1.1/24 的 LAN 访问。我找不到有关网桥的静态 IP 地址的任何信息,因此我尝试了以下方法:

ubuntu@ubuntu:/etc/netplan$ cat 01-network-manager-all.yaml
# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager
  ethernets:
    enp2s0:
      dhcp4: no
      addresses: [192.168.1.120/24]
      gateway4: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8,8.8.8.4]
    enp3s0:
      dhcp4: no
  bridges:
    br0:
      dhcp4: yes
      interfaces:
        - enp3s0
    br1:
      dhcp4: no
        addresses: [192.168.1.120/24]
        gateway4: 192.168.1.1
        nameservers:
          addresses: [8.8.8.8,8.8.8.4]
      interfaces:
        - enp2s0

但是运行 netplan 显示错误:

ubuntu@ubuntu:/etc/netplan$ sudo netplan try
/etc/netplan/01-network-manager-all.yaml:21:18: Invalid YAML: inconsistent indentation:
        addresses: [192.168.1.120/24]
                 ^

答案1

这是已修复的 yaml 输出。主要问题是您的 br1 缩进。

#Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager
  ethernets:
    enp2s0:
      dhcp4: no
      addresses: [192.168.1.120/24]
      gateway4: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8,8.8.8.4]
    enp3s0:
      dhcp4: no
  bridges:
    br0:
      dhcp4: yes
      interfaces:
        - enp3s0
    br1:
      dhcp4: no
      addresses: [192.168.1.120/24]
      gateway4: 192.168.1.1
      nameservers:
          addresses: [8.8.8.8,8.8.8.4]
      interfaces:
        - enp2s0

相关内容