11

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 192.168.100.230 now are actually sent to a public address on the internet?

2 Answers 2

17

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.

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

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

ssh -TNnfaq -L 192.168.100.230:22:192.168.100.240:22 user@localhost

or

ssh -L 192.168.100.230:22:192.168.100.240:22 user@localhost # for test

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .