Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

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

share|improve this question

closed as not constructive by Bart De Vos, womble, Khaled, Tom O'Connor, Skyhawk Apr 22 '12 at 14:30

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

3  
Just cutting and pasting your question back in when it's rejected doesn't accomplish anything but annoying people. Figure out why it was rejected and fix it. –  geekosaur Apr 22 '12 at 9:46
    
@geekosaur i have sent it to stackoverflow.com/questions/10266676/… it says: "This question might be better asked on serverfault.com" –  Metalik Apr 22 '12 at 10:03
    
simple question: "need a way to proxify a port" –  Metalik Apr 22 '12 at 15:26

1 Answer 1

You can redirect traffic to a port on the local machine like this:

sudo iptables -t nat -A OUTPUT -p tcp --dport 80 -j DNAT --to-destination 127.0.0.1:8000

You can't redirect traffic to an arbitrary machine though, see the comment at the bottom of http://www.netfilter.org/documentation/HOWTO//NAT-HOWTO-6.html (which still seems to be valid - I tested it)

Given this restriction, you might be able to place a reverse proxy on the local machine to forward your HTTP requests to the proxy. Nginx should be able to do this, see http://tumblr.intranation.com/post/766288369/using-nginx-reverse-proxy

Whether this works or not will probably depend on how your proxy is configured...

share|improve this answer
    
1. is it possible to change 127.0.0.1:8000 to an external ip:port ? –  Metalik Apr 22 '12 at 14:30
    
2. 8000 is port of proxy server? –  Metalik Apr 22 '12 at 14:31
    
3. if your solution work, i can config proxy server to use cascade proxy –  Metalik Apr 22 '12 at 14:32
    
It's not possible to change 127.0.0.1:8000 to an external port, the packets will not be rewritten correctly. Yes, 8000 is the port of the proxy server –  dwurf Apr 22 '12 at 22:00

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