Skip to content

Instantly share code, notes, and snippets.

@aleskxyz
Created December 22, 2023 10:42
Show Gist options
  • Select an option

  • Save aleskxyz/1e5957a7f0852b7ab3f28fe2c174e3f5 to your computer and use it in GitHub Desktop.

Select an option

Save aleskxyz/1e5957a7f0852b7ab3f28fe2c174e3f5 to your computer and use it in GitHub Desktop.

Revisions

  1. aleskxyz created this gist Dec 22, 2023.
    10 changes: 10 additions & 0 deletions iptables-forward-port.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    # This snippet is an example of how we can forward port 80 and 443 from a local server to a remote server
    # These commands are working on Debian and Ubuntu

    echo net.ipv4.ip_forward=1 > /etc/sysctl.d/99-ipforward.conf
    sysctl -p
    apt install iptables-persistent
    iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination <remote-server-ip>:80
    iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT --to-destination <remote-server-ip>:443
    iptables -t nat -A POSTROUTING -j MASQUERADE
    iptables-save > /etc/iptables/rules.v4