The problemI have two programs that runs on two distant computers and communicate through a specific protocol. All I know is that this protocol only communicates through UDP and uses the ports 1101 and 1102 and that both computers need to be on the same local network.I already managed to do this using a VPN (p2p), but I wonder if it is possible using iptables through SSH tunnel (SSH tunnel is mandatory here).I use two Linux Debian wheezy servers to open a tunnel over internet between the two programs. I managed to create a SSH tunnel that redirects UDP traffic from one side to the other (for all ports), but this does not work. To do so I use socat (here the representation for port 1101):transmission from computer1 --> port 1101/server1 --> socat to port 61101 --->---> ssh tunnel ---> ---> socat from port 61101--> port 1101/server2 --> reception on computer2My goal is to make server2 behaves exactly as it was computer1 from computer2's point of view (and vice versa). IP addresses have to be translated correctly when transmitting packets and tranfered data have to be changed accordingly.SSH is configured with automated login using keyfiles.My tunnel configurationThis is how I configured the tunnel in order to redirect both ports in both directions.#From server1's shell $ ssh -f -N -T -R51101:localhost:51101 login@server2 # reverse tunnel for port 1101$ ssh -f -N -T -R51102:localhost:51102 login@server2 # reverse tunnel for port 1102$ ssh -f -N -T -L61101:localhost:61101 login@server2 # tunnel for port 1101$ ssh -f -N -T -L61102:localhost:61102 login@server2 # tunnel for port 1102#socat redirection on server1$ socat TCP4-LISTEN:51101,fork UDP4:server1:1101 #redirects from the tunnel to the local 1101 port$ socat TCP4-LISTEN:51102,fork UDP4:server1:1102 #redirects from the tunnel to the local 1102 port$ sudo socat -d -d UDP4-LISTEN:1101,fork,bind=1101 TCP4:localhost:61101  #redirects to both tunnel and local UDP port 1101$ sudo socat -d -d UDP4-LISTEN:1102,fork,bind=1102 TCP4:localhost:61102  #redirects to both tunnel and local UDP port 1102#From server2's shell #socat redirection on server2$ socat TCP4-LISTEN:61101,fork UDP4:server1:1101 #redirects from the tunnel to the local 1101 port$ socat TCP4-LISTEN:61102,fork UDP4:server1:1102 #redirects from the tunnel to the local 1102 port$ sudo socat -d -d UDP4-LISTEN:1101,fork,bind=1101 TCP4:localhost:51101  #redirects to both tunnel and local UDP port 1101$ sudo socat -d -d UDP4-LISTEN:1102,fork,bind=1102 TCP4:localhost:51102  #redirects to both tunnel and local UDP port 1102I think it possible to do this using iptables, but I don't know how to do this.Anyone having a solution ? Or a recipe on how to make correct address translation using iptables ?
iptables rule to transfer UDP through a SSH tunnel
ssh;iptables;ssh tunneling;udp