NeuroAgent

OpenVPN in WSL2: Impact on Windows Traffic

Learn how to install OpenVPN in WSL2 Ubuntu and configure SOCKS proxy for Windows. Traffic isolation and routing through VPN without affecting the host system.

If I connect to OpenVPN in WSL2, will this affect all other Windows traffic?

I’m starting to learn about WSL2 and have a question: can I install an OpenVPN client in WSL2 (I have Ubuntu) and connect to an OpenVPN server? If yes, how will this connection affect the rest of the host system’s Windows 10 traffic?

My goal is to install an OpenVPN client in the WSL2 virtual machine to configure a SOCKS proxy, and then route only the necessary applications in the host system through this SOCKS proxy.

NeuroAgent

Yes, you can install an OpenVPN client in WSL2 (Ubuntu) and connect to an OpenVPN server. The connection in WSL2 will not affect the traffic of the Windows host system, as WSL2 has a separate network architecture and isolated routing.

Table of Contents


Installing OpenVPN in WSL2

Installing an OpenVPN client in WSL2 is fully possible and works without issues with the latest versions of WSL2. The process includes the following steps:

bash
# Update packages
sudo apt update && sudo apt upgrade -y

# Install OpenVPN
sudo apt install openvpn -y

# Install additional utilities for configuration management
sudo apt install network-manager-openvpn -y

To work with OpenVPN configuration files, you’ll need to copy .ovpn files from your system to the WSL2 environment. As users note on Reddit, “this works without issues with the latest version of WSL2 (LTS or pre-release)”.


Network Traffic Isolation

Key point: WSL2 has a separate network architecture from the Windows host system. As experts explain on Reddit, “routing in WSL2 is separate from the Windows host system”.

This means:

  • Connecting to a VPN in WSL2 will not affect regular Windows network traffic
  • Applications in Windows will continue to work through the regular network interface
  • Only traffic within WSL2 will pass through the VPN connection

WSL2 uses a virtual network with its own DHCP server, ensuring complete isolation of network subsystems.


Setting Up SOCKS Proxy

To achieve your goal (setting up a SOCKS proxy in WSL2 and using it from Windows), you’ll need additional configuration:

Option 1: Using SSH Tunnel

bash
# In WSL2 Ubuntu
sudo apt install openssh-server -y
sudo systemctl start ssh
sudo systemctl enable ssh

Then in Windows, you can configure PuTTY or another SSH client to create a SOCKS proxy on localhost:1080.

Option 2: Using proxychains in WSL2

bash
# Install proxychains
sudo apt install proxychains4 -y

# Edit configuration
sudo nano /etc/proxychains4.conf

Add at the end of the file:

socks5  127.0.0.1 1080

To use in WSL2:

bash
proxychains4 wget https://example.com

Routing Windows Traffic Through WSL2

To route Windows traffic through a SOCKS proxy in WSL2, there are several approaches:

Method 1: Using netsh in Windows

cmd
# Create a proxy server in Windows pointing to WSL2
netsh winhttp set proxy 127.0.0.1:1080

Method 2: Configure proxy for individual applications

Browsers and other applications can be manually configured to use a proxy:

  • Proxy server: 127.0.0.1
  • Port: 1080
  • Type: SOCKS5

Method 3: Using Privoxy (intermediate HTTP proxy)

bash
# In WSL2
sudo apt install privoxy -y

# Configure Privoxy to use SOCKS
sudo nano /etc/privoxy/config

Add:

forward-socks5   /               127.0.0.1:1080 .

Issues and Solutions

Issue: IP address conflicts when using VPN in Windows

When Windows is connected to a VPN, WSL2 may lose internet connectivity. This happens due to routing conflicts.

Solution: Change the WSL2 subnet according to the GitHub gist:

cmd
# In Windows PowerShell as administrator
wsl --update
wsl --shutdown
netsh interface ipv4 set subinterface "vEthernet (WSL)" mtu 1500 store=persistent

Issue: DNS resolution in WSL2

When using a VPN, DNS issues may occur.

Solution: Manually configure DNS as described on Reddit:

bash
# Add DNS servers to /etc/resolv.conf
nameserver 10.100.0.1
options timeout:1
options attempts:2

Alternative Approaches

Option 1: Using VPN in Windows + proxy in WSL2

If you need access to resources only through a VPN without affecting the entire Windows system, you can:

  1. Connect to VPN in Windows
  2. Set up a proxy server in WSL2 pointing to the local VPN interface
  3. Route the required traffic through this proxy

Option 2: Using Docker in WSL2

bash
# Install Docker in WSL2
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

# Run container with OpenVPN
docker run -d --name openvpn-client --cap-add=NET_ADMIN --device /dev/net/tun -v /path/to/config:/etc/openvpn openvpn

Option 3: Using Mullvad VPN in WSL2

For those looking for a ready-made solution, Mullvad provides official instructions for WSL2:

bash
# Add Mullvad repository
echo "deb https://repository.mullvad.net/debian/stable main" | sudo tee /etc/apt/sources.list.d/mullvad.list

# Install Mullvad
sudo apt update
sudo apt install mullvad-vpn

Sources

  1. OpenVPN client on WSL - Reddit discussion
  2. VPN Split Tunnel between Linux and Windows - Reddit
  3. Workaround for WSL2 network broken on VPN - GitHub gist
  4. How to route network traffic from WSL2 through a VPN connection - Stack Overflow
  5. WSL2 Proxy Setting - Medium article
  6. Routing traffic through OpenVPN using a local SOCKS proxy - Kiljan.org
  7. How to use host’s VPN on WSL - Reddit

Conclusion

  1. Traffic Isolation: An OpenVPN client in WSL2 does not affect the traffic of the Windows host system due to WSL2’s separate network architecture.

  2. Practical Implementation: To set up a SOCKS proxy in WSL2, you can use SSH tunnels, proxychains, or specialized utilities like Privoxy.

  3. Problem Resolution: The main challenges arise from routing conflicts and DNS issues, which are resolved by changing WSL2 settings and manually configuring network parameters.

  4. Alternative Approaches: Depending on your needs, you can use a combination of VPN in Windows + proxy in WSL2, Docker containers, or ready-made solutions like Mullvad VPN.

  5. Recommendation: Start with basic OpenVPN installation in WSL2 to verify traffic isolation, then proceed to set up a SOCKS proxy and route the required applications through this proxy.