3

I followed this tutorial to install a KVM virtual machine on my ubuntu server. Now i need to bind a port from the guest to the host. I tried several tutorial to bind the port, but nothing worked.

My setup is:


Host: Ubuntu 14.04, IP: 192.168.122.1 (KVM IP), IP where i can reach the host: 10.211.55.4

eth1      Link encap:Ethernet  HWaddr 00:1c:42:d0:7a:75  
      inet addr:10.211.55.4  Bcast:10.211.55.255  Mask:255.255.255.0
      inet6 addr: fe80::21c:42ff:fed0:7a75/64 Scope:Link
      inet6 addr: fdb2:2c26:f4e4:0:21c:42ff:fed0:7a75/64 Scope:Global
      inet6 addr: fdb2:2c26:f4e4:0:19bb:354a:25f2:6d0f/64 Scope:Global
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:701 errors:0 dropped:0 overruns:0 frame:0
      TX packets:218 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000 
      RX bytes:110682 (110.6 KB)  TX bytes:28366 (28.3 KB)

virbr0    Link encap:Ethernet  HWaddr fe:54:00:9e:7b:58  
      inet addr:192.168.122.1  Bcast:192.168.122.255  Mask:255.255.255.0
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:131 errors:0 dropped:0 overruns:0 frame:0
      TX packets:112 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:0 
      RX bytes:15021 (15.0 KB)  TX bytes:11985 (11.9 KB)

Guest: Ubuntu 14.04, IP: 192.168.122.141

eth0      Link encap:Ethernet  HWaddr 52:54:00:9e:7b:58  
      inet addr:192.168.122.141  Bcast:192.168.122.255  Mask:255.255.255.0
      inet6 addr: fe80::5054:ff:fe9e:7b58/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:404 errors:0 dropped:3 overruns:0 frame:0
      TX packets:186 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000 
      RX bytes:33867 (33.8 KB)  TX bytes:24842 (24.8 KB)

Can anybody help me to bind e.g. port 80 from the guest to the host, so i can get the web server from the guest with http://10.211.55.4?

Thanks so much in advance!

Matthias
  • 31
  • 3
  • Why don't you use 192.168.122.141? And, you have IPv6 addresses on the host, so why did you disable it on the guest? – Michael Hampton Nov 14 '15 at 21:40
  • I cannot use 192.168.122.141, because i want to access the guest machine from an external computer through the host, lets say from a computer with the IP 10.211.55.3. Maybe that was not clear in my question, sorry! I didn't disable it active, maybe this is the default setting. – Matthias Nov 21 '15 at 08:55
  • 1
    I suggest you bridge the VM to your external network. – Michael Hampton Nov 21 '15 at 09:13
  • Ok, i think i will try it to bridge the VM then. Thanks! – Matthias Nov 22 '15 at 11:52

1 Answers1

1

Either you bridge the VM iface to the "external" network, or you set up iptables and create a DNAt entry for the ports needed.

Xavy
  • 159
  • 3
  • > "or you set up iptables and create a DNAt entry for the ports needed." Can you show me how the command should look like to create the iptables entry? – Matthias Jan 15 '16 at 10:32
  • Something like: iptables -t nat -A PREROUTING -d 10.211.55.4/32 -i eth1 -p tcp --dport 80 -j DNAT --to-destination 192.168.122.141. If this did not work probably you should use tcpdump to check if any routing extra setting might be needed – Xavy Jan 15 '16 at 10:40