Port forwarding port 80 to virtual host
Posted: 12. Jul 2012, 13:48
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
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
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
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)
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
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
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
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)