> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ahmadraza.in/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenVPN SplitTunnel

# OpenVPN Setup Guide with Split Tunneling on Ubuntu

## Prerequisites

* Ubuntu 20.04 or later
* Root or sudo access
* OpenVPN server configuration files

## Step 1: Install OpenVPN

```bash theme={null}
sudo apt update
sudo apt install openvpn -y
```

## Step 2: Place Configuration Files

Copy your OpenVPN configuration files (e.g., `.ovpn`) to the `/etc/openvpn/client/` directory:

```bash theme={null}
sudo cp your-config.ovpn /etc/openvpn/client/
```

## Step 3: Configure Split Tunneling

Edit the OpenVPN client configuration file to enable split tunneling. Open the file:

```bash theme={null}
sudo nano /etc/openvpn/client/your-config.ovpn
```

### Modify the following settings:

1. **Prevent default gateway override**:
   ```bash theme={null}
   route-nopull
   ```
2. **Route only specific traffic through VPN** (e.g., a corporate network `10.0.0.0/24`):
   ```bash theme={null}
   route 10.0.0.0 255.255.255.0
   ```
3. **Ensure correct DNS resolution (Optional)**:
   ```bash theme={null}
   dhcp-option DNS 8.8.8.8
   dhcp-option DNS 8.8.4.4
   ```

## Step 4: Start OpenVPN Client

Run OpenVPN using the configuration file:

```bash theme={null}
sudo openvpn --config /etc/openvpn/client/your-config.ovpn --daemon
```

## Step 5: Verify VPN Connection

Check your IP to confirm split tunneling is working:

```bash theme={null}
curl ifconfig.me
```

To ensure only specific traffic is routed via VPN:

```bash theme={null}
ip route
```

## Step 6: Enable OpenVPN on Boot (Optional)

Create a systemd service file:

```bash theme={null}
sudo nano /etc/systemd/system/openvpn-client.service
```

Paste the following:

```ini theme={null}
[Unit]
Description=OpenVPN client
After=network.target

[Service]
ExecStart=/usr/sbin/openvpn --config /etc/openvpn/client/your-config.ovpn --daemon
Restart=always

[Install]
WantedBy=multi-user.target
```

Enable and start the service:

```bash theme={null}
sudo systemctl enable openvpn-client
sudo systemctl start openvpn-client
```

## Step 7: Disconnect OpenVPN

To disconnect, run:

```bash theme={null}
sudo systemctl stop openvpn-client
```

## Troubleshooting

* Check OpenVPN logs for errors:
  ```bash theme={null}
  journalctl -u openvpn-client --no-pager
  ```
* Restart OpenVPN service:
  ```bash theme={null}
  sudo systemctl restart openvpn-client
  ```
* Verify routing rules:
  ```bash theme={null}
  ip route show
  ```

## Conclusion

You have successfully configured OpenVPN with split tunneling on Ubuntu. Now, only specified traffic will pass through the VPN while the rest uses the local network.
