0

imagine that on the same host I have 2 services: an ssh daemon listening on port 22 a socks5 proxy listening on port 1080

I want to multiplex both services using only port 22 but depending on the source port.

For example: if source port is one of (1,2,3,4,5,6) then it goes to 1080 otherwise it does to port 22

This rule works one way

iptables -t nat -A PREROUTING -p tcp -m tcp --dport 22 -m multiport --sports 1,2,3,4,5,6 -j REDIRECT --to-ports 1080

But I don't know what rule to put for the way back.

I suppose something along the lines of:

iptables -t nat -A POSTROUTING -p tcp -m tcp .....

But I don't seem to get the right one.

Update: this seems to work for a single port:

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 22 --sport 2 -j DNAT --to :1080
0

And here we go:

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 22 -m multiport --sports 1:6 -j DNAT --to :1080

I knew it was simple.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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