Using ip tables to forward port to virtual machine

This is a discussion on Using ip tables to forward port to virtual machine within the Networking/Device Communication forums, part of the General Programming Boards category; I'm running VirtualBox for a class lab, and VirtualBox on Ubuntu appears to be missing the "Bridge Interface" feature for ...

  1. #1
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913

    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)

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    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!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Converting 32 bit binary IP to decimal IP (vice-versa)
    By Mankthetank19 in forum C Programming
    Replies: 15
    Last Post: 12-28-2009, 06:17 PM
  2. Virtual Tables
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 02-19-2002, 09:02 PM
  3. C++ XML Class
    By edwardtisdale in forum C++ Programming
    Replies: 0
    Last Post: 12-10-2001, 10:14 PM
  4. Exporting Object Hierarchies from a DLL
    By andy668 in forum C++ Programming
    Replies: 0
    Last Post: 10-20-2001, 01:26 PM

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