Andre
Andre

Reputation: 790

Port forwarding to virtual machine qemu

I recently installed a Virtual Machine under Ubuntu 11.10, Right now, I assume, it is using NAT and its internal address is 192.168.122.88.

I have setup a web server in my virtual machine and I want to be able to access it when I go to 192.168.122.88 . However, right now it times out. When I log in to the virtual machine and try to access localhost it works.

So, for some reason, my iptables is blocking traffic from the host to the virtual machine (But not the other way around).

How can I allow traffic to flow from my host to my vm so I can see the webserver from the host?

I used Ubuntu Virtual Machine Manager w/KVM and libvirt.

I tried doing someting like this

iptables -t nat -A PREROUTING -d 192.168.0.10 -p tcp --dport 80 -j DNAT --to-destination 192.168.122.88:80

with no avail. Apparently it says there is no route to host??

Upvotes: 2

Views: 7246

Answers (2)

Francesc Guasch
Francesc Guasch

Reputation: 317

Maybe you need to allow forwarded connections to the virtual machines. Try this:

iptables -I FORWARD -m state -d 192.168.122.0/24 --state NEW,RELATED,ESTABLISHED -j ACCEPT

Hope this helps.

Upvotes: 1

FarDarkMist
FarDarkMist

Reputation: 408

'No route to host' means that the host machine doesn't have a IP address that can match the net you are trying to reach (you even don't have a default route), assure you have both nets on the host.

For example:

$ ip route show  
default via 192.168.1.254 dev p3p1  src 192.168.1.103  
default via 172.16.128.1 dev p3p1  
169.254.0.0/16 dev p3p1  scope link  metric 1003  
172.16.128.0/17 dev p3p1  proto kernel  scope link  src 172.16.128.2  
192.168.1.0/24 dev p3p1  proto kernel  scope link  src 192.168.1.103

On KVM host machines, I attach the virtual interfaces to some bridge. For example:

<interface type='bridge'>     
  <mac address='01:02:03:04:05:06'/>       
  <source bridge='br4'/>    
  <target dev='vnet4'/>    
  <model type='virtio'/>    
  <alias name='net0'/>    
  <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>    
</interface>

Then, I assign an IP address to the bridge on the host, and set it on up:

ip address add 192.168.0.1/24 dev br4    
ip link set up dev br4

On my virtual machine, I assign some IP address on the subnet like 192.168.0.2, then the ping should be successful between them.

ping 192.168.0.1

Upvotes: 1

Related Questions