Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Port Forwarding

I have a simple requirement of a software level port forwarding/tunnelling of socket based communication.

  • I have a source server and port using Sockets. This is a java program which works both in windows and linux and this is irrelevant.
  • I have devices which keep sending data to this port. There may be a bi-directional communication
  • I want to redirect this data to another remote server and port. So for the clients they will not have to worry about change of ip address whenever I move my app server.

Are there any tools/deamon/service programs which I can use to configure and do this?

I tried SSH, but to my understanding this needs a SSH protocol enabled server. In my case this is not applicable. I also tried using JSch but this again is an implementation of SSH in java format.

Can someone throw some pointers? Is it possible to use iptables NAT in linux?

like image 447
Muthu Avatar asked Dec 04 '11 08:12

Muthu


2 Answers

You can try netcat or socat (it's more powerful than netcat)

An example for socat to forward port 80 using tcp4:

socat tcp4-listen:80,fork tcp4:{another server}:{another port}

and refer to http://en.wikipedia.org/wiki/Netcat#Port_Forwarding_or_Port_Mapping for netcat

Both are not java-related.

like image 107
Tony Wang Avatar answered Oct 20 '22 08:10

Tony Wang


There is a TCP/IP port forwarding utility named portforward available in code.google.com. It is entirely written in Java.

like image 2
Jomoos Avatar answered Oct 20 '22 08:10

Jomoos