Migrating Servers - Redirect to new Server IP = No Downtime? How to

Here's the method that worked for me:
1) Sync the files and databases with the new server.
2) Perform a re-sync just before cut-off.
3) Change the DNS to point to the new server.
4) Forward the request coming to the old ip to the new server until DNS propagation completes.
Here's how I would do the step 4:
We will configure IPTables on a Linux server to redirect all the traffic coming on port 80, (which is the default web server port), to a server with the IP 122.164.34.240. The first step is to set your Linux box to allow this kind of forwarding to take place. Open a terminal window, log in as root user and run the following command:
# echo 1 >/proc/sys/net/ipv4/ip_forward
The next step is to tell IPTables to redirect the traffic to the new server:
# iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 122.164.34.240
Here’s where the IPTables magic happens. With the third and final step we tell IPTables to rewrite the origin of connections to the new server’s port 80 to appear to come from the old server.
# iptables -t nat -A POSTROUTING -p tcp -d 122.164.34.240 --dport 80 -j MASQUERADE
The final step is required because if we don’t tell the web server of the new server that the connections are coming from the client machines, it would think that they are originating from the old server.
You may want to repeat this for the databases and email server port as well.

root@usman [~]# iptables -t nat -A POSTROUTING -p tcp -d 162.23.232.23 --dport 3306 -j MASQUERADE
root@usman [~]# # iptables -t nat -A POSTROUTING -p tcp -d 162.23.232.23--dport 80 -j MASQUERADE
root@usman [~]# # iptables -t nat -A POSTROUTING -p tcp -d 162.23.232.23 --dport 80 -j MASQUERADE
root@usman [~]# # iptables -t nat -A POSTROUTING -p tcp -d 162.23.232.23 --dport 21 -j MASQUERADE
root@usman [~]# # iptables -t nat -A POSTROUTING -p tcp -d 162.23.232.23 --dport 25 -j MASQUERADE
root@usman [~]# # iptables -t nat -A POSTROUTING -p tcp -d 162.23.232.23 --dport 110 -j MASQUERADE
root@usman [~]# # iptables -t nat -A POSTROUTING -p tcp -d 162.23.232.23 --dport 3306 -j MASQUERADE
root@usman [~]#





How Do I See Open Ports and Socket Information Under UNIX or Linux?

You can use the netstat command:
# netstat -tulpn
FreeBSD specific example:
# sockstat -l
To list open IPv4 connections use the lsof command:
# lsof -Pnl +M -i4

Post a Comment

0 Comments