How to Set up Port Forwarding with iptables


sudo sysctl -p sudo sysctl --system
iptables -t nat -A PREROUTING -p tcp -d --dport 8080 -j DNAT --to-destination
iptables -t nat -A POSTROUTING ! -s -j MASQUERADE

Making it permanent

# open the interface definitions
sudo nano /etc/network/interfaces
# find your interface and add the following
pre-up iptables-restore < /etc/iptables.rules
pre-down iptables-save > /etc/iptables.rules
# ifupdown has been replaced by netplan(5) on this system. See
# /etc/netplan for current configuration.
# To re-enable ifupdown on this system, you can run:
# sudo apt install ifupdown
echo 'iptables-restore < /etc/iptables.rules' | sudo tee /etc/networkd-dispatcher/routable.d/50-iptables-restore
echo 'iptables-save > /etc/iptables.rules' | sudo tee /etc/networkd-dispatcher/off.d/50-iptables-save

React, Flutter, Firebase Developer from Germany