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 [port_number]
- 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 [protocol] from any to [guest_ip] port [port_number]
For 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
It is important to note that this is a basic example and you may want to adjust the rules depending on your specific use case and security requirements.