Configuring and viewing IP addresses

You can configure an IP address when you create a virtual machine (VM). The IP address is provisioned with cloud-init.

You can view the IP address of a VM by using the OKD web console or the command line. The network information is collected by the QEMU guest agent.

Configuring IP addresses for virtual machines

You can configure a static IP address when you create a virtual machine (VM) by using the web console or the command line.

You can configure a dynamic IP address when you create a VM by using the command line.

The IP address is provisioned with cloud-init.

Configuring an IP address when creating a virtual machine by using the command line

You can configure a static or dynamic IP address when you create a virtual machine (VM). The IP address is provisioned with cloud-init.

If the VM is connected to the pod network, the pod network interface is the default route unless you update it.

Prerequisites

  • The virtual machine is connected to a secondary network.

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

Procedure

  • Edit the spec.template.spec.volumes.cloudInitNoCloud.networkData stanza of the virtual machine configuration:

    • To configure a dynamic IP address, specify the interface name and enable DHCP:

      1. kind: VirtualMachine
      2. spec:
      3. # ...
      4. template:
      5. # ...
      6. spec:
      7. volumes:
      8. - cloudInitNoCloud:
      9. networkData: |
      10. version: 2
      11. ethernets:
      12. eth1: (1)
      13. dhcp4: true
      1Specify the interface name.
    • To configure a static IP, specify the interface name and the IP address:

      1. kind: VirtualMachine
      2. spec:
      3. # ...
      4. template:
      5. # ...
      6. spec:
      7. volumes:
      8. - cloudInitNoCloud:
      9. networkData: |
      10. version: 2
      11. ethernets:
      12. eth1: (1)
      13. addresses:
      14. - 10.10.10.14/24 (2)
      1Specify the interface name.
      2Specify the static IP address.

Viewing IP addresses of virtual machines

You can view the IP address of a VM by using the OKD web console or the command line.

The network information is collected by the QEMU guest agent.

Viewing the IP address of a virtual machine by using the web console

You can view the IP address of a virtual machine (VM) by using the OKD web console.

You must install the QEMU guest agent on a VM to view the IP address of a secondary network interface. A pod network interface does not require the QEMU guest agent.

Procedure

  1. In the OKD console, click VirtualizationVirtualMachines from the side menu.

  2. Select a VM to open the VirtualMachine details page.

  3. Click the Details tab to view the IP address.

Viewing the IP address of a virtual machine by using the command line

You can view the IP address of a virtual machine (VM) by using the command line.

You must install the QEMU guest agent on a VM to view the IP address of a secondary network interface. A pod network interface does not require the QEMU guest agent.

Procedure

  • Obtain the virtual machine instance configuration by running the following command:

    1. $ oc describe vmi <vmi_name>

    Example output

    1. # ...
    2. Interfaces:
    3. Interface Name: eth0
    4. Ip Address: 10.244.0.37/24
    5. Ip Addresses:
    6. 10.244.0.37/24
    7. fe80::858:aff:fef4:25/64
    8. Mac: 0a:58:0a:f4:00:25
    9. Name: default
    10. Interface Name: v2
    11. Ip Address: 1.1.1.7/24
    12. Ip Addresses:
    13. 1.1.1.7/24
    14. fe80::f4d9:70ff:fe13:9089/64
    15. Mac: f6:d9:70:13:90:89
    16. Interface Name: v1
    17. Ip Address: 1.1.1.1/24
    18. Ip Addresses:
    19. 1.1.1.1/24
    20. 1.1.1.2/24
    21. 1.1.1.4/24
    22. 2001:de7:0:f101::1/64
    23. 2001:db8:0:f101::1/64
    24. fe80::1420:84ff:fe10:17aa/64
    25. Mac: 16:20:84:10:17:aa

Additional resources