How to manually deploy IKEv1 with PSK and Xauth VPN using strongSwan on OpenWrt
Why IPSec/IKEv1 PSK + Xauth instead of IPSec/IKEv2 PSK
In built in vpn settings, after I choose IPSec/IKEv2 PSK, it asks me to input identifier, username and password mandatorily, which I did not know how to set in strongSwan. Though IPSec/IKEv1 PSK + Xauth VPN has lower security which could be brute-force attack offline, I believe using a 64 digital strong password is safe enough for me.
Manual IPSec VPN Deployment Guide
Based on luci-app-ipsec-vpnd source code analysis, this guide shows how to manually deploy IKEv1 with PSK and Xauth VPN using strongSwan on OpenWrt. This configuration replicates the exact functionality of luci-app-ipsec-vpnd without requiring the LuCI interface, making it compatible with official OpenWrt installations.
Step 1: Install Required Packages
1 | opkg update |
Step 2: Fix strongSwan UCI Plugin Issue
IMPORTANT: OpenWrt’s strongSwan uses a UCI plugin by default, but it often fails to load. We need to disable it first:
1 | # Disable the broken UCI plugin |
Step 3: Configure /etc/ipsec.conf
Create the main IPSec configuration file with vpn0 interface binding:
1 | vim /etc/ipsec.conf |
1 | # ipsec.conf - strongSwan IPsec configuration file |
Step 4: Configure /etc/ipsec.secrets
Set up authentication credentials:
1 | vim /etc/ipsec.secrets |
1 | # /etc/ipsec.secrets - strongSwan IPsec secrets file |
Step 5: Configure strongSwan daemon (/etc/strongswan.conf)
1 | vim /etc/strongswan.conf |
1 | # strongswan.conf - strongSwan configuration file |
Step 6: Enable IP Forwarding
1 | # Enable IP forwarding |
Step 7: Start and Test strongSwan Service
CRITICAL: You must completely stop any existing strongSwan processes first:
1 | # Stop strongSwan completely |
Expected output should show:
1 | Connections: |
Step 8: Configure VPN Interface for LuCI Monitoring
The kernel-libipsec
module automatically creates ipsec0 interface when VPN connections are established. Configure the network interface for LuCI monitoring:
1 | # Edit network configuration |
Add the VPN interface configuration to /etc/config/network
:
1 | # VPN interface configuration - manually created ipsec0 for monitoring |
Apply the network configuration:
1 | # Reload network configuration |
Step 9: Configure Firewall for VPN Traffic (Based on Official Implementation)
Edit the firewall configuration (based on official luci-app-ipsec-vpnd):
1 | # Edit firewall configuration with vim |
Add the following sections to your firewall config (following official implementation):
1 | # IPSec protocol rules (IKE) |
After editing, save and exit vim (:wq), then apply all configuration changes:
1 | # Reload firewall |
Key Parameters to Customize
Based on the source code analysis:
- Client IP Range: Uses
rightsourceip=10.10.10.100-10.10.10.200
(separate VPN subnet) - DNS Server: Set to
rightdns=192.168.5.1
(VPN gateway as DNS) - Pre-shared Key: Modify in
/etc/ipsec.secrets
- Username/Password: Add users in
/etc/ipsec.secrets
Client Configuration
For iOS/Android native clients, use these settings:
- Server: Your router’s public IP (e.g., 1.2.3.4)
- Account:
vpnuser
(from ipsec.secrets) - Password:
your_password_here
(from ipsec.secrets) - PSK:
your_preshared_key_here
(your PSK from ipsec.secrets)
Expected behavior:
- ✅ VPN connects successfully
- ✅ Can access internal LAN devices (e.g., 192.168.5.x)
- ✅ Can access internet sites
- ✅ VPN traffic visible in LuCI interface statistics
- ✅ ipsec0 interface shows automatically in Network > Interfaces with bandwidth graphs
Source Code Reference
This configuration is extracted from:
- Package:
luci-app-ipsec-vpnd
- Location:
/feeds/luci/applications/luci-app-ipsec-vpnd/
- Key files analyzed:
root/etc/init.d/ipsec-vpnd
(lines 382-412: ipsec.conf generation)root/etc/init.d/ipsec-vpnd
(lines 408-412: ipsec.secrets generation)root/etc/config/ipsec-vpnd
(default configuration values)htdocs/luci-static/resources/view/ipsec-vpnd.js
(web interface parameters)
Dependencies
For OpenWrt 24.10:
strongswan-full
- Full strongSwan package (replaces separate minimal packages)strongswan-mod-xauth-generic
- Xauth authentication modulestrongswan-mod-kernel-libipsec
- Kernel libipsec interface (creates ipsec0 for monitoring)kmod-tun
- TUN kernel module
OpenWrt 24.10 Specific Changes
- Uses
strongswan-full
instead of separate packages - Disables broken UCI plugin that prevents configuration loading
- Uses libipsec kernel interface to create ipsec0 for LuCI monitoring
- Separate VPN subnet (10.10.10.0/24) for better network isolation
- Enhanced firewall rules with explicit family settings and NAT
Security Notes
- Use strong passwords (minimum 20 characters)