Skip to content

harryd337/protonvpn-linux-split-tunneling

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ProtonVPN Split Tunneling for Linux

License: MIT Shell

Automated bash scripts for implementing split tunneling with ProtonVPN on Linux. This solution allows you to exclude specific IP addresses or network ranges from going through the VPN tunnel, routing them directly through your regular internet connection instead.

Split tunneling is a feature built-in to ProtonVPN on all other platforms, but unfortunately Proton have not prioritised implementing it for Linux, so this is my attempt to provide a workaround.

πŸš€ Features

  • Automatic Detection: Monitors ProtonVPN connection status and applies exclusions automatically
  • Network Resilience: Re-applies exclusions after system wake from suspension or network changes
  • Robust Monitoring: Handles manual VPN restarts and connection interruptions
  • Headless Compatible: Works on servers and headless systems with no desktop environment required
  • Systemd Integration: Runs as a system service with proper logging and error handling
  • Configurable: Easy-to-modify configuration file for managing exclusions

πŸ“‹ Requirements

  • Linux system with systemd
  • ProtonVPN client installed and configured
  • Root/sudo access for installation
  • ip, pgrep, and logger utilities (typically pre-installed)

βš™οΈ Configuration

The configuration file is located at /usr/local/etc/protonvpn-split-tunnel.conf and must be created before installation.

It must contain an EXCLUSIONS variable defining an array of the IP addresses/networks you want to exclude from the VPN tunnel.

Configuration Example

EXCLUSIONS=(
    "192.168.1.10/32"    # Single IP (local printer)
    "192.168.1.0/24"     # Entire local network
    "10.0.0.100/32"      # Work server
    "203.0.113.0/24"     # External service network
)

⚑ Installation

Step 1: Clone and Prepare

git clone https://github.com/harryd337/protonvpn-linux-split-tunneling.git
cd protonvpn-linux-split-tunneling
chmod +x install.sh

Step 2: Configure Your Split Tunnel Routes

⚠️ Important: You must create your configuration file before running the installer.

# Copy the example configuration
sudo cp examples/protonvpn-split-tunnel.conf.example /usr/local/etc/protonvpn-split-tunnel.conf

# Edit the configuration file
sudo nano /usr/local/etc/protonvpn-split-tunnel.conf

Configure your exclusions by editing the EXCLUSIONS array:

EXCLUSIONS=(
    "192.168.1.10/32"    # Your local printer
    "192.168.1.0/24"     # Your entire local network
    # Add your specific IPs/networks here
)

Step 3: Run the Installer

sudo ./install.sh

The installer will:

  1. Verify your configuration file exists
  2. Copy scripts to /usr/local/bin/
  3. Set up systemd services
  4. Enable and start the monitoring service

πŸ”§ Manual Usage

Start/Stop the Service

# Start the split tunnel service
sudo systemctl start protonvpn-split-tunnel.service

# Stop the split tunnel service
sudo systemctl stop protonvpn-split-tunnel.service

# Check service status
sudo systemctl status protonvpn-split-tunnel.service

Remove All Routes (Clean Slate)

# Stop the split tunnel service
sudo systemctl stop protonvpn-split-tunnel.service

# Remove all existing exclusion routes
sudo /usr/local/bin/protonvpn-split-tunnel-remove.sh

Manual Script Execution

# Apply exclusions manually
sudo /usr/local/bin/protonvpn-split-tunnel-add.sh

# Remove exclusions manually
sudo /usr/local/bin/protonvpn-split-tunnel-remove.sh

View Logs

# View real-time logs
sudo journalctl -u protonvpn-split-tunnel.service -f

# View recent logs
sudo journalctl -u protonvpn-split-tunnel.service -n 50

# Enable debug logging (temporary for current session)
sudo systemctl stop protonvpn-split-tunnel.service
sudo DEBUG=1 /usr/local/bin/protonvpn-split-tunnel-monitor.sh

# Or enable debug logging permanently by editing the service
sudo systemctl edit protonvpn-split-tunnel.service
# Add the following lines:
# [Service]
# Environment="DEBUG=1"
# Then restart: sudo systemctl restart protonvpn-split-tunnel.service

πŸ”„ Uninstallation

Automated Uninstall (Recommended)

Use the provided uninstall script for safe and complete removal:

chmod +x uninstall.sh
sudo ./uninstall.sh

The uninstall script will:

  • βœ… Stop and disable the systemd service
  • βœ… Clean up any existing split tunnel routes
  • βœ… Remove all installed scripts and service files
  • βœ… Optionally preserve your configuration file
  • βœ… Reload systemd daemon

Manual Uninstall

If you prefer to remove components manually:

# Stop and disable service
sudo systemctl stop protonvpn-split-tunnel.service
sudo systemctl disable protonvpn-split-tunnel.service

# Clean up routes (optional - run the removal script first)
sudo /usr/local/bin/protonvpn-split-tunnel-remove.sh

# Remove files
sudo rm -f /usr/local/bin/protonvpn-split-tunnel-add.sh
sudo rm -f /usr/local/bin/protonvpn-split-tunnel-remove.sh
sudo rm -f /usr/local/bin/protonvpn-split-tunnel-monitor.sh
sudo rm -f /usr/local/etc/protonvpn-split-tunnel.conf
sudo rm -f /etc/systemd/system/protonvpn-split-tunnel.service

# Reload systemd
sudo systemctl daemon-reload

πŸ“ Project Structure

protonvpn-linux-split-tunneling/
β”œβ”€β”€ scripts/                                    # Main executable scripts
β”‚   β”œβ”€β”€ protonvpn-split-tunnel-add.sh         # Adds route exclusions
β”‚   β”œβ”€β”€ protonvpn-split-tunnel-remove.sh      # Removes route exclusions
β”‚   └── protonvpn-split-tunnel-monitor.sh     # Main monitoring daemon
β”œβ”€β”€ examples/                                   # Configuration templates
β”‚   └── protonvpn-split-tunnel.conf.example   # Example configuration
β”œβ”€β”€ systemd/                                    # Systemd service files
β”‚   └── protonvpn-split-tunnel.service        # Main monitoring service
└── install.sh                                 # Installation script

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

Development

  • Follow bash best practices and shellcheck recommendations
  • Test on multiple Linux distributions
  • Update documentation for any new features
  • Ensure backward compatibility

Development Testing

Use the included dev-test.sh script for development and troubleshooting:

# Check all scripts for syntax errors
./dev-test.sh syntax-check

# Test configuration loading
./dev-test.sh test-config

# View current routing table and VPN status
./dev-test.sh show-routes
./dev-test.sh show-vpn
./dev-test.sh show-exclusions

# Simulate route additions (dry run)
./dev-test.sh simulate-add

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

⚠️ Disclaimer

This software is provided as-is. Use at your own risk. Always test in a safe environment before deploying to production systems.

πŸ™ Acknowledgments

  • ProtonVPN team for their excellent VPN service
  • Linux networking community for routing documentation
  • Contributors and users who provide feedback and improvements

About

Automated bash scripts for implementing split tunneling with ProtonVPN on Linux.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages