KVM: Passing a port from your public NATd IP to an internal VM host

If you're using KVM's "default" network to provide NAT to your VMs you may want to map certain inbound ports to a specific VM. Using these iptables commands and destination NAT you will be able to connect to your VMs using a single outward facing IP.

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -t nat -A PREROUTING -p tcp --dport 2222 -j DNAT --to 192.168.122.32:22


Note: Replies will be formatted with PHP Markdown Extra syntax.

Name: Email (Not Required):
 
Logged IP: 3.84.228.68
To prevent spam please submit by clicking the kitten: