Posts

Showing posts from May, 2020

forward port 22 from host ip to nat network KVM guest

Image
In your home lab or in public server it is quite possible that you have only one kvm host ip on eth0 and you dont want or cannot create bridge interface in order to assign public ips to all the guest vm so that you can access them individually from outside host network. In this case you can forward ports to nat network guest ip . Example. KVM host ip is :172.16.0.20 linux guest ip : 192.168.122.10 you have ssh access to host using port 22 i.e. ssh [email protected] now if you want to access guest vm also you can forward a port 2222 to guest vm and you can access as ssh [email protected] -p 2222 we can use iptables rule in order to get this happen . iptables -I FORWARD -o virbr0 -d  192.168.122.10 -p tcp --dport 22 -j ACCEPT iptables -t nat -I PREROUTING -p tcp --dport 2222 -j DNAT --to 192.168.122.10:22 next in extending this if you want to expose 80 of your guest from host ip then do so and add bellow extra rules iptables -I FORWARD -o virbr0 -d  192.168.122.10