Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

simple question: "need a way to proxify a port"

I have a linux server and have a proxy server on another machine.

My linux server needs connect to port 'x' on ip 'y'

Is it possible to create iptables rule or another way to: when my linux server tries to connect to port 'x' on ip 'y' uses my proxy server on another machine?

In other words, I need to my server's ip changes when it needs to connect port 'x' on ip 'y' by using another proxy server machine.

share|improve this question
What kind of proxy (SOCKS, HTTP, FTP, …)? Or do you simply want to redirect TCP traffic? – Gilles Apr 22 '12 at 23:27
@Gilles it is socks. no i need proxify a specific port. – Metalik Apr 23 '12 at 4:34
I'm still unclear on what you're asking. "need to my server's ip changes" seems like it's missing a verb. Need to log? Need to redirect? Need to block? Is the idea that the proxy is not used by linux box unless it is specifically attempting to connect to y:x ? – ckhan Apr 27 '12 at 2:58
@ckhan need a way to proxify a port – Metalik Apr 27 '12 at 6:14

This can't be done at the TCP layer because the application won't be using the SOCKS protocol and so the SOCKS server can't understand the request. You can look into using tsocks to transparently send traffic from certain application(s) via the SOCKS server. You can configure tsocks to select the proxy based on the destination and port number, using the reaches configuration directive.

share|improve this answer

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.