Forward a host network traffic to another host with the exception of the ssh service [closed]

StackOverflow https://stackoverflow.com/questions/22212197

سؤال

I am trying to redirect all the network traffic received in a old host to a different new host. For that i created two new rules on iptables of the old host:

echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A PREROUTING -d old_machine_ip -j DNAT --to-destination new_machine_IP
iptables -t nat -A POSTROUTING -s new_machine_ip -j SNAT --to-source old_machine_ip
/etc/init.d/iptables save
/etc/init.d/iptables restart

Everything worked perfectly however i cannot access the old host ssh anymore since it redirect to the new host so i would like to know if it is possible to create a single rule that ignores the prerouting for the ssh service.

best regards,

هل كانت مفيدة؟

المحلول

iptables -t nat -A PREROUTING -m tcp -p tcp --dport 22 -j RETURN

It must appear before your DNAT rules.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top