How to redirect HTTP traffic to new server using iptables ?

How to redirect HTTP traffic to new server using iptables ?

In this article we will learn to redirect HTTP traffic from old server to new server. If you want redirect all traffic from the old server's HTTP port to new server with a different IP.

First of all we can assume you have a server with interface name as "host1", and destination IP on which you want to redirect it is "175.25.6.89".

Like:
Old server interface name : host1
Destination IP : 175.25.6.89
Service : Apache(port 80 and 443)

Now, you can do redirection by running the below given commands :

# iptables -t nat -A PREROUTING -i host1 -p tcp –dport 80 -m conntrack –ctstate NEW -j DNAT –to 175.25.6.89:80
# iptables -t nat -A PREROUTING -i host1 -p tcp –dport 443 -m conntrack –ctstate NEW -j DNAT –to 175.25.6.89:443
# iptables -t nat -A PREROUTING -m conntrack –ctstate ESTABLISHED,RELATED -j ACCEPT
# iptables -A POSTROUTING -t nat -j MASQUERADE
Author
bhawanisingh
Views
5,073
First release
Last update
Rating
0.00 star(s) 0 ratings
Top