Configuring IP addresses for virtual machines

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

Prerequisites

  • The virtual machine can connect to a secondary network

  • To configure a dynamic IP for the virtual machine, you must have a DHCP server available on the secondary network.

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:

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

      1. kind: VirtualMachine
      2. spec:
      3. ...
      4. volumes:
      5. - cloudInitNoCloud:
      6. networkData: |
      7. version: 2
      8. ethernets:
      9. eth1: (1)
      10. addresses:
      11. - 10.10.10.14/24 (2)
      1The interface name.
      2The static IP address for the virtual machine.