KVM forward ports to guests VM with UFW on Linux


#1

Originally published at: https://www.cyberciti.biz/faq/kvm-forward-ports-to-guests-vm-with-ufw-on-linux/

My Debian/Ubuntu/CentOS Linux server using KVM as a hypervisor. I would like to forward ports to guests VM with UFW iptables. How do I forward ports on a Linux server running libvirt/KVM to specified ports on VM’s, when using NAT?


#2

Thanks Vivek for again one interesting post.

One remark: it might be of interest to explain the role of the subnet 192.168.2.0/24, which is not shown in the schema.
As I understand it, it is the sole subnet on the “internet” from which the port forwarding will be activated, as the forward rule added in the first part is limited to the “source” (-s) 192.168.2.0/24
To activate it for any external address, the -s parameter should be either absent or 0.0.0.0/0

Also, I’d like to point that the hook could be located in /etc/libvirt/hooks/network so that it doesn’t get executed everytime a machine is started but only at start of the network.

Thanks again for all your tutorials.


#3

yes, I would update page soon with newer hook info. Thanks!