Redirecting network traffic to a new port using IPtables
Posted on: 7 February 2015 /
Categories:
The following article describes how to redirecting traffic from port 443 to 143 in IPtables
The first thing to do is do enable IP forwarding. This is done either by using:
# echo “1” > /proc/sys/net/ipv4/ip_forward or sysctl net.ipv4.ip_forward=1
Then, we will add a rule telling to forward the traffic on port 443 to port 143:
iptables -t nat -A PREROUTING -p tcp –dport 443 -j DNAT –to-destination 143:443
And finally, we ask IPtables to masquerade:
iptables -t nat -A POSTROUTING -j MASQUERADE