READ ENTIRE GUIDE BEFORE YOU BEGIN
This is a tutorial which will enable you to run PIA OPENVPN on OpenWrt / Lede. First, I would suggest that you run PIA VPN with the recommended encryption algorithm which they have available - which is AES-128-CBC. See here: https://www.privateinternetaccess.com/pages/vpn-encryption
So let's get started. OK - I decided to put this up on the Forum as I could not find a tutorial anywhere with specific step by step instructions for getting PIA OPENVPN working with OpenWrt/ Lede. I use davidc502 firmware which is described as Moderately Customized LEDE Development Builds found here - https://davidc502sis.dynamic-dns.net/releases/ and here - https://davidc502sis.dynamic-dns.net/snapshots/ -- davidc502's forum found here - Davidc502- wrt1200ac wrt1900acx wrt3200acm wrt32x builds - Dave's builds are for Linksys WRT1900AC v1 Linksys WRT1900AC v2 Linksys WRT1900ACS Linksys WRT3200ACM Linksys WRT1200AC models ONLY !!! One of the many benefits of using Dave's custom firmware is that it comes with many pre-installed and configured software packages - including OpenVpn . For full list of packages see Dave's configuration seed found here - https://davidc502sis.dynamic-dns.net/releases/config.seed - However, the guide tutorial here will work on any and every OpenWrt/ Lede firmware based router. I also tested this with OpenWrt / Lede 18.06.0-rc1 found here - : ( download and do fresh install of squashfs-factory.img ) on your device for best performance ) https://downloads.openwrt.org/releases/18.06.0-rc1/
-
In Luci Gui go to System > Software, do update first ( ssh command opkg update )
then search for openvpn and install openvpn-openssl and luci-app-openvpn. ( uci ssh command - opkg install openvpn-openssl luci-app-openvpn )
These are necessary - Luci is GUI frontend for Openwrt - it comes pre-installed with davidc502's firmware. Also installed on OpenWrt / Lede 18.06.0-rc1 -
opkg install nano - if you need to install nano - ( if not already there / comes pre-installed in davidc502's builds ). SSH into router then type ( copy and paste ) -" nano /etc/config/openvpn " ( without parenthesis ) - erase all contents of file ( hold Ctrl + k ) and replace ( copy and paste ) with contents of config file below:
config openvpn 'myvpnc'
option enabled '1'
option client '1'
option port '1198'
option dev 'tun'
option proto 'udp'
option resolv_retry 'infinite'
option nobind '1'
option persist_key '1'
option persist_tun '1'
option ca '/etc/openvpn/ca.rsa.2048.crt'
option tls_client '1'
option remote_cert_tls 'server'
option auth_user_pass '/etc/openvpn/piavpn-login.pem'
option auth_nocache '1'
option compress 'lzo' # necessary for OpenVpn 2.4 and above
option verb '3'
option reneg_sec '0'
option keepalive '10 120'
option auth 'sha1'
option cipher 'aes-128-cbc'
option engine 'cryptodev'
option script_security '2'
list remote 'us-east.privateinternetaccess.com' # change to resolver of your choice if you wish
option tun_mtu_extra '32'
option float "0" # you can enable with '1' and list additional remote servers
option mute_replay_warnings '1'
option disable_occ '1'
option log '/tmp/openvpn.log'
Then hit Ctrl + o - you will be asked to write file - hit enter to save file - then Ctrl + x to close file and go back into shell
3 ) opkg install wget ( if you need to install wget ) ssh into router use wget ( install wget if not already there / comes pre-installed in davidc502's builds ) to issue following commands in order to install necessary credentials to /etc/openvpn/ for PIA OPENVPN successful connection
A ) wget -P /etc/openvpn https://www.privateinternetaccess.com/openvpn/ca.rsa.2048.crt
B ) Then enter nano /etc/openvpn/piavpn-login.pem ( here you will in the new file enter your PIA OPENVPN username on first line and PIA OPENVPN password on second line )
C ) Then hit ( Ctrl + o ) - you will be asked to write file - hit enter to save file - then ( Ctrl + x ) to close file and go back into shell - /piavpn-login.pem is now added under /etc/openvpn/ folder as well.
4 ) Change permissions to the files you downloaded and created:
A ) chmod 0777 /etc/openvpn/ca.rsa.2048.crt
B ) chmod 0400 /etc/openvpn/piavpn-login.pem
- Create a PIA OPENVPN Network Interface:
By way of SSH shell enter:
uci set network.myvpnc=interface
uci set network.myvpnc.proto=none
uci set network.myvpnc.ifname=tun0
uci commit network
- Create firewall rules for PIA OPENVPN:
By way of SSH shell enter:
uci add firewall zone
uci set firewall.@zone[-1]=zone
uci set firewall.@zone[-1].name=myvpnc_fw
uci set firewall.@zone[-1].network=myvpnc
uci set firewall.@zone[-1].input=REJECT
uci set firewall.@zone[-1].output=ACCEPT
uci set firewall.@zone[-1].forward=REJECT
uci set firewall.@zone[-1].masq=1
uci set firewall.@zone[-1].mtu_fix=1
uci add firewall forwarding
uci set firewall.@forwarding[-1]=forwarding
uci set firewall.@forwarding[-1].src=lan
uci set firewall.@forwarding[-1].dest=myvpnc_fw
uci commit firewall
-
Reboot your router with reboot; exit command
-
Optional Setup - YOU CAN NOT USE ONE ABOVE IN STEP 2 IF YOU USE THIS METHOD
You can select to use uci in SSH to create /etc/config/openvpn file if you prefer - commands are as follows:
uci set openvpn.myvpnc=openvpn
uci set openvpn.myvpnc.enabled=1
uci set openvpn.myvpnc.client=1
uci set openvpn.myvpnc.port='1198'
uci set openvpn.myvpnc.dev=tun
uci set openvpn.myvpnc.proto=udp
uci set openvpn.myvpnc.resolv_retry=infinite
uci set openvpn.myvpnc.nobind=1
uci set openvpn.myvpnc.persist_key=1
uci set openvpn.myvpnc.persist_tun=1
uci set openvpn.myvpnc.ca=/etc/openvpn/ca.rsa.2048.crt
uci set openvpn.myvpnc.tls_client=1
uci set openvpn.myvpnc.remote_cert_tls=server
uci set openvpn.myvpnc.auth_user_pass=/etc/openvpn/piavpn-login.pem
uci set openvpn.myvpnc.auth_nocache=1
uci set openvpn.myvpnc.compress=lzo
uci set openvpn.myvpnc.verb=3
uci set openvpn.myvpnc.reneg_sec=0
uci set openvpn.myvpnc.keepalive='10 120'
uci set openvpn.myvpnc.float=0
uci set openvpn.myvpnc.proto=udp
uci set openvpn.myvpnc.auth=sha1
uci set openvpn.myvpnc.cipher=aes-128-cbc
uci add_list openvpn.myvpnc.remote='us-east.privateinternetaccess.com'
uci commit openvpn
- Bonus Feature- For Adding DNS-Over-TLS support to OpenWRT (LEDE) with Unbound see here:
https://torguard.net/forums/index.php?/topic/1374-adding-dns-over-tls-support-to-openwrt-lede-with-unbound/ or here:
Adding DNS-Over-TLS support to OpenWrt (LEDE) with Unbound
Final Advice - I always setup DNS before configuring OPENVPN - I believe that this is the best way to proceed.