Page 1 of 1

Port forwarding port 80 to virtual host

Posted: 12. Jul 2012, 13:48
by hergel
Hi,

I have the following set up:
1 host machine with Debian Gnu/linux that are running a virtual machine with debian linux.
The virtual machine is hosting a web server on port 80 and is set to HostOnly
The host machine is not running and web server and I want to port forward port 80 on host to virtual machine.
In other words, when I type the IP address of my host on the network, I will be redirected to the virtual machines web server.
How do I do this using iptables ?


host ifconfig:
eth0 Link encap:Ethernet HWaddr 00:26:18:37:39:d9
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Interrupt:18
# eth is where I get my internet connection
eth1 Link encap:Ethernet HWaddr 00:26:18:37:3f:a5
inet addr:10.0.0.15 Bcast:10.0.0.255 Mask:255.255.255.0
inet6 addr: fe80::226:18ff:fe37:3fa5/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:703884 errors:0 dropped:0 overruns:0 frame:0
TX packets:409460 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:998863176 (952.5 MiB) TX bytes:35456137 (33.8 MiB)
Interrupt:17

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:1044 errors:0 dropped:0 overruns:0 frame:0
TX packets:1044 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:89366 (87.2 KiB) TX bytes:89366 (87.2 KiB)

vboxnet0 Link encap:Ethernet HWaddr 0a:00:27:00:00:00
inet addr:192.168.56.1 Bcast:192.168.56.255 Mask:255.255.255.0
inet6 addr: fe80::800:27ff:fe00:0/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:140 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:18035 (17.6 KiB)

Virtual machine ifconfig:

eth0 Link encap:Ethernet HWaddr 08:00:27:02:cc:54
inet addr:192.168.56.2 Bcast:192.168.56.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe02:cc54/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:105 errors:0 dropped:0 overruns:0 frame:0
TX packets:90 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:14575 (14.2 KiB) TX bytes:16144 (15.7 KiB)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:560 (560.0 B) TX bytes:560 (560.0 B)

Re: Port forwarding port 80 to virtual host

Posted: 12. Jul 2012, 14:50
by Perryg
Host-only is the key here that should tell you there will be no communication with the LAN from the guest.
First you can not forward privileged ports (ports <= 1000) in Linux as a normal user.
Given what you are wanting to do I would suggest using VBox NAT and port forwarding, or bridged and the guest will appear as another PC on the LAN.
See Chapter 6 in your VirtualBox users manual.

Re: Port forwarding port 80 to virtual host

Posted: 18. Jul 2012, 11:10
by omikron
Omg I wrote huge tutorial how to do this. And then when I was postin forums informed "You must be a member for 1 days and have 1 post before you can post addresses).. I didn't even have real addresses, just examples with dot separating two words and it didn't allow me to post them. Damn you Forum Admins! (LOL, even word U R L is forbidden for newcomers)

But short story to do this which may not help you if you don't understand.
1) Install and configure your web VM server normally with all stuff like apache, mysql, php, if you are working with those
2) put your site under Apache DocumentRoot folder, it can be under subfolder, lets call it yoursite-folder.
3) Install on your HOST-server Apache to control your proxying.
4) Activate on your host server proxy mod
5) Use Apache's ProxyPass command pass data to your VM. Set your virtualhost site file and give (where is your ServerName and ServerAlias etc... and add line: ProxyPass / address_to_your_vm_server/yoursite

added: btw.. and just port forward your router 80 to your HOST server and let it do the rest