KVM forward ports to guests VM with UFW on Linux
To forward ports to guests VM with KVM on a Linux machine using UFW (Uncomplicated Firewall), you can use the following steps:
- Enable UFW on the host machine by running the command:
sudo ufw enable - Allow incoming traffic on the desired ports by running the command:
sudo ufw allow - Configure the virtual network in the KVM settings to use NAT mode. This can be done by editing the XML configuration file for the virtual machine, or by using a GUI tool such as virt-manager.
- Create a new rule in UFW to forward traffic from the host's network interface to the guest's IP address on the desired port. You can use the following command:
sudo ufw route allow from any to portFor example, to forward incoming TCP traffic on port 80 to a guest with IP address 10.0.0.100, you would use the command:
sudo ufw route allow tcp from any to 10.0.0.100 port 80- Finally, reload UFW to apply the changes:
sudo ufw reload
