Question

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

Posted August 23, 2015 2.5k views
Ubuntu Networking Firewall Linux Commands

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

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

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…

Submit an Answer