Netplan:如何为特定 NIC 赋予特定名称和 IP 地址

Netplan:如何为特定 NIC 赋予特定名称和 IP 地址

好的,设置如下:DHCP 服务器为特定 MAC 地址分配 IP。相关机器有多个 NIC,其接口名为 eth0-5。顺便说一下,只有一个 NIC 连接,即 MAC 地址为 00:30:18:08:03:f5 的 NIC。

Netplan 配置如下:

  ethernets:
    eth0:
      dhcp-identifier: mac
      dhcp4: true
      match:
        macaddress: 00:30:18:08:03:f0
      optional: true
    eth1:
      dhcp-identifier: mac
      dhcp4: true
      match:
        macaddress: 00:30:18:08:03:f1
      optional: true
    eth2:
      dhcp-identifier: mac
      dhcp4: true
      match:
        macaddress: 00:30:18:08:03:f2
      optional: true
    eth3:
      dhcp-identifier: mac
      dhcp4: true
      match:
        macaddress: 00:30:18:08:03:f3
      optional: true
    eth4:
      dhcp-identifier: mac
      dhcp4: true
      match:
        macaddress: 00:30:18:08:03:f4
      optional: true
    eth5:
      dhcp-identifier: mac
      dhcp4: true
      match:
        macaddress: 00:30:18:08:03:f5
      optional: true
  version: 2

但每次启动时,都会有一个不同的接口获取 MAC 和 IP。以下是 ifconfig 显示的内容:

eth0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 00:30:18:08:03:f0  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device memory 0xdf160000-df17ffff

eth1: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 00:30:18:08:03:f1  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device memory 0xdf140000-df15ffff

eth2: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 00:30:18:08:03:f2  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device memory 0xdf120000-df13ffff

eth3: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 00:30:18:08:03:f3  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device memory 0xdf100000-df11ffff

eth4: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.2.1.40  netmask 255.255.255.0  broadcast 10.2.1.255
        ether 00:30:18:08:03:f5  txqueuelen 1000  (Ethernet)
        RX packets 220  bytes 21996 (21.9 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 178  bytes 28347 (28.3 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 16  memory 0xdf200000-df220000

eth5: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 00:30:18:08:03:f4  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device memory 0xdf000000-df01ffff

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 2868  bytes 204492 (204.4 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2868  bytes 204492 (204.4 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

请告诉我如何将 eth5 设置为 MAC 为 00:30:18:08:03:f5 且分配 IP 的接口。提前致谢

相关内容