KVM forward ports to guests VM with UFW on Linux

‮al.www‬utturi.com
KVM forward ports to guests VM with UFW on Linux

To forward ports to guests VM with KVM and UFW on a Linux host, you can use the following steps:

  1. Make sure that the KVM virtualization is installed and enabled on your Linux host.

  2. Install the UFW firewall on your host by running the following command:

sudo apt-get install ufw
  1. Enable the UFW firewall by running the following command:
sudo ufw enable
  1. Start the guest VM that you want to forward the ports to.

  2. Find the IP address of the guest VM by running the following command:

sudo virsh domifaddr <guest-vm-name>

Replace <guest-vm-name> with the name of your guest VM.

  1. Forward the desired ports from the host to the guest VM by running the following command:
sudo ufw allow proto tcp to any port <host-port> to <guest-vm-ip> port <guest-vm-port>

Replace <host-port> with the port number on the host, <guest-vm-ip> with the IP address of the guest VM, and <guest-vm-port> with the port number on the guest VM.

For example, to forward port 8080 on the host to port 80 on the guest VM, you would run the following command:

sudo ufw allow proto tcp to any port 8080 to 192.168.122.50 port 80
  1. Verify that the port forwarding rule has been added by running the following command:
sudo ufw status

You should see the port forwarding rule listed in the output.

  1. Test the port forwarding by trying to access the guest VM from the host using the forwarded port. For example, you can use a web browser to visit http://localhost:8080 to access the web server on the guest VM.
Created Time:2017-10-29 22:08:50  Author:lautturi