Skip to content

Instantly share code, notes, and snippets.

@blackestwhite
Created December 5, 2022 13:46
Show Gist options
  • Save blackestwhite/6797d35d39c6368f4813bd47e65cd2b6 to your computer and use it in GitHub Desktop.
Save blackestwhite/6797d35d39c6368f4813bd47e65cd2b6 to your computer and use it in GitHub Desktop.
port forwarding using ip tables
#!/bin/bash
read -p "Enter your proxy server's IP: " PROXY_IP
read -p "Enter your destination server's IP: " DEST_IP
sysctl net.ipv4.ip_forward=1
iptables -t nat -A PREROUTING -p tcp --dport 22 -j DNAT --to-destination $PROXY_IP
iptables -t nat -A PREROUTING -j DNAT --to-destination $DEST_IP
iptables -t nat -A POSTROUTING -j MASQUERADE
iptables-save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment