In this article, we'll explore solutions for a common issue where you lose your SSH connection to a server after initiating a VPN connection to a second server. This typically occurs because, in the default OpenVPN configuration, all outgoing traffic is routed through the VPN server.
We'll use the following terms in this tutorial:
PC: The device from which you're connecting
SERVER1: Your first server
Second Server: Your VPN server
Solution 1: Direct Traffic Through Your PC
To ensure your traffic is routed directly through your PC and not the VPN, add a route for your PC's IP address. This allows you to connect to the server only from the IP address of your device. Run the following command while connected to your VPS via SSH:
For Container and Storage VPS:

For Linux VPS:

Note: Replace "PC-IP" with your device's IP address.
Solution 2: Advanced Configuration
For more advanced users, you can mark traffic to a specific port so that it is routed directly to the server (as it was before setting up the VPN) instead of through the VPN.
For Container and Storage VPS:
1. Disable rp_filter:

2. Create iptables rules:

For Linux VPS:
1. Create iptables rules:

Note: You can change the port from 22 to another port, such as 80 or 443, to make other services on your first server accessible from outside.
If you want traffic to a specific IP (or port) to bypass the VPN, use the following iptables rules (example for Container and Storage VPS):
