Using iptables to redirect ip address
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?
Solution 1:
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.