Understand, Learn and Implement.. LINUX / UNIX DEVOPS CONTAINERS OPENSHIFT KUBERNETES DEVOPS TOOLS VIRTUALIZATION STORAGE BACKUP SCRIPTS MONITORING MIDDLEWARE

Monday, August 18, 2014

How to Redirect HTTP traffic to another IP using iptables

10:47 PM Posted by vinod , No comments
I want to redirect all traffic coming to the old server’s HTTP port(during the TTL change period) to the web server running in new server with a different ip.

DETAILS:


Service                                                      : Apache(port 80 and 443)

Interface name in old server(this is a vps)      : venet0
Destination ip                                             : 192.168.248.115

SOLUTION:


Use iptables nat to redirect http and https traffic to another server ip and port. Execute the following commands in the source server.


************************************************************************************************************************
iptables -t nat -A PREROUTING -i venet0 -p tcp –dport 80 -m conntrack –ctstate NEW -j DNAT –to 98.59.254.163:80


iptables -t nat -A PREROUTING -i venet0 -p tcp –dport 443 -m conntrack –ctstate NEW -j DNAT –to 98.59.254.163:443


iptables -t nat -A PREROUTING -m conntrack –ctstate ESTABLISHED,RELATED -j ACCEPT


iptables -A POSTROUTING -t nat -j MASQUERADE

************************************************************************************************************************

0 comments:

Post a Comment