Netplan - 添加辅助 IP 地址并分配标签

Netplan - 添加辅助 IP 地址并分配标签

我在这里看到了同样的问题,但我再也找不到了。如何通过 netplan 添加辅助 IP 地址并为其分配标签?

我有这个 netplan 配置:

# This is the network config written by 'subiquity'
network:
  ethernets:
    eth0:
      dhcp4: false
      addresses:
      - 12.34.56.78/24
      - 98.76.54.32/24
      nameservers:
        addresses:
        - 8.8.8.8
        - 8.8.4.4
        search: []
      routes:
        - to: 0.0.0.0/0
          via: 12.34.56.1
  version: 2

ifconfig:

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 12.34.56.78  netmask 255.255.255.0  broadcast 12.34.56.255
        inet6 fe80::a00:27ff:fede:7ecc  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:de:7e:cc  txqueuelen 1000  (Ethernet)
        RX packets 1656148  bytes 121855580 (121.8 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5300728  bytes 7534018953 (7.5 GB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 1342850  bytes 259593981 (259.5 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1342850  bytes 259593981 (259.5 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

我设法通过以下方式添加辅助 IP 地址并为其分配标签ip addrip addr add 98.76.54.32/24 dev eth0 label eth0:1我得到了以下信息:

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 12.34.56.78  netmask 255.255.255.0  broadcast 12.34.56.255
        inet6 fe80::a00:27ff:fede:7ecc  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:de:7e:cc  txqueuelen 1000  (Ethernet)
        RX packets 1656148  bytes 121855580 (121.8 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5300728  bytes 7534018953 (7.5 GB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 98.76.54.32  netmask 255.255.255.0  broadcast 0.0.0.0
        ether 08:00:27:de:7e:cc  txqueuelen 1000  (Ethernet)

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 1342850  bytes 259593981 (259.5 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1342850  bytes 259593981 (259.5 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

但是如何通过 netplan 来实现呢?

答案1

尝试这个

  network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: false
      addresses:
        - 12.34.56.78/24
      labels:
        eth0:0:
          addresses:
            - 98.76.54.32/24

相关内容