I have the requirement on a Linux system where the Linux device is using RSYNC to sync data to another Linux machine. This is working fine at the moment, however I need to move one of the machines to a different data centre.

Is it possible, using iptables to configure the machine such that all calls to (for example) local address now are actually sent to a public address on the internet?


IP forwarding needs to enabled: edit /etc/sysctl.conf and ensure that the line net.ipv4.ip_forward = 1 is there and not commented out.

Then you need to execute this command:

iptables -t nat -A OUTPUT -d [ipaddress1] -j DNAT --to-destination [ipaddress2]

Where ipaddress1 is the address that you want redirecting to ipaddress2.

Note - this command doesn't survive a reboot.

  • 3
    to complete this: iptables-save >/somepath/iptables.save Add to cron upon start up iptables-restore </somepath/iptables.save
    – cybernard
    Nov 28 '13 at 18:55
  • @cybernard's comment should be added to the answer.
    – insaner
    Sep 24 '17 at 3:42

The client connects to the old address, and the new address maybe changed, for example You can do port forwarding with ssh tunnel instead of iptables.

ssh -TNnfaq -L user@localhost


ssh -L user@localhost # for test

All requests send to with forward to You do not need root if port number is greater than 1024.

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.