Sunday, August 16, 2015

iptables - how can I forward all ports (my outgoing traffic) through a local-proxy / SSH?

I have a very basic understanding of iptables from reading about 30 different similar questions people have asked and some tutorials. What I am trying to do is forward all of my outgoing traffic through SSH, to have it function as a sort of universal socks proxy. I don't have a way to test this right now, but this is what I've come up with on my own:


iptables -A OUTPUT -i eth0 -p tcp --destination-port 22 -j ACCEPT
iptables -A OUTPUT -i eth0 -p tcp -j REDIRECT --to-port 22

The first rule should automatically accept anything already destined for port 22, while the second rule should redirect any remaining outgoing packets to port 22.


My main issue is that I don't have a complete understanding on the differences between PREROUTING and OUTPUT, because I've seen them both be used in different ways to forward ports like this.

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...