The original post: /r/linux by /u/poynnnnn on 2024-12-20 00:27:37.

I’m working on a setup where I run multiple VPN clients inside Linux-based containers (e.g., Docker/LXC) on a single VM, each providing a unique external IP address. I’d then direct traffic from a Windows VM’s Python script through these container proxies to achieve multiple unique IP endpoints simultaneously.

Has anyone here tried a similar approach or have suggestions on streamlining the setup, improving performance, or other best practices?

-----------------------

I asked ChatGPT, and it suggested this. I’m unsure if it’s the best approach or if there’s a better one. I’ve never used Linux before, which is why I’m asking here. I really want to learn if it solves my issue:

  1. Host and VM Setup:
    • You have your main Windows Server host running Hyper-V.
    • Create one Linux VM (for efficiency) or multiple Linux VMs (for isolation and simplicity) inside Hyper-V.
  2. Inside the Linux VM:Why a proxy? Because it simplifies routing. Each container’s VPN client will give that container a unique external IP. Running a proxy in that container allows external machines (like your Windows VM) to access the network over that VPN tunnel.
    • Use either Docker or LXC containers. Each container will run:
      • A VPN client (e.g., OpenVPN, WireGuard, etc.)
      • A small proxy server (e.g., SOCKS5 via dante-server, or an HTTP proxy like tinyproxy)
  3. Network Configuration:Make sure the firewall rules on your Linux VM allow inbound traffic to these proxy ports from your Windows VM’s network.
    • Make sure the Linux VM’s network is set to a mode where the Windows VM can reach it. Typically, if both VMs are on the same virtual switch (either internal or external), they’ll be able to communicate via the Linux VM’s IP address.
    • Each container will have a unique listening port for its proxy. For example:
      • Container 1: Proxy at LinuxVM_IP:1080 (SOCKS5)
      • Container 2: Proxy at LinuxVM_IP:1081
      • Container 3: Proxy at LinuxVM_IP:1082, and so forth.
  4. Use in Windows VM:For example, if you’re using Python’s requests module with SOCKS5 proxies via requests[socks]:import requests # Thread 1 uses container 1’s proxy session1 = requests.Session() session1.proxies = { ‘http’: ‘socks5://LinuxVM_IP:1080’, ‘https’: ‘socks5://LinuxVM_IP:1080’ } # Thread 2 uses container 2’s proxy session2 = requests.Session() session2.proxies = { ‘http’: ‘socks5://LinuxVM_IP:1081’, ‘https’: ‘socks5://LinuxVM_IP:1081’ } # and so forth…
    • On your Windows VM, your Python code can connect through these proxies. Each thread you run in Python can use a different proxy endpoint corresponding to a different container, thus a different VPN IP.
  5. Scaling:
    • If you need more IPs, just spin up more containers inside the Linux VM, each with its own VPN client and proxy.
    • If a single Linux VM becomes too complex, you can create multiple Linux VMs, each handling a subset of VPN containers.

In Summary:

  • The Linux VM acts as a “router” or “hub” for multiple VPN connections.
  • Each container inside it provides a unique VPN-based IP address and a proxy endpoint.
  • The Windows VM’s Python code uses these proxies to route each thread’s traffic through a different VPN tunnel.

This approach gives you a clean separation between the environment that manages multiple VPN connections (the Linux VM with containers) and the environment where you run your main application logic (the Windows VM), all while ensuring each thread in your Python script gets a distinct IP address.

https://preview.redd.it/zxc2mb92ew7e1.png?width=1387&format=png&auto=webp&s=dd8dc0fa30dc445b92b6a07781973e8f561fc793