C Board  

Go Back   C Board > General Programming Boards > Networking/Device Communication

Reply
 
LinkBack Thread Tools Display Modes
Old 10-30-2009, 11:50 AM   #1
Super Moderator
 
Join Date: Sep 2001
Posts: 4,680
Using ip tables to forward port to virtual machine

I'm running VirtualBox for a class lab, and VirtualBox on Ubuntu appears to be missing the "Bridge Interface" feature for a network adapter - so the instructions we were given won't work for me, and the TA's don't know much about IP tables, so I'm pretty much on my own to get this working.

I need my virtual server to be accessible from remote servers. My host machine has a publically routable address and can access the virtual machine through the local (and static) address 192.168.100.254, and so I figured I could just forward a port from my host machine to the virtual machine. My host can access the virtual machine through IP address 192.168.100.254, and I want to forward any tcp traffic on port 5345 (chosen at random) to my virtual machine. So I'm trying the following iptables commands on my host. I modified commands explained at Port forwarding for iptables (DMZ), changing just the ports and the address.

Code:
iptables -A PREROUTING -t nat -i eth1 -p tcp --dport 5345 -j DNAT --to 192.168.100.254:80

iptables -A INPUT -p tcp -m state --state NEW --dport 5345 -i eth1 -j ACCEPT
The commands appear to execute successfully, but localhost:5345 and a similar request from a remote machine recieve no response. I haven't done anything else to the default iptables in Ubuntu, and the policy for FORWARD, INPUT and OUTPUT are all accept.


Can anyone see anything wrong with the commands above (from my limited understanding of iptables - I dont see a problem), or am I going at this the completely wrong way?

edit:

I have set /proc/sys/net/ipv4/ip_forward to 1 (despite previous edits with problems I was having)
sean is offline   Reply With Quote
Old 10-31-2009, 09:16 AM   #2
Super Moderator
 
Join Date: Sep 2001
Posts: 4,680
Problem solved. I wish I could've done with iptables - because I really wanna learn more about that - but I found I tool could rinetd that runs as a server and does the forwarding for you. It has a simple config file, where all I had to say was "0.0.0.0 5345 192.168.100.254 80" and it forward any traffic on my host at port 5345 to port 80 on the virtual machine. WOO HOO!
sean is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting 32 bit binary IP to decimal IP (vice-versa) Mankthetank19 C Programming 14 11-27-2008 12:53 PM
Virtual Tables Unregistered C Programming 1 02-19-2002 10:02 PM
C++ XML Class edwardtisdale C++ Programming 0 12-10-2001 11:14 PM
Exporting Object Hierarchies from a DLL andy668 C++ Programming 0 10-20-2001 01:26 PM


All times are GMT -6. The time now is 12:28 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22