Skip to content

Instantly share code, notes, and snippets.

@thc282
Last active June 13, 2026 08:10
Show Gist options
  • Select an option

  • Save thc282/fe1b261aa712dcf6b5746298a431640b to your computer and use it in GitHub Desktop.

Select an option

Save thc282/fe1b261aa712dcf6b5746298a431640b to your computer and use it in GitHub Desktop.
Bypass OpenVPN connection

Background Story

Since the .ovpn have a setting with

redirect-gateway def1 bypass-dhcp
dhcp-option DOMAIN-ROUTE . 

Therefore, your PC network route will all go through the VPN. Which make the connection failed in local
Cannot surfing the web 🚫🚫🚫🚫

Solution?

Note

This workaround not modify any content inside the .ovpn file or route table

The solution is very simple, use a docker container to run the ovpn
VPN setting will only apply inside the docker container environment
Expose the port & ip to let local network to access

Full Architechture
[ Host Machine (Your PC) ] ───> Physical NIC (Wi-Fi/Ethernet) ───> Normal Local Internet (Fast & Untouched)
       β”‚
       β”œβ”€β”€β”€> [ Proxifier (Host) ] ───> Intercepts {your target device IP} ───> Forwards to localhost:{your fav port}
       β”‚                                                                   β”‚
       └─> [ Docker Engine (WSL2) ] β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                 β”‚
                 └─> [ Shared Network Space ]
                           β”‚
                           β”œβ”€β”€> [ Service 2: Gost (SOCKS5 Server) ] ───> Listens on port {your fav port}
                           β”‚                                                   β”‚
                           └──> [ Service 1: OpenVPN Client Container ] β”€β”€β”€β”€β”€β”€β”€β”˜
                                     β”‚
                                     β”œβ”€β”€> Connects to {provided VPN domain}
                                     └──> Highjacks CONTAINER-ONLY routes & DNS

Prerequest

Application Setup Guide

Proxifier SetUp

1. Create Proxy Server

Go to Menu, Open "Profile" > "Proxy Servers..."
"Add" a new server
Address: 127.0.0.1 | port: {your fav port} | Protocol: SOCKS VERSION 5
OK to Save

2. Create Proxification Rules

Go to Menu, Open "Profile" > "Proxification Rules..."
"Add" a new rule
Name: {your fav name} | Target host: {your target device IP} | Action: {the proxy server create in part 1}
OK to Save

Docker SetUp

File Preparation

File Structure
Create the below structure in any directory of your PC

vpn-proxy/
β”œβ”€β”€ compose.yml
└── vpn/
    β”œβ”€β”€ {provided}.ovpn
    β”œβ”€β”€ credentials.txt
    └── private_key_pwd.txt

Some value in template should change on your own

{port} β€” the port should be same as proxifier setting
{provided}.ovpn β€” the .ovpn file, use your own name

1. Create compose.yml

Download the compose.yml
Change the {port} and {provided}

Open Vpn Ref image

2. Create credentials.txt

Download or create credentials.txt
Fill in {user name} {password}

3. Create private_key_pwd.txt

Download or create password.txt
Fill in {private key password}

Docker Image build

  1. Open & Start Docker Desktop
  2. Goto the compose.yml directory.
  3. open cmd/terminal run docker compose up -d

Connection Guide

Note

this part is start from the init state, no "already in use" application or process

Start up & Prepare application

  1. Open Docker Destop (MUST)
  2. Open Proxifier (MUST)
  3. Prepare your auth tools

Docker kick start & vpn service

MUST already open the Docker Desktop

  1. Goto the compose.yml location
  2. run docker compose start
  3. run docker attach openvpn-client
  4. Fill in the 6-digit Auth code & Press Enter (if any)

    OpenVPN often doesn't automatically re-prompt or flush the stdout to show the 2FA Enter Authenticator Code hint when a new terminal attaches, leaving you staring at a blank, frozen screen.

    1. Even if the screen is blank or stuck on old logs, just type your 2FA code and hit Enter.
    2. OpenVPN will often accept the input anyway and proceed with the connection.
    3. Once connected, safely detach by pressing Ctrl + P then Ctrl + Q.
    if you input the wrong 2FA code, please detach first and do the following command
    docker compose restart
    docker attach openvpn-client
    

Start Remote Connection

  1. Open your remote desktop tools, fill in the {target device IP}
# template only
# {port} , {provided} must be fill in
version: '3.8'
services:
openvpn-client:
container_name: openvpn-client
image: my-openvpn-client:local
build:
context: .
dockerfile_inline: |
FROM alpine:latest
RUN apk add --no-cache openvpn
WORKDIR /vpn
entrypoint: ["openvpn"]
command: ["--config", "/vpn/{provided}.ovpn", "--auth-user-pass", "/vpn/credentials.txt", "--askpass", "/vpn/private_key_pwd.txt"]
cap_add:
- NET_ADMIN
devices:
- /dev/net/tun:/dev/net/tun
volumes:
- ./vpn:/vpn
stdin_open: true
tty: true
ports:
- "{port}:{port}"
restart: unless-stopped
gost:
image: ginuerzh/gost:latest
container_name: gost-proxy
network_mode: "container:openvpn-client"
command: "-L socks5://:{port}"
depends_on:
- openvpn-client
restart: unless-stopped
{user name}
{password}
{private key password}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment