I'm trying to create a proxy of sorts using just iptables.
The linux computer (my proxy) has two ports:
- p2p1 is connected to the Internet.
- em1 is connected to a local network.
There are two devices on the local network (not including the linux machine). To connect to these, we should type (from any computer on the Internet):
where xx.xx.xx.xx is the public IP (and is dynamic).
These devices can be accessed from the linux machine on the em1 port by accessing the following IPs:
So, all traffic that gets routed into xx.xx.xx.xx:10001 on p2p1 should be redestined for 192.168.3.100 on em1.
I also need to retain the source IP, or something to that effect, so the packets can find their way back.
Here's what I'm using in my IP tables script.
iptables -t nat -F # Clear out any old rules. MyIP=10.27.155.200 MyPort=10001 DestIP=192.168.3.100 DestPort=80 iptables -t nat -A PREROUTING --dst $MyIP -p tcp --dport $MyPort -j DNAT --to-destination $DestIP:$DestPort iptables -t nat -A POSTROUTING -p tcp --dst $DestIP --dport $DestPort -j SNAT --to-source $MyIP iptables -t nat -A OUTPUT --dst $MyIP -p tcp--dport $MyPort -j DNAT --to-destination $DestIP:$DestPort
Obviously there are some problems because my IP is dynamic, yet I'm hard coding it in every time. Furthermore, the packets, once they return to the computer, don't know how to get to their original source.
I don't know where to go from here.