How to Forward http and mysql traffic to the new server IP

Once you do server migration, You will definitively change the DNS records of the domain to the new server IP, But as you know, Such DNS update will take **8-24 hours for the DNS propagation**, and will cause an issue like some users with the old DNS recodrs in the DNS cache will be going to the OLD server it self.

Now, the question is how you can forward the traffic received at your OLD server to your NEW server, so that all your users requests should served by the NEW server Only. Here we are talking about a LAMP server which serves the website on port 80, and mysql on port 3306.

**In this scenario, The old server IP us and the new server IP is**

Now, Just you need to apply the following rules on the OLD server IPTABLES chain.

### Run the following from a terminal,

iptables -t nat -A PREROUTING -p tcp -d –destination-port 80 -j DNAT –to-destination

iptables -t nat -A POSTROUTING -p tcp -d –destination-port 80 -j SNAT –to-source“`

iptables -t nat -A PREROUTING -p tcp -d –destination-port 3306 -j DNAT –to-destination

iptables -t nat -A POSTROUTING -p tcp -d –destination-port 3306 -j SNAT –to-source“`

/etc/init.d/iptables save

/etc/init.d/iptables restart“`

You are done, Now all the http and mysql traffic coming to the OLD server will be forwarded to the NEW server IP

Of course, You can change the Port numbers to any other service, Say you want to redirect email traffic, The you could replace 80 with 25.

Any Questions, Please comment. ![:)](

0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x
Scroll to Top