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. View the IP address of a VM by using the OpenShift Container Platform web console or the command line. The network information is collected by the QEMU guest agent.
Configuring a static IP address when creating a virtual machine by using the web console
You can configure a static IP address when you create a virtual machine (VM) by using the web console. 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.
Procedure
- Navigate to Virtualization → Catalog in the web console.
- Click a template tile.
- Click Customize VirtualMachine.
- Click Next.
- On the Scripts tab, click the edit icon beside Cloud-init.
- Select the Add network data checkbox.
- Enter the ethernet name, one or more IP addresses separated by commas, and the gateway address.
- Click Apply.
- Click Create VirtualMachine.
Configuring an IP address when creating a virtual machine by using the CLI
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.networkDatastanza of the virtual machine configuration:- To configure a dynamic IP address, specify the interface name and enable DHCP:
apiVersion: kubevirt.io/v1kind: VirtualMachinemetadata:name: <interface_name>kind: VirtualMachinespec:# ...template:# ...spec:volumes:- cloudInitNoCloud:networkData: |version: 2ethernets:eth1:dhcp4: true# ...
- To configure a static IP, specify the interface name and the IP address:
apiVersion: kubevirt.io/v1kind: VirtualMachinemetadata:name: <interface_name>kind: VirtualMachinespec:# ...template:# ...spec:volumes:- cloudInitNoCloud:networkData: |version: 2ethernets:eth1:addresses:- 10.10.10.14/24# ...
- To configure a dynamic IP address, specify the interface name and enable DHCP:
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 OpenShift Container Platform 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
- In the OpenShift Container Platform console, click Virtualization → VirtualMachines from the side menu.
- Select a VM to open the VirtualMachine details page.
- Click the Details tab to view the IP address.
Viewing the IP address of a virtual machine by using the CLI
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.
Prerequisites
- You have installed the OpenShift CLI (
oc).
Procedure
-
Obtain the virtual machine instance configuration by running the following command:
$ oc describe vmi <vmi_name>Example output:
# ...Interfaces:Interface Name: eth0Ip Address: 10.244.0.37/24Ip Addresses:10.244.0.37/24fe80::858:aff:fef4:25/64Mac: 0a:58:0a:f4:00:25Name: defaultInterface Name: v2Ip Address: 1.1.1.7/24Ip Addresses:1.1.1.7/24fe80::f4d9:70ff:fe13:9089/64Mac: f6:d9:70:13:90:89Interface Name: v1Ip Address: 1.1.1.1/24Ip Addresses:1.1.1.1/241.1.1.2/241.1.1.4/242001:de7:0:f101::1/642001:db8:0:f101::1/64fe80::1420:84ff:fe10:17aa/64Mac: 16:20:84:10:17:aa
Additional resources