如何透過 netplan 在單一介面上的多個 VLAN 上使用 DHCP?

如何透過 netplan 在單一介面上的多個 VLAN 上使用 DHCP?

在我目前的網路拓撲中,我有多個 VLAN - 每個 VLAN 都有自己的路由:

VLAN 10:
  DHCP:    10.0.10.10-10.0.10.255
  Subnet:  255.255.255.0
  Gateway: 10.0.10.1

VLAN 11
  DHCP:    10.0.11.10-10.0.11.255
  Subnet:  255.255.255.0
  Gateway: 10.0.11.1

我自動配置的機器有一個 NIC。這就是為什麼我想避免使用靜態配置,而是依賴 DHCP 來提供「正確」的設定。

我的 yaml 看起來像這樣:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp5s0:
      # Designate the connection as "critical to the system", meaning that special care will be taken by systemd-networkd 
      # to not release the IP from DHCP when it the daemon is restarted.
      critical: yes
      dhcp4: no

  vlans:
    cloud:
      id: 10
      link: enp5s0
      dhcp4: yes
      dhcp4-overrides:
        route-metric: 200

    office:
      id: 11
      link: enp5s0
      dhcp4: yes
      dhcp4-overrides:
        route-metric: 100

問題是它只取得cloudVLAN 的 DHCP 設定,而對 VLAN 不執行任何office操作。我在這裡錯過了什麼嗎?

注意:
這不是重複的在單一介面上具有多個 VLAN 的 netplan - 需要協助

答案1

請記住,您的 DHCP 伺服器不知道您的 VLAN 配置。

它正在取得 enp5s0 MAC 位址的 IP 請求,然後收到另一個請求,很可能與前一個請求相同。查看 DHCP 日誌,應該可以確認這一點。或使用 tcpdump 調試流量。

相關內容