The most annoying thing when a server is being retired and a new one taking over is trying to get users and traffic in general to go to the new server even though all the DNS has been updated thanks in part to cached DNS.
So how do you solve this? Simple…
Let’s use iptables! For those who don’t know, this is a software firewall that ships with almost every Linux distro out there and can be used for a lot more than just security. In our case, we want to use it to forward traffic from one server to another because we’re going to lay claim to the old one for our gaming server… but we won’t tell management that.
So, okay, let’s login via SSH to our server we’re going to be forwarding the traffic from as root and run the following:
echo 1 > /proc/sys/net/ipv4/ip_forward
Next we have to setup the forwarding rule to send all traffic on port 80 (HTTP) to our destination, 127.2.55.124:
iptables -t nat -D PREROUTING -p tcp –dport 80 -j DNAT –to-destination 127.2.55.124
Now, here’s the fun, we’re going to rewrite the origins to the new server to appear to come from the old server:
iptables -t nat -D POSTROUTING -p tcp -d 127.2.55.124 –dport 80 -j MASQUERADE
If we don’t, then we have the problem of the new server thinking the connections are not coming from the clients but from the old server itself which could pose issues.
