I have created this tunnel on server ssh -f -N -o -L 8789: user@

This allows me to connect from local server to the remote server, through port 8789, like so : ssh -p 8789 user@localhost

What I want to achieve, is to let also other servers, to connect to remote server through that port, so I came with this :

ssh -f -N -o -L user@

This way, other servers , like or ( who are able to ssh into , can connect to through the tunnel:

ssh -p 8789 user@

The problem is that this way, everyone who has access to can use that tunnel, and I don't want that. Let's say I only want and to be able to use that tunnel. How do I achieve this ? Thanks.

1 Answer 1


This can be done with firewall rules. For example , Iptables. First we allow the traffic on a specific IP:

iptables -A IN_public_allow -s a.b.c.d -p tcp -m tcp --dport abcd -m conntrack --ctstate NEW -j ACCEPT

Then the whole traffic is restricted on the port:

iptables -A IN_public_allow -p tcp -m tcp --dport abcd -m conntrack --ctstate NEW -j DROP

This way, everyone is blocked on the port, except ip a.b.c.d.

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.