Ping and Connect to KVM Virtual Machines on M1 and M2
In this article, we will discuss how to ping and connect to KVM virtual machines on two machines, M1 and M2, where M2 has a virtual machine (VM) installed using virt-install. Both M1 and M2 will be able to ping the IP address of the VM on M2.
Installing KVM on M1 and M2
Before we begin, we need to ensure that KVM is installed on both M1 and M2. To do this, run the following command on both machines:
sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils
Creating a Virtual Machine on M2
Next, we need to create a virtual machine on M2. To do this, run the following command on M2:
sudo virt-install --name=myvm --ram=1024 --disk=path=/var/lib/libvirt/images/myvm.img,size=8 --vnc --os-type=linux --os-variant=ubuntu18.04
This will create a new virtual machine named "myvm" with 1GB of RAM and an 8GB disk image. The virtual machine will use VNC for display and will be based on Ubuntu 18.04.
Pinging the Virtual Machine on M2 from M1
Now that we have a virtual machine on M2, we can ping it from M1. To do this, we need to find the IP address of the virtual machine. We can do this by running the following command on M2:
virsh domiflist myvm
This will display a list of network interfaces for the virtual machine. Look for the interface with the type "ipv4" and note the IP address. Then, on M1, run the following command to ping the virtual machine:
ping
Connecting to the Virtual Machine on M2 from M1
Once we have confirmed that we can ping the virtual machine from M1, we can connect to it. To do this, we need to use a VNC client to connect to the VNC server running on M2. We can do this by running the following command on M1:
vncviewer :
The display number can be found by running the following command on M2:
virsh vncdisplay myvm
This will open a VNC client and connect to the virtual machine's console. We can now use the virtual machine as if it were a physical machine.
- KVM needs to be installed on both M1 and M2.
- A virtual machine can be created on M2 using the
virt-installcommand. - The IP address of the virtual machine can be found using the
virsh domiflistcommand on M2. - The virtual machine can be pinged from M1 using the
pingcommand. - The virtual machine can be connected to from M1 using a VNC client and the
vncviewercommand.