×

You can configure either dynamically or statically provisioned IP addresses for virtual machines.

Prerequisites
  • The virtual machine must connect to an external network.

  • You must have a DHCP server available on the additional network to configure a dynamic IP for the virtual machine.

Configuring an IP address for a new virtual machine using cloud-init

You can use cloud-init to configure an IP address when you create a virtual machine. The IP address can be dynamically or statically provisioned.

Procedure
  • Create a virtual machine configuration and include the cloud-init network details in the spec.volumes.cloudInitNoCloud.networkData field of the virtual machine configuration:

    1. To configure a dynamic IP, specify the interface name and the dhcp4 boolean:

      kind: VirtualMachine
      spec:
      ...
        volumes:
        - cloudInitNoCloud:
            networkData: |
              version: 2
              ethernets:
                eth1: (1)
                  dhcp4: true (2)
      1 The interface name.
      2 Uses DHCP to provision an IPv4 address.
    2. To configure a static IP, specify the interface name and the IP address:

      kind: VirtualMachine
      spec:
      ...
        volumes:
        - cloudInitNoCloud:
            networkData: |
              version: 2
              ethernets:
                eth1: (1)
                  addresses:
                  - 10.10.10.14/24 (2)
      1 The interface name.
      2 The static IP address for the virtual machine.