Skip to content

Instantly share code, notes, and snippets.

@SaeedDev94
Last active April 30, 2023 08:55
Show Gist options
  • Save SaeedDev94/94a7eedebd534d1c87c92a7a5c412375 to your computer and use it in GitHub Desktop.
Save SaeedDev94/94a7eedebd534d1c87c92a7a5c412375 to your computer and use it in GitHub Desktop.
TCP/UDP simple port-forward
#!/bin/bash
FROM="1024"
TO="443"
DEST="x.x.x.x"
# Flush nat rules
iptables -t nat --flush
# Exclude localhost
iptables -t nat -A POSTROUTING ! -s 127.0.0.1 -j MASQUERADE
# TCP Port Forward
iptables -t nat -A PREROUTING -p tcp --dport "$FROM" -j DNAT --to-destination "$DEST:$TO"
# UDP Port Forward
iptables -t nat -A PREROUTING -p udp --dport "$FROM" -j DNAT --to-destination "$DEST:$TO"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment