Use firewalld as proxy

Here is a simple way to redirect your traffic from one server to another. This is particularly useful if you are moving servers or IP addresses.

Instead of installing an internal proxy, we just use firewalld to redirct all traffic to a different IP address.

Here an example for redirecting port 443 to IP 10.12.34.56


echo "net.ipv4.ip_forward = 1" > /etc/sysctl.conf # allow forwarding
sysctl -p # reload to activate changes.
 


firewall-cmd --zone=public --add-port=22/tcp --permanent # required or you will lose your ssh access.
firewall-cmd --zone=public --add-port=443/tcp --permanent
firewall-cmd --zone=public --add-masquerade
firewall-cmd --zone=public --add-forward-port=port=443:proto=tcp:toport=443:toaddr=10.12.34.56
firewall-cmd --reload

 

You can also do the same via iptables:

echo "net.ipv4.ip_forward = 1" > /etc/sysctl.conf # allow forwarding
sysctl -p # reload to activate changes.

iptables -A FORWARD -i eth0 -j ACCEPT

iptables -t nat -A PREROUTING -p tcp -m tcp -i eth0 --dport 443 -j DNAT --to-destination 10.12.34.56:443
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

netfilter-persistent save # install iptables-persistant if you don't have this command.