I have used this technique for a few years now so thought I should post it here as it doesn’t appear to break.
Please note: This has been updated for Debian 12 and tested.
Last done on 2 plesk servers and a naked server (no control panel) this week all using various sub versions of Cent 6.x.
Replace XXX.XXX.XXX.XXX with the destination servers IP address.
WARNING: Use this technique at your own risk. Ensure that you have a way of getting to the server to turn the firewall off. For example a KVM.
sysctl net.ipv4.ip_forward=1
iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 109.228.55.36:80
iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT --to-destination 109.228.55.36:443
iptables -t nat -A POSTROUTING -p tcp -d 109.228.55.36 --dport 80 -j MASQUERADE
iptables -t nat -A POSTROUTING -p tcp -d 109.228.55.36 --dport 443 -j MASQUERADE
Repeat for each port.
Prior to doing this I create a file called server.txt on both servers in the root web with "Old Server" and "New Server" as the contents so I can see what server is being served on the main domain name.
Note I don’t redirect SSH or Plesk as I need to be able to access these per server still.
Leave a Reply