Skip to content

Instantly share code, notes, and snippets.

@jpalala
Last active October 3, 2025 03:17
Show Gist options
  • Save jpalala/763176383d9233204d2a2d67babeb26e to your computer and use it in GitHub Desktop.
Save jpalala/763176383d9233204d2a2d67babeb26e to your computer and use it in GitHub Desktop.
how to vpc proxy

πŸ”Œ Step 1: SSH-Add to set up the ssh-agent to use your ssh key

ssh-add -l /path/to/id_rsa # or /path/to/id_ed25519

πŸ›°οΈ Step 2: Open an SSH SOCKS Proxy Tunnel (localhost-only)

# Establish SOCKS5 proxy on localhost:1080 via the VPC bastion server
# This tunnel makes your local machine behave as if it has a "network cable"
# plugged directly into the VPC (10.15.0.0/16) β€” but only for apps configured
# to use this proxy.
ssh -D 1080 [email protected]

πŸ”Œ Step 3 (Optional): Route Commands or Tools Through the Tunnel

# Example: Use curl over the tunnel to reach a private IP in the VPC
curl --socks5 127.0.0.1:1080 http://10.15.3.42

# Example: Launch your devbox container and configure tools inside to use proxy
# (Note: docker itself won’t auto-proxy β€” apps inside must be proxy-aware)
docker run -it --rm jpalala/joesdevenv
# Inside container, set proxy manually when needed:
export ALL_PROXY=socks5://127.0.0.1:1080

πŸ” Visual Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         SSH Tunnel (-D)          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Your Host  │────────────────────────────────▢│ Bastion Server        β”‚
β”‚ (Windows / β”‚  SOCKS5 on 127.0.0.1:1080        β”‚ bastion.vpc.example.comβ”‚
β”‚  Devbox)   β”‚                                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜                                           β”‚
     β”‚  All proxied traffic goes through tunnel          β”‚
     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           Access to VPC-only IPs
                           e.g. 10.15.0.0/16
#!/usr/bin/env bash
# ===============================
# SSH Proxy / Tunnel Helper Script
# Usage:
# ./vpc-proxy.sh socks user@host -> Creates a SOCKS5 proxy at localhost:1080
# ./vpc-proxy.sh vpn user@host 10.0.0.0/16 -> Full VPN-like routing via sshuttle
# ===============================
MODE="$1"
TARGET="$2"
SUBNET="$3"
if [[ "$MODE" == "socks" ]]; then
echo "[*] Starting SOCKS proxy on localhost:1080 ..."
ssh -D 1080 -q -C -N "$TARGET"
elif [[ "$MODE" == "vpn" ]]; then
if [[ -z "$SUBNET" ]]; then
echo "Usage: ./vpc-proxy.sh vpn user@host <subnet>"
exit 1
fi
echo "[*] Starting full-network tunnel via sshuttle ..."
sshuttle -r "$TARGET" "$SUBNET"
else
echo "Usage:"
echo " ./vpc-proxy.sh socks user@host"
echo " ./vpc-proxy.sh vpn user@host <subnet>"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment