1

I try to redirect ssh-traffic from one machine to other with following bash sctipt:

   IPTABLES="/usr/sbin/iptables"

   $IPTABLES -F        
   $IPTABLES -X        
   $IPTABLES -F -t nat 
   $IPTABLES -X -t nat 
   $IPTABLES -F -t mangle
   $IPTABLES -X -t mangle

   $IPTABLES --policy INPUT   ACCEPT
   $IPTABLES --policy FORWARD ACCEPT
   $IPTABLES --policy OUTPUT  ACCEPT

   $IPTABLES -t nat -A POSTROUTING --out-interface ppp0 -j MASQUERADE
   $IPTABLES -t nat -A PREROUTING  -p tcp --dport 22 -j DNAT --to 192.168.2.2

   echo 1 > /proc/sys/net/ipv4/ip_forward 

But when I input

ssh user@localhost

or

ssh user@192.168.2.1 # (address of local host)

I get error 'Connection refused'.

Please, help me.

5

ssh user@localhost won't work, at least not with the rules you've used.

The PREROUTING chain works on packets coming into the machine, whereas if you're connecting to localhost, packets are being generated locally.

The upside, though, is that your configuration should work for external connections. Have you tried it from somewhere else?

Edit: This is a useful diagram of the flows for netfilter:-

enter image description here

| improve this answer | |
  • Thank You, Andy. Now it's clean for me. When I "tried it from somewhere else" these rules work well, according with the scheme. – Михаил Беляков Dec 3 '11 at 20:01

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.