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 123.123.123.123 and the new server IP is 222.222.222.222**

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 123.123.123.123 –destination-port 80 -j DNAT –to-destination 222.222.222.222:80


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

“`
iptables -t nat -A PREROUTING -p tcp -d 123.123.123.123 –destination-port 3306 -j DNAT –to-destination 222.222.222.222:3306


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

“`
/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 222.222.222.222

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. ![:)](https://www.jobnix.in/wp-includes/images/smilies/icon_smile.gif)

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