User Tools

Site Tools


docs:guide-user:services:vpn:openvpn:client

OpenVPN client

Introduction

  • This guide describes how to configure OpenWrt to run OpenVPN client.
  • You can use it to connect to your own OpenVPN server or a commercial OpenVPN provider.
  • Follow OpenVPN basic for server setup and OpenVPN extras for additional tuning.

Goals

  • Encrypt your internet connection to enforce security and privacy.
    • Prevent data leak and traffic spoofing on the client side.
  • Bypass regional restrictions using commercial providers.
    • Escape client side content filters and internet censorship.
  • Access your LAN services remotely without port forwarding.

Instructions

1. Firewall

Consider VPN network as public and assign VPN interface to WAN zone to minimize firewall setup.

# Configure firewall
uci set firewall.@zone[1].device="tun0"
uci commit firewall
service firewall restart

2. Basic client

Save your client profile. Install and configure VPN client. Drop VPN service privileges and ensure VPN interface name matches network configuration.

# Save VPN client profile
cat << "EOF" > /etc/openvpn/vpnclient.conf
COPY_PASTE_CLIENT_PROFILE_HERE
EOF
 
# Fix permissions
chmod "u=rw,g=,o=" /etc/openvpn/vpnclient.conf
 
# Install packages
opkg update
opkg install openvpn-openssl
 
# Configure VPN client
sed -i -e "
/^user/s/^/#/
\$a user nobody
/^group/s/^/#/
\$a group nogroup
/^dev/s/^/#/
\$a dev $(uci get firewall.@zone[1].device)
" /etc/openvpn/vpnclient.conf
service openvpn restart

3. Commercial provider

If using a commercial VPN provider, set up credentials for username/password authentication and enforce gateway redirect.

# Save username/password credentials
cat << "EOF" > /etc/openvpn/vpnclient.auth
YOUR_VPN_USERNAME
YOUR_VPN_PASSWORD
EOF
 
# Fix permissions
chmod "u=rw,g=,o=" /etc/openvpn/vpnclient.auth
 
# Configure VPN client
sed -i -e "
/^auth-user-pass/s/^/#/
\$a auth-user-pass /etc/openvpn/vpnclient.auth
/^redirect-gateway/s/^/#/
\$a redirect-gateway def1 ipv6
" /etc/openvpn/vpnclient.conf
service openvpn restart

See also: Instance management, DNS encryption

Testing

Establish VPN connection. Verify your client traffic is routed via VPN gateway.

traceroute openwrt.org
traceroute6 openwrt.org

Check your client public IP addresses.

Make sure there is no DNS leak on the client side.

Delegate a public IPv6 prefix to VPN6 network to use IPv6 by default.

Troubleshooting

Collect and analyze the following information.

# Restart the services, then try to reconnect
service log restart; service openvpn restart; sleep 10
 
# Log and status
logread -e openvpn; netstat -l -n -p | grep -e openvpn
 
# Runtime configuration
pgrep -f -a openvpn
ip addr show; ip route show; ip rule show; iptables-save
ip -6 addr show; ip -6 route show; ip -6 rule show; ip6tables-save
 
# Persistent configuration
uci show network; uci show firewall; uci show openvpn
head -n -0 /etc/openvpn/*.conf
docs/guide-user/services/vpn/openvpn/client.txt · Last modified: 2019/04/28 02:35 by vgaetera