Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm struggling a bit trying to see how to use socat (or a similar TCP port redirector) to expose a firewalled service on a PC.

Here's the scenario: I have a server PC which will be acting as a listen-listen "proxy" / redirector between two client machines. The server can have as many firewall ports open as needed and has a public IP. On the first "client" (as in establishing an outbound connection to the proxy server), Client A, I am hosting a service on port 4200. This PC is behind a firewall which only allows inbound TCP connections based on a previous outbound connection. The same is true of the firewall Client B is behind.

What I need to do is have Client B able to access port 42000 on Client A through the internet-facing TCP proxy server. The problem is that I can only initiate outbound TCP connections from Client A. How can I redirect the TCP connections through the server when both of the relay's clients are behind firewalls which only allow outbound connections? Please see the diagram below & let me know if clarification is in order.

                 |   Server   |
                 |w/ public IP|
                 /            \
          {|<Firewall>|}    {|<Firewall>|}
                |                 |
          ----------          ----------        
         | Client A |        | Client B |
          ----------          ----------
       (hosting a service    (wanting to access
         on port 4200)         Client A port 4200)

I would greatly appreciate any advice, thanks.

share|improve this question
up vote 1 down vote accepted

Something like

On "Server":

socat TCP4-LISTEN:10000 TCP4-LISTEN:4200

On "Client A"

socat TCP4:Server:10000 TCP4:localhost:4200

On "Client B"
Configure the client to connect to Server:4200

Alternatively, have a look at SSH port forwarding.

share|improve this answer
Thanks for the answer! It was perfect :). The one issue I'm having is, say I set up the chain as you've stated above & say the service is actually RDP. The connection immediately drops for some reason, after the first few packets are sent. Maybe this is a misunderstanding on my part of how to use socat? – slashp Apr 2 '11 at 20:01
socat has lots (really really lots) of options. I expect you need to find the right options to suit the needs of RDP. I'm not enough of an expert in socat or RDP to work it out easily. Have a look at which is related to this task and the man page which I find moderately intimidating. – RedGrittyBrick Apr 2 '11 at 23:25

You can also use PortFusion which I originally developed personally for this type of scenario, specifically for RDP.

  server> PortFusion                ] 10000        [
client-a> PortFusion 4200 localhost - 10000 server [ 4200

Now client-b can connect to server:4200 for RDP.


You should start PortFusion on client-a (or socat or anything else for that matter) as a different user AND ALSO NOT from within the graphical session of the user you want to connect as - otherwise you will get a black screen or a drop, etc.

Hope my answer can be of help.

share|improve this answer
Easier than socat, thanks! Can this be used in a commercial application if it's attributed? – slashp Sep 15 '11 at 20:30
Yes! It can be used in any type of applications. I would love to hear about the application in which you use it :) – Cetin Sert Sep 17 '11 at 23:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.