Forward port 80 and 443 to another droplet via the private network.

August 23, 2015 1k views
Firewall Linux Commands Networking Ubuntu

Hello,
I happened to accidentally remove my old iptables for forwarding port 80 and 443 to another droplet on the private DO network. After googling now for a few hours I have to say I really can't find anything related to it. From what I remember I read a tutorial here but as said I can't find it. Maybe someone could tell me how to do it or link me to the tutorial (if it still exists).

Many thanks,
Carl

1 Answer

Okay so apparently I had the same script on another server (for whatever reason. Well I won't complain...)

#!/bin/sh

echo 1 > /proc/sys/net/ipv4/ip_forward

iptables -F
iptables -t nat -F
iptables -X

iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT --to-destination 10.132.112.54:443
iptables -t nat -A POSTROUTING -p tcp -d 10.132.112.54 --dport 443 -j SNAT --to-source 10.132.113.5

The same for port 80 and so on...

Have another answer? Share your knowledge.