Port/Address forwarding with iptables with one network interface.
Due to circumstances involving my motherboard (the one that comes in an HP Pavillon 8700), I'm unable to put a second ethernet card in my linux computer.
Problem: Want to forward incoming internet traffic to another computer via iptables, using only one ethernet interface. Information: Routing computer's IP: 1.1.1.1 Destination computer's IP: 1.1.1.4 Port of interest: TCP 6112 Here's what I think is the best solution for my problem, but I'm 100% open to suggestions: Packet on 6112 -> Routing Computer's eth0, reroute to lo0 Packet on 127.0.0.1:6112 -> reroute to eth0, 1.1.1.4:6112 Basically, I'm trying to get around one interface by routing incoming traffic on that port to my loopback device, then routing traffic on that interface back out eth0 to the proper computer on my network. I've done a ton of research in this, and I would put the best sites I found, but I can't due to lack of sufficient posts :/ For whatever reason, I just can't get anything to work. Thank you in advance for any help. -Nextrastus |
How is the packet arriving at the routing computer? What's the source? Also, are you actually using the 1.1.1.0 IP Block? You should be using a valid RFC1918 reserved network block on a LAN, if you're performing NAT.
|
So far, I've just been using 0/0 for the source, since I figured allowing anything would rule out a few problems, I could always lock it down better later anyways.
Network Setup: Code:
Here is my iptables stuff as is (as applicable to my question): Code:
iptables -t nat -I PREROUTING --src 0/0 --dst 1.1.1.1 -p tcp --dport 6112 -j DNAT --to-destination 127.0.0.1 Code:
iptables -A FORWARD -s 0/0 -i eth0 -d 1.1.1.1 -o lo0 -p TCP --dport 6113 -j ACCEPT Code:
iptables -t nat -A PREROUTING -p tcp -d 127.0.0.1 --dport 6113 -j DNAT --to-destination 1.1.1.4:6112 (Granted, I've found two very good sites for reference, but they only really show how the command syntax is, they don't go into detail how one might apply such information) This way, I can essentially move my NATing off of my DSL modem. Most things that require incoming ports are on my linux computer, I only really want to forward a handful of stuff to my windows machine, but in those cases where something needs to be quickly forwarded, I don't want to have to stop everything I'm doing, disconnect from everything, edit modem config, restart, etc. Once again, many thanks for your time. |
Quote:
|
Hello Nextrastus,
Why don't you create a virtual adapter and route all your data coming on the interface eth0 to the newly created one? Having created the virtual adapter, you can forward the incoming data by using NAT in iptables. I think this would work in your scenario, please update us with the details, in case. Thanks,,,, |
Port/Address forwarding with iptables with one network interface
this is what was missing here : iptables -t nat -A POSTROUTING -j MASQUERADE
so what you acctualy should do is : sysctl net.ipv4.ip_forward=1 iptables -t nat -A PREROUTING -s 0/0 -p tcp -d x.x.x.x --dport 6112 -j DNAT --to y.y.y.y:6112 iptables -t nat -A POSTROUTING -j MASQUERADE where x.x.x.x is the server IP you want to forward the port from , and y.y.y.y is the destination server IP hope this helps Piotr |
All times are GMT -5. The time now is 05:42 PM. |