Forwarding ports using netcat
You can fordward ports from userspace using netcat like this:
nc -l -p $localport -c "nc $remotehost $remoteport"
Example:
nc -l -p 8888 -c "nc example.com 8888"
Caution: This starts a new process for ever connect to the port.
Jonas Wagner
Hey Jonas, are you sure that this version of nc is that same as the BSD version? Under linux I don't have the "-c" command line option. Any ideas?
Comment by heretoo — 5/21/09 9:11 AM | # - re
Okay, I figured it out. There are several versions of netcat. Under ubuntu I have the two variants "openbsd" and "traditional" (nc 1.10 which has a buffer overflow in it). Well, I think I'll forward ports some other way.
Comment by heretoo — 5/21/09 9:34 AM | # - re
hi there, i'm stuck with this problem:
I need to forward traffic from a local tcp port to another tcp in the same machine... like tcp 8080 to tcp 81. Can i use netcat to do that??
Something like:
nc -l -p 8080 -c "nc 127.0.0.1 81"
Thanks in advance...
Comment by caesar — 8/26/09 4:16 PM | # - re
I think this should work. Although if you are using linux I think you are better of if you use iptables.
Comment by Jonas Wagner — 8/26/09 8:08 PM | # - re
Hi there!! It's me again. I want to explain why i need "something" to forward a local port to another local port...
I use Java ICA Client Applet to connect via SSL-Tunnels to my Citrix Metaframe XP Server... ICA server listens by default on port tcp 1494 and it doesn't allow me to set a listening port range. When i set up the java ica client, i cannot open 2 SSL-tunnels over the same port(1494), and if i set another SSL-tunnel over other port than 1494 the client cannot connect to de ICA Server. So if i redirect tcp port 1495 traffic to tcp 1494 then i guess i'll be able to set up ssl-tunnels over other ports than 1494 forwarding them locally to itself.
Comment by caesar — 8/26/09 7:04 PM | # - re