[SOLVED] Issue when creating OpenVPN Server via scripts on OpenWrt 18: OpenWrt Router goes offline requiring system restore

Hello Community,

I want to apologize in advance for this monsterious post. If it is catergorized incorrectly or posted in the wrong forum, please let me know rather than down-voting me and I will follow the proper protocol and procedures.

Before we begin, here is my network topology:
image

I have been trying to configure my Linksys WRT 3200ACM router to serve as my OpenVPN server so I can free up one of my Raspberry Pis. I noticed that the OpenVPN (Server Setup) and the OpenVPN Server (Comprehensive) wiki are no longer available so I followed along with the OpenVPN Basic wiki tutorial.

The tutorial has me follow three scripts (if this is an old post that I am not supposed to follow please let me know).

  1. create-certs.sh
  2. create-configs.sh
  3. create-ovpn.sh

I am able to run the first script, create-certs.sh, fine without any problems I can detect.

However, there were some complications when running 2 and 3. When I run the 2nd script, create-configs.sh and reload the network/firewall or reboot the router, the router is inaccessible, not able to be pinged, loss of internet connectivity, and dhcp service does not distribute IP address.

The issues I have with the 3rd script, create-ovpn.sh, I notice that some configurations are missing in the *.ovpn file i.e. it will not list the dev, port number next to the ddns address, and there could be more I am not aware of.

Of course, my network is not standard in the way these scripts are meant to be performed on. So I had to, unfortunately, modify them to meet my use-case. I have three networks, each on their own respective vlan. I am starting with creating a vpn connection to my private lan interface. If that works, I would like to eventually edit the scripts to create the configs necessary to create remote-accessible vpn connections to connect to the other networks.

My current interfaces/networks are:

  • lan = my private network
  • slave = guest network
  • tor = my tor network

The minor changes I made to the scripts was naming the vpnserver as their respective network they would connect to and the IP addresses/subnet they would be members of i.e. lan_vpnserver, 192.168.0.0/C, etc.

I tried breaking down the 2nd script and running the uci set commands individually, restarting the router after every input to try and isolate the root cause. It looks like the network and firewall redirect configs may be the culprit in causing my router to go offline.

My edited scripts are listed below (I have made comments on the areas I have changed):
Note: I have tried running the 2 script without changing vpnserver to lan_vpnserver and I still experience the same issue

01.create-certs.lan.sh
#!/bin/sh
 
# Installing packages
opkg update
opkg install openssl-util openvpn-openssl
 
# Creating Directory Structure
VPN_DIR="/etc/openvpn/lan"                                #added dir lan for orginizational purposes
PKI_DIR="$VPN_DIR/ssl"
 
if [ -d "$PKI_DIR" ]
then
    rm -rf "$PKI_DIR"
fi
mkdir -p "$PKI_DIR"
chmod -R 600 "$PKI_DIR"
cd "$PKI_DIR"
touch index.txt index
echo 1000 > serial
cp -f /etc/ssl/openssl.cnf "$PKI_DIR"
 
# Customizing openssl.cnf
PKI_CONF="$PKI_DIR/openssl.cnf"
 
sed -i "
                              s:\\\\:/:g
/^dir/                        s:=.*:= $PKI_DIR:
/^new_certs_dir/              s:=.*:= $PKI_DIR:
/.*Name/                      s:= match:= optional:
/organizationName_default/    s:= .*:= OG.Infraverse:
/stateOrProvinceName_default/ s:= .*:= Yorkshire:
/countryName_default/         s:= .*:= UK:
/default_days/                s:=.*:= 3650:
/default_bits/                s:=.*:= 4096:
" "$PKI_CONF"
 
cat << "EOF" >> "$PKI_CONF"
[ lan_vpnserver ]
  keyUsage = digitalSignature, keyEncipherment
  extendedKeyUsage = serverAuth
 
[ lan_vpnclient ]
  keyUsage = digitalSignature
  extendedKeyUsage = clientAuth
EOF
 
# Generating Server PSK and CA, Server, & Client Certs
# Generating Certifcate Authority Cert & Key
openssl req -batch -nodes -new -keyout "ca.key" -out "ca.crt" -x509 -config "$PKI_CONF" -days "3650"

#changed vpnserver/vpnclient to lan_vpnserver/lan_client

# Generating Server Cert & Key
openssl req -batch -nodes -new -keyout "lan_vpnserver.key" -out "lan_vpnserver.csr" -subj "/CN=lan_vpnserver" -config "$PKI_CONF"       
# Signing Server Cert
openssl ca  -batch -keyfile "ca.key" -cert "ca.crt" -in "lan_vpnserver.csr" -out "lan_vpnserver.crt" -config "$PKI_CONF" -extensions "lan_vpnserver"
# Generating Client Cert & Key
# PASSPHRASE MUST BE SET (4 chars minimum, 16+ chars recommended)
openssl req -batch -new -keyout "lan_vpnclient.key" -out "lan_vpnclient.csr" -subj "/CN=lan_vpnclient" -config "$PKI_CONF"
# Signing Client Cert
openssl ca  -batch -keyfile "ca.key" -cert "ca.crt" -in "lan_vpnclient.csr" -out "lan_vpnclient.crt" -config "$PKI_CONF" -extensions "lan_vpnclient"
 
# Generating OpenVPN TLS PSK
openvpn --genkey --secret "tc.pem"
 
# Generating Diffie-Hellman Cert
# May take a while to complete (~25m on WRT3200ACM)
openssl dhparam -out "dh.pem" 2048
 
# Correcting Permissions
chmod 600 tc.pem dh.pem ca.key lan_vpnserver.key lan_vpnclient.key
 
# Copying Certs & Keys to $VPN_DIR
cp tc.pem dh.pem ca.crt lan_vpnserver.* lan_vpnclient.* "$VPN_DIR"
 
# Returning to initial working directory
cd -
 
# Done
02.create-configs.lan.sh
#!/bin/sh
 
# Installing packages
opkg update
opkg install openvpn-openssl luci-app-openvpn
 
# Configuring network
uci set network.lan_vpnserver="interface"
uci set network.lan_vpnserver.ifname="tun0"
uci set network.lan_vpnserver.proto="none"
uci commit network
 
# Configuring firewall
uci add firewall rule
uci set firewall.@rule[-1].name="Allow-LAN-OpenVPN"
uci set firewall.@rule[-1].src="wan"
uci set firewall.@rule[-1].dest_port="1999"                    #custom port for the vpn
uci set firewall.@rule[-1].proto="tcp udp"
uci set firewall.@rule[-1].target="ACCEPT"
 
uci add firewall zone
uci set firewall.@zone[-1].name="lan_vpnserver"
uci add_list firewall.@zone[-1].network="lan_vpnserver"
uci set firewall.@zone[-1].input="ACCEPT"
uci set firewall.@zone[-1].output="ACCEPT"
uci set firewall.@zone[-1].forward="REJECT"
 
uci add firewall forwarding
uci set firewall.@forwarding[-1].src="lan_vpnserver"
uci set firewall.@forwarding[-1].dest="wan"
 
uci add firewall forwarding
uci set firewall.@forwarding[-1].src="lan_vpnserver"
uci set firewall.@forwarding[-1].dest="lan"
uci commit firewall
 
# Configuring OpenVPN Server
VPN_DIR="/etc/openvpn/lan"                                             #added dir lan for orginizational purposes
uci set openvpn.lan_vpnserver="openvpn"
uci set openvpn.lan_vpnserver.enabled="1"
uci set openvpn.lan_vpnserver.verb="3"
uci set openvpn.lan_vpnserver.dev="tun0"
uci set openvpn.lan_vpnserver.topology="subnet"
uci set openvpn.lan_vpnserver.port="1999"
uci set openvpn.lan_vpnserver.proto="udp"
uci set openvpn.lan_vpnserver.server="192.168.200.0 255.255.255.0"
uci set openvpn.lan_vpnserver.client_to_client="1"
uci set openvpn.lan_vpnserver.compress="lzo"
uci set openvpn.lan_vpnserver.keepalive="10 120"
uci set openvpn.lan_vpnserver.persist_tun="1"
uci set openvpn.lan_vpnserver.persist_key="1"
uci set openvpn.lan_vpnserver.dh="$VPN_DIR/dh.pem"
uci set openvpn.lan_vpnserver.tls_crypt="$VPN_DIR/tc.pem"
uci set openvpn.lan_vpnserver.ca="$VPN_DIR/ca.crt"
uci set openvpn.lan_vpnserver.cert="$VPN_DIR/lan_vpnserver.crt"
uci set openvpn.lan_vpnserver.key="$VPN_DIR/lan_vpnserver.key"
 
uci add_list openvpn.lan_vpnserver.push="redirect-gateway def1"
uci add_list openvpn.lan_vpnserver.push="route 192.168.0.0 255.255.255.0"
uci add_list openvpn.lan_vpnserver.push="dhcp-option DNS 192.168.0.1"
uci add_list openvpn.lan_vpnserver.push="compress lzo"
uci add_list openvpn.lan_vpnserver.push="persist-tun"
uci add_list openvpn.lan_vpnserver.push="persist-key"
 
VPN_DOMAIN="$(uci -q get dhcp.@dnsmasq[0].domain)"
if [ -n "$VPN_DOMAIN" ]
then
    uci add_list openvpn.lan_vpnserver.push="dhcp-option DOMAIN $VPN_DOMAIN"
fi
uci commit openvpn
 
# Restarting services
service network restart
sleep 5
service firewall restart
sleep 5
service openvpn restart
 
# Done
03.create-ovpn.lan.sh
#!/bin/sh
 
# Obtaining server address from WAN-interface IP
source /lib/functions/network.sh
network_find_wan WAN_IF
network_get_ipaddr SERVER_ADDR "$WAN_IF"
 
# Obtaining server address from DDNS client service
SERVER_FQDN="$(uci -q get $(uci -q show ddns \
    | sed -n -e "s/^\(.*\)\.enabled='1'$/\1/p" \
    | head -n 1).lookup_host)"
if [ -n "$SERVER_FQDN" ]
then
    SERVER_ADDR="$SERVER_FQDN"
fi
 
# Setting configuration parameters
SERVER_PORT="$(uci get openvpn.lan_vpnclient.port)"               #changed vpnclient => lan_vpnclient
SERVER_PROTO="$(uci get openvpn.lan_vpnclient.proto)"               #changed vpnclient => lan_vpnclient
CLIENT_DEV="$(uci get openvpn.lan_vpnclient.dev | sed -e "s/\d*$//")"               #changed vpnclient => lan_vpnclient
CLIENT_COMPR="$(uci get openvpn.lan_vpnclient.compress)"               #changed vpnclient => lan_vpnclient
VPN_DIR="/etc/openvpn/lan"                                                   #added dir lan for orginizational purposes
TC_KEY="$(sed -e "/^#/d;/^\w/N;s/\n//" "$VPN_DIR/tc.pem")"
CA_CERT="$(openssl x509 -in "$VPN_DIR/ca.crt")"
 
# Generating .ovpn-files
grep -l -e "TLS Web Client Authentication" "$VPN_DIR"/*.crt \
| sed -e "s/^.*\///;s/\.[^.]*$//" \
| while read CLIENT_ID
do
CLIENT_CERT="$(openssl x509 -in "$VPN_DIR/$CLIENT_ID.crt")"
CLIENT_KEY="$(cat "$VPN_DIR/$CLIENT_ID.key")"
CLIENT_CONF="$VPN_DIR/$CLIENT_ID.ovpn"
cat << EOF > "$CLIENT_CONF"
verb 3
nobind
dev $CLIENT_DEV
client
remote $SERVER_ADDR $SERVER_PORT $SERVER_PROTO
fast-io
compress $CLIENT_COMPR
auth-nocache
remote-cert-tls server
<tls-crypt>
$TC_KEY
</tls-crypt>
<ca>
$CA_CERT
</ca>
<cert>
$CLIENT_CERT
</cert>
<key>
$CLIENT_KEY
</key>
EOF
done
 
# Setting permissions
chmod 600 "$VPN_DIR"/*.ovpn
 
# Showing generated .ovpn-files
head -v -n -0 "$VPN_DIR"/*.ovpn
 
# Done
Output of 3rd script

verb 3
nobind
dev #the device is missing, i think this would need to match the config on the server/script which would be "tun"
client
remote my.domainname.com 1999 
fast-io
compress 
auth-nocache
remote-cert-tls server
<tls-crypt>
-----BEGIN OpenVPN Static key V1-----
d37...ef1a
-----END OpenVPN Static key V1-----
</tls-crypt>
<ca>
-----BEGIN CERTIFICATE-----
MII...qKP
-----END CERTIFICATE-----
</ca>
<cert>
-----BEGIN CERTIFICATE-----
MII...eYH
-----END CERTIFICATE-----
</cert>
<key>
-----BEGIN ENCRYPTED PRIVATE KEY-----
MII...M8=
-----END ENCRYPTED PRIVATE KEY-----
</key>

Current Configs before running the script.

Network:
config interface 'loopback'
	option ifname 'lo'
	option proto 'static'
	option ipaddr '127.0.0.1'
	option netmask '255.0.0.0'

config globals 'globals'
	option ula_prefix 'fdfb:7e04:aca7::/48'

config interface 'lan'
	option type 'bridge'
	option ifname 'eth0.1'
	option proto 'static'
	option netmask '255.255.255.0'
	option ip6assign '60'
	option ipaddr '192.168.0.1'
	option gateway '192.168.0.1'
	option broadcast '192.168.0.255'
	option dns '8.8.8.8'

config interface 'wan'
	option ifname 'eth1.2'
	option proto 'dhcp'
	option hostname 'infraverse.network'

config interface 'wan6'
	option ifname 'eth1.2'
	option proto 'dhcpv6'

config switch
	option name 'switch0'
	option reset '1'
	option enable_vlan '1'

config switch_vlan
	option device 'switch0'
	option vlan '1'
	option vid '1'
	option ports '0t 1 2 3 5t'

config switch_vlan
	option device 'switch0'
	option vlan '2'
	option ports '4 6t'
	option vid '2'

config interface 'slave'
	option type 'bridge'
	option proto 'static'
	option ipaddr '172.16.0.1'
	option netmask '255.255.0.0'
	option ifname 'eth0.3 radio1'
	option gateway '172.16.0.1'
	option broadcast '172.16.255.255'

config interface 'tor'
	option proto 'static'
	option ipaddr '10.1.1.1'
	option netmask '255.0.0.0'
	option type 'bridge'
	option ifname 'eth0.4'

config switch_vlan
	option device 'switch0'
	option vlan '3'
	option vid '3'
	option ports '0t 5t'

config switch_vlan
	option device 'switch0'
	option vlan '4'
	option vid '4'
	option ports '0t 5t'
dhcp:

config dnsmasq
	option domainneeded '1'
	option localise_queries '1'
	option rebind_protection '1'
	option rebind_localhost '1'
	option local '/lan/'
	option domain 'lan'
	option expandhosts '1'
	option authoritative '1'
	option readethers '1'
	option leasefile '/tmp/dhcp.leases'
	option resolvfile '/tmp/resolv.conf.auto'
	option nonwildcard '1'
	option localservice '1'
	option serversfile '/tmp/adb_list.overall'
        list server '8.8.8.8'
        list server '8.8.4.4'

config dhcp 'lan'
	option interface 'lan'
	option leasetime '12h'
	option dhcpv6 'server'
	option ra 'server'
	option start '2'
	option limit '254'
	option ra_management '1'

config dhcp 'slave'
	option leasetime '12h'
	option interface 'slave'
	option start '2'
	option limit '254'

config dhcp 'tor'
	option leasetime '12h'
	option interface 'tor'
	option start '2'
	option limit '254'

config dhcp 'wan'
	option interface 'wan'
	option ignore '1'

config odhcpd 'odhcpd'
	option maindhcp '0'
	option leasefile '/tmp/hosts/odhcpd'
	option leasetrigger '/usr/sbin/odhcpd-update'
	option loglevel '4'
Firewall:

config defaults
	option syn_flood '1'
	option input 'ACCEPT'
	option output 'ACCEPT'
	option forward 'REJECT'

config zone
	option name 'lan'
	list network 'lan'
	option input 'ACCEPT'
	option output 'ACCEPT'
	option forward 'ACCEPT'

config zone
	option name 'wan'
	list network 'wan'
	list network 'wan6'
	option input 'REJECT'
	option output 'ACCEPT'
	option forward 'REJECT'
	option masq '1'
	option mtu_fix '1'

config forwarding
	option src 'lan'
	option dest 'wan'

config rule
	option name 'Allow-DHCP-Renew'
	option src 'wan'
	option proto 'udp'
	option dest_port '68'
	option target 'ACCEPT'
	option family 'ipv4'

config rule
	option name 'Allow-Ping'
	option src 'wan'
	option proto 'icmp'
	option icmp_type 'echo-request'
	option family 'ipv4'
	option target 'ACCEPT'

config rule
	option name 'Allow-IGMP'
	option src 'wan'
	option proto 'igmp'
	option family 'ipv4'
	option target 'ACCEPT'

config rule
	option name 'Allow-DHCPv6'
	option src 'wan'
	option proto 'udp'
	option src_ip 'fc00::/6'
	option dest_ip 'fc00::/6'
	option dest_port '546'
	option family 'ipv6'
	option target 'ACCEPT'

config rule
	option name 'Allow-MLD'
	option src 'wan'
	option proto 'icmp'
	option src_ip 'fe80::/10'
	list icmp_type '130/0'
	list icmp_type '131/0'
	list icmp_type '132/0'
	list icmp_type '143/0'
	option family 'ipv6'
	option target 'ACCEPT'

config rule
	option name 'Allow-ICMPv6-Input'
	option src 'wan'
	option proto 'icmp'
	list icmp_type 'echo-request'
	list icmp_type 'echo-reply'
	list icmp_type 'destination-unreachable'
	list icmp_type 'packet-too-big'
	list icmp_type 'time-exceeded'
	list icmp_type 'bad-header'
	list icmp_type 'unknown-header-type'
	list icmp_type 'router-solicitation'
	list icmp_type 'neighbour-solicitation'
	list icmp_type 'router-advertisement'
	list icmp_type 'neighbour-advertisement'
	option limit '1000/sec'
	option family 'ipv6'
	option target 'ACCEPT'

config rule
	option name 'Allow-ICMPv6-Forward'
	option src 'wan'
	option dest '*'
	option proto 'icmp'
	list icmp_type 'echo-request'
	list icmp_type 'echo-reply'
	list icmp_type 'destination-unreachable'
	list icmp_type 'packet-too-big'
	list icmp_type 'time-exceeded'
	list icmp_type 'bad-header'
	list icmp_type 'unknown-header-type'
	option limit '1000/sec'
	option family 'ipv6'
	option target 'ACCEPT'

config rule
	option name 'Allow-IPSec-ESP'
	option src 'wan'
	option dest 'lan'
	option proto 'esp'
	option target 'ACCEPT'

config rule
	option name 'Allow-ISAKMP'
	option src 'wan'
	option dest 'lan'
	option dest_port '500'
	option proto 'udp'
	option target 'ACCEPT'

config include
	option path '/etc/firewall.user'

config include 'miniupnpd'
	option type 'script'
	option path '/usr/share/miniupnpd/firewall.include'
	option family 'any'
	option reload '1'

config zone
	option name 'slave'
	option forward 'REJECT'
	option output 'ACCEPT'
	option network 'slave'
	option input 'REJECT'

config forwarding
	option dest 'wan'
	option src 'slave'

config rule
	option target 'ACCEPT'
	option proto 'tcp udp'
	option dest_port '53'
	option name 'Slave dns'
	option src 'slave'

config rule
	option target 'ACCEPT'
	option proto 'udp'
	option dest_port '67-68'
	option name 'slave dhcp'
	option src 'slave'

config zone
	option name 'tor'
	option forward 'REJECT'
	option output 'ACCEPT'
	option network 'tor'
	option input 'ACCEPT'
	option syn_flood '1'
	option conntrack '1'

config forwarding
	option dest 'wan'
	option src 'tor'

config forwarding
	option src 'wan'
	option dest 'tor'

config rule
	option src 'tor'
	option proto 'udp'
	option dest_port '67'
	option target 'ACCEPT'

config rule
	option src 'tor'
	option proto 'tcp'
	option dest_port '9040'
	option target 'ACCEPT'

config rule
	option src 'tor'
	option proto 'udp'
	option dest_port '9053'
	option target 'ACCEPT'

config redirect
	option name 'Redirect-Tor-Traffic'
	option src 'tor'
	option src_dip '!10.1.1.1'
	option dest_port '9040'
	option proto 'tcp'
	option target 'DNAT'

config redirect
	option name 'Redirect-Tor-DNS'
	option src 'tor'
	option src_dport '53'
	option dest_port '9053'
	option proto 'udp'
	option target 'DNAT'

I am not able to grab the logs after I run the 2nd and 3rd scripts. After I run the scripts, it renders my router offline since the second script reloads/restarts firewall and network which prohibits me from connecting to it to extract the logs.

If you need the configs of what it looks like after I run the scripts, let me know. I will re-run it on the router again with the reload/restart commented to grab them. I do not have it on me since I had to blow away my router and reload its backup.

I did notice after individually running each uci set command for the network section in the 2nd script and rebooting the router is what causes the issue. I notice the VPN interface has only two lines and it appends to the config file and adds it to the bottom underneath the vlan/switch config. Would this conflict if it puts it at the bottom of the vlan/switch config? would the vlan/switch config need to be the last lines of the network config file?

Are these scripts still applicable to OpenWrt 18?

I wouldn't be surprised if the minor changes I made to the script is causing these issues. I know running the scripts in the original form is best practice but if the original script works, how would I correctly create other vpns to connect with the other vlans/network interfaces? can the scripts be repurposed and reused in that case?

Thank you for your patience in allowing me to describe my predicament in detail. Any help would greatly be appreciated.

Sincerely,

A humbely committed student

You may wish to follow this thread, I just asked a similar question:

1 Like

Thank you lleachii, I am currently following a number of similar threads on the topic and I am always open for more information. Thank you for providing another area where a possible solution may arise.

1 Like

Yes.

You mean that?

uci set network.lan_vpnserver="interface"
uci set network.lan_vpnserver.ifname="tun0"
uci set network.lan_vpnserver.proto="none"
uci commit network
service network restart

It shouldn't cause any problems, unless there's some UCI network configuration parsing error or bad block on the disk.

Hello @vgaetera

I think you may be correct, I did try it on another router, same model and trying to recreate my test case.

Is there a way to repair or check to see if uci is having network configuration parsing errors or bad blocks on the disk?

As far as a second pair of eyes are concerned, is there any problems you can see from my slightly edited scripts?

Update: I applied the firewall uci set commands and rebooted on my test router, and it knocked it offline.
segment of uci commands ran:

# Configuring firewall
# Configuring firewall
uci add firewall rule
uci set firewall.@rule[-1].name="Allow-LAN-OpenVPN"
uci set firewall.@rule[-1].src="wan"
uci set firewall.@rule[-1].dest_port="1999"
uci set firewall.@rule[-1].proto="tcp udp"
uci set firewall.@rule[-1].target="ACCEPT"
 
uci add firewall zone
uci set firewall.@zone[-1].name="lan_vpnserver"
uci add_list firewall.@zone[-1].network="lan_vpnserver"
uci set firewall.@zone[-1].input="ACCEPT"
uci set firewall.@zone[-1].output="ACCEPT"
uci set firewall.@zone[-1].forward="REJECT"
 
uci add firewall forwarding
uci set firewall.@forwarding[-1].src="lan_vpnserver"
uci set firewall.@forwarding[-1].dest="wan"
 
uci add firewall forwarding
uci set firewall.@forwarding[-1].src="lan_vpnserver"
uci set firewall.@forwarding[-1].dest="lan"
uci commit firewall
 
firewall output in /etc/firewall:

config rule
        option name 'Allow-LAN-OpenVPN'
        option src 'wan'
        option dest_port '1999'
        option proto 'tcp udp'
        option target 'ACCEPT'

config zone
        option name 'lan_vpnserver'
        list network 'lan_vpnserver'
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'REJECT'

config forwarding
        option src 'lan_vpnserver'
        option dest 'wan'

config forwarding
        option src 'lan_vpnserver'
        option dest 'lan'

Script 3 sets up a router to be a VPN client. Why are you running that at all when you want to create a server?

Since you have the server running on a Pi already I suggest you copy your certs and config files over to the router. Then change the firewall to open port 1999 locally (instead of forwarding it to the Pi).

Hello @mk24

Thank you for your reply. You are correct that the script creates a VPN client, it is grabbing the cert info that was generated on the server and dumping it to a *.ovpn file that I will then export via winscp from the router and download it to my computer (or distribute to an end user).

That is an idea to explore with extracting the pi certs, but I kind of wanted to do this all off the router so that I can reproduce this all from one device in the future.

In addition, I am also wanting to generate certs/configs for the other networks/vlans I have on the router.

No, it just creates ovpn-profiles for clients.

thank you @anon50098793 for your reply.

to confirm you wanted me to not run these commands correct?:

uci set network.lan_vpnserver="interface"
uci set network.lan_vpnserver.ifname="tun0"
uci set network.lan_vpnserver.proto="none"
uci commit network

I am unfortunately not working with a router that has a console/serial port :frowning:

In your statement

were you saying you came across a similar error and you ended up having to recompile a new openwrt image to resolve this?

For this statement,

were you meaning that while you were working on recompiling an openwrt images, you found this post and ended up stopping your work to do more research?

forgive me for my noobness but I am a little loss at this part,

In the part where you say,

I do not have a serial or console connection on this device. is there a method to add one? is it a soldering method or is there a cool little trick to use the usb port in the device to accomplish this?

Would you kindly provide details on how you disabled "kernel panicks" on the tun driver or point me in the right direction?

Thanks again for your help and patience with my ignorance.

What I meant was... my openvpn works now.

Previously my router crashed.... and I feel it's either because of;

-no manual definition of the tun interface in /etc/config/network
-my reversion 18.06.1
-altering one of ( udp to tcp, lzo ) in the config file
-using openvpn-ssl instead of openvpn-mbedtls

They are really quick things for you to test. Change one at a time and see how it goes. Edit: It's not the tun definition.... looking more like mbed / tun version / cypto crash....

I suppose disable panicks was putting it wrong..... and was more thinking from the point of view of the software and troubleshooting it.

Can you post output of;

cat /sys/kernel/debug/crashlog ( if you can generate one )
or versions of your related packages?

@anon50098793,

would it be cool to post your configs and corresponding commands you used to resolve it on your end?

when you mentioned

did you mean that you manually typed in the info to the config file?

cat os-release
root@OpenWrt:/etc# cat os-release
NAME="OpenWrt"
VERSION="18.06.1"
ID="openwrt"
ID_LIKE="lede openwrt"
PRETTY_NAME="OpenWrt 18.06.1"
VERSION_ID="18.06.1"
HOME_URL="http://openwrt.org/"
BUG_URL="http://bugs.openwrt.org/"
SUPPORT_URL="http://forum.lede-project.org/"
BUILD_ID="r7258-5eb055306f"
LEDE_BOARD="mvebu/cortexa9"
LEDE_ARCH="arm_cortex-a9_vfpv3"
LEDE_TAINTS=""
LEDE_DEVICE_MANUFACTURER="OpenWrt"
LEDE_DEVICE_MANUFACTURER_URL="http://openwrt.org/"
LEDE_DEVICE_PRODUCT="Generic"
LEDE_DEVICE_REVISION="v0"
LEDE_RELEASE="OpenWrt 18.06.1 r7258-5eb055306f"

opkg list
root@OpenWrt:/etc/opkg# opkg list
base-files - 192-r7258-5eb055306f
busybox - 1.28.3-4
dnsmasq - 2.80test3-1
dropbear - 2017.75-5
firewall - 2018-07-26-aa8846bb-1
fstools - 2018-04-16-e2436836-1
fwtool - 1
hostapd-common - 2018-04-09-fa617ee6-5
ip6tables - 1.6.2-1
iptables - 1.6.2-1
iw - 4.14-1
iwinfo - 2018-07-24-94b1366d-1
jshn - 2018-07-25-c83a84af-1
jsonfilter - 2018-02-04-c7e938d6-1
kernel - 4.14.63-1-c0354e0486370ffeacebcc4352595371
kmod-bluetooth - 4.14.63-1
kmod-btmrvl - 4.14.63-1
kmod-cfg80211 - 4.14.63+2017-11-01-9
kmod-crypto-acompress - 4.14.63-1
kmod-crypto-aead - 4.14.63-1
kmod-crypto-cmac - 4.14.63-1
kmod-crypto-ecb - 4.14.63-1
kmod-crypto-ecdh - 4.14.63-1
kmod-crypto-hash - 4.14.63-1
kmod-crypto-kpp - 4.14.63-1
kmod-crypto-manager - 4.14.63-1
kmod-crypto-null - 4.14.63-1
kmod-crypto-pcompress - 4.14.63-1
kmod-gpio-button-hotplug - 4.14.63-2
kmod-hid - 4.14.63-1
kmod-i2c-core - 4.14.63-1
kmod-input-core - 4.14.63-1
kmod-input-evdev - 4.14.63-1
kmod-ip6tables - 4.14.63-1
kmod-ipt-conntrack - 4.14.63-1
kmod-ipt-core - 4.14.63-1
kmod-ipt-nat - 4.14.63-1
kmod-ipt-offload - 4.14.63-1
kmod-lib-crc-ccitt - 4.14.63-1
kmod-lib-crc16 - 4.14.63-1
kmod-lib-lzo - 4.14.63-1
kmod-mac80211 - 4.14.63+2017-11-01-9
kmod-mmc - 4.14.63-1
kmod-mwifiex-sdio - 4.14.63+2017-11-01-9
kmod-mwlwifi - 4.14.63+2018-06-15-8683de8e-1
kmod-nf-conntrack - 4.14.63-1
kmod-nf-conntrack6 - 4.14.63-1
kmod-nf-flow - 4.14.63-1
kmod-nf-ipt - 4.14.63-1
kmod-nf-ipt6 - 4.14.63-1
kmod-nf-nat - 4.14.63-1
kmod-nf-reject - 4.14.63-1
kmod-nf-reject6 - 4.14.63-1
kmod-nls-base - 4.14.63-1
kmod-ppp - 4.14.63-1
kmod-pppoe - 4.14.63-1
kmod-pppox - 4.14.63-1
kmod-regmap - 4.14.63-1
kmod-slhc - 4.14.63-1
kmod-tun - 4.14.63-1
kmod-usb-core - 4.14.63-1
libblobmsg-json - 2018-07-25-c83a84af-1
libc - 1.1.19-1
libgcc - 7.3.0-1
libip4tc - 1.6.2-1
libip6tc - 1.6.2-1
libiwinfo - 2018-07-24-94b1366d-1
libiwinfo-lua - 2018-07-24-94b1366d-1
libjson-c - 0.12.1-1
libjson-script - 2018-07-25-c83a84af-1
liblua - 5.1.5-1
liblucihttp - 2018-05-18-cb119ded-1
liblucihttp-lua - 2018-05-18-cb119ded-1
liblzo - 2.10-1
libnl-tiny - 0.1-5
libopenssl - 1.0.2p-1
libpthread - 1.1.19-1
libubox - 2018-07-25-c83a84af-1
libubus - 2018-07-26-40e0931e-1
libubus-lua - 2018-07-26-40e0931e-1
libuci - 2018-08-11-4c8b4d6e-1
libuclient - 2018-08-03-ae1c656f-1
libuhttpd-openssl - 2.0.3-1
libustream-openssl - 2018-07-30-23a3f283-1
libxtables - 1.6.2-1
logd - 2018-02-14-128bc35f-2
lua - 5.1.5-1
luci - git-19.011.54896-1f423b1-1
luci-app-firewall - git-18.228.31946-f64b152-1
luci-app-openvpn - git-19.011.54896-1f423b1-1
luci-base - git-18.228.31946-f64b152-1
luci-lib-ip - git-18.228.31946-f64b152-1
luci-lib-jsonc - git-18.228.31946-f64b152-1
luci-lib-nixio - git-18.228.31946-f64b152-1
luci-mod-admin-full - git-18.228.31946-f64b152-1
luci-proto-ipv6 - git-18.228.31946-f64b152-1
luci-proto-ppp - git-18.228.31946-f64b152-1
luci-ssl-openssl - git-19.011.54896-1f423b1-1
luci-theme-bootstrap - git-18.228.31946-f64b152-1
luci-theme-material - git-19.011.54896-1f423b1-1
mtd - 23
mwifiex-sdio-firmware - 2017-09-06-a61ac5cf-1
mwlwifi-firmware-88w8964 - 2018-06-15-8683de8e-1
netifd - 2018-07-30-a0a1e52e-1
odhcp6c - 2018-07-14-67ae6a71-14
odhcpd-ipv6only - 1.10-1
openssl-util - 1.0.2p-1
openvpn-openssl - 2.4.5-4.2
openwrt-keyring - 2018-05-18-103a32e9-1
opkg - 2017-12-07-3b417b9f-2
ppp - 2.4.7-12
ppp-mod-pppoe - 2.4.7-12
procd - 2018-03-28-dfb68f85-1
rpcd - 2018-08-16-41333abe-1
rpcd-mod-rrdns - 20170710
swconfig - 11
ubi-utils - 2.0.2-1
uboot-envtools - 2018.03-1
ubox - 2018-02-14-128bc35f-2
ubus - 2018-07-26-40e0931e-1
ubusd - 2018-07-26-40e0931e-1
uci - 2018-08-11-4c8b4d6e-1
uclient-fetch - 2018-08-03-ae1c656f-1
uhttpd - 2018-06-26-796d42bc-1
usign - 2015-07-04-ef641914-1
wireless-regdb - 2017-10-20-4343d359
wpad-mini - 2018-04-09-fa617ee6-5
zlib - 1.2.11-2
root@OpenWrt:/etc/opkg#

I cannot post output of crashlog when I input the commands/configs that causes the crash because I get locked out of the router since it goes off line, but FWIW, when i checked the directory right before running the 2 script to create the configs for the a second vpn, there is no crashlog file.

Thanks for the info.... let me re-assess..... perhaps I jumped to the wrong conclusions re: your issue being the same as mine....

When you say

My current interfaces/networks are:

lan = my private network
slave = guest network
tor = my tor network

Which one is WAN?

It's your firewall allright!!!

UPDATE: I think I am on a lead here everyone. I ended up having to mix and match manually configuring the tunnel interfaces i.e. tun0, tun1, tun2, etc. via the web gui Luci and manually entering in the commands within the script on the CLI.

Here is the procedures I executed:

  1. On Luci: Network>interface>click ADD NEW INTERFACE button. Note: for some reason only the first vpn tun interface would retain the "unmanged" setting, the additional vpn tun interfaces I added would only retain a static setting. I had to manually ssh into the system and edit i.e. vi /etc/config/network to set proto to "none"

  2. click on newly created vpn interface edit button>click on firewall settings tab>add vpn interface. Note: be sure to check the firewall settings to see what interface is selected, for some reason it selected the first vpn interface I entered. In addition, the gui would not take long names for the tun interface and it would ask me to revert settings. eventually I was able to get it to work by making the interface names smaller. Another setting that would not take immediately was the interface in the firewall settings tab, which required me going to step 3, below to manually configure them.
    image
    image

  3. Network>firewall> and configured the vpn interfaces to access wan and lan interfaces
    image

  4. On CLI: Ran or excluted the following commands extracted from the scripts Note: I changed the naming convention on the scripts because I think for some reason it did not like single underscores "__" in the name as well as long interface names. I seperated the commands in the script and would restart the service each step of the way. I noticed when running the reload/restart commands and get an error or the cli freezes, then the commands were bad and the router would then go offline and require factory reset:

Did not run this command in the script since I manually did them in steps 1-2

# Configuring network
 
# Configuring network
uci set network.lanvpn="interface"
uci set network.lanvpn.ifname="tun0"
uci set network.lanvpn.proto="none"
uci commit network
 

ran the following firewall commands

# Configuring firewall
# Configuring firewall
uci add firewall rule
uci set firewall.@rule[-1].name="Allow-LAN-OpenVPN"
uci set firewall.@rule[-1].src="wan"
uci set firewall.@rule[-1].dest_port="1999"
uci set firewall.@rule[-1].proto="tcp udp"
uci set firewall.@rule[-1].target="ACCEPT"
 
uci add firewall zone
uci set firewall.@zone[-1].name="lanvpn"
uci add_list firewall.@zone[-1].network="lanvpn"
uci set firewall.@zone[-1].input="ACCEPT"
uci set firewall.@zone[-1].output="ACCEPT"
uci set firewall.@zone[-1].forward="REJECT"
 
uci add firewall forwarding
uci set firewall.@forwarding[-1].src="lanvpn"
uci set firewall.@forwarding[-1].dest="wan"
 
uci add firewall forwarding
uci set firewall.@forwarding[-1].src="lanvpn"
uci set firewall.@forwarding[-1].dest="lan"
uci commit firewall
 
service firewall restart

ran the following openvpn commands

# Configuring OpenVPN Server
# Configuring OpenVPN Server
VPN_DIR="/etc/openvpn/lan"
uci set openvpn.lanvpn="openvpn"
uci set openvpn.lanvpn.enabled="1"
uci set openvpn.lanvpn.verb="3"
uci set openvpn.lanvpn.dev="tun0"
uci set openvpn.lanvpn.topology="subnet"
uci set openvpn.lanvpn.port="1999"
uci set openvpn.lanvpn.proto="udp"
uci set openvpn.lanvpn.server="192.168.200.0 255.255.255.0"
uci set openvpn.lanvpn.client_to_client="1"
uci set openvpn.lanvpn.compress="lzo"
uci set openvpn.lanvpn.keepalive="10 120"
uci set openvpn.lanvpn.persist_tun="1"
uci set openvpn.lanvpn.persist_key="1"
uci set openvpn.lanvpn.dh="$VPN_DIR/dh.pem"
uci set openvpn.lanvpn.tls_crypt="$VPN_DIR/tc.pem"
uci set openvpn.lanvpn.ca="$VPN_DIR/ca.crt"
uci set openvpn.lanvpn.cert="$VPN_DIR/lanvpnserver.crt"
uci set openvpn.lanvpn.key="$VPN_DIR/lanvpnserver.key"
 
uci add_list openvpn.lanvpn.push="redirect-gateway def1"
uci add_list openvpn.lanvpn.push="route 192.168.0.0 255.255.255.0"
uci add_list openvpn.lanvpn.push="dhcp-option DNS 192.168.0.1"
uci add_list openvpn.lanvpn.push="compress lzo"
uci add_list openvpn.lanvpn.push="persist-tun"
uci add_list openvpn.lanvpn.push="persist-key"
 
VPN_DOMAIN="$(uci -q get dhcp.@dnsmasq[0].domain)"
if [ -n "$VPN_DOMAIN" ]
then
    uci add_list openvpn.lanvpn.push="dhcp-option DOMAIN $VPN_DOMAIN"
fi
uci commit openvpn
 
service openvpn restart

So it looks like script 1 worked out well with out any problems generating the certs, which in my eyes was the trickiest part of the whole thing.

Script 2 is where things went wrong, I will be working on hacking around with the 2 script to see if I can get this down in a more automated fasion.

Script 3 worked for generating the first *.ovpn client file but when I ran it for the other two vpns, it was missing some fields. Here are some examples of my *.ovpn files generated. I commented the areas where information was missing and where I had to add the missing information, another note was for some reason my guest subnet IP was in "remote" field, maybe because this is a test router with no ddns set, so i had to change the remote IP address to my WANs IP that it got from my home network's main router

lanvpnclient.ovpn
verb 3
nobind
dev tun
client
remote 192.168.0.252 1999 udp #was oriignally 172.168.0.1 1999 udp
fast-io
compress lzo
auth-nocache
remote-cert-tls server
<tls-crypt>
-----BEGIN OpenVPN Static key V1-----
47e...b6f
-----END OpenVPN Static key V1-----
</tls-crypt>
<ca>
-----BEGIN CERTIFICATE-----
MII...1n4
-----END CERTIFICATE-----
</ca>
<cert>
-----BEGIN CERTIFICATE-----
MII...I=
-----END CERTIFICATE-----
</cert>
<key>
-----BEGIN ENCRYPTED PRIVATE KEY-----
MII...40=
-----END ENCRYPTED PRIVATE KEY-----
</key>

slavevpnserver.ovpn
verb 3
nobind
dev tun #was missing tun
client
remote 192.168.0.252 1111 udp  #was originally 172.168.0.1 1111, and missing udp
fast-io
compress lzo #was missing lzo
auth-nocache
remote-cert-tls server
<tls-crypt>
-----BEGIN OpenVPN Static key V1-----
43a...e96
-----END OpenVPN Static key V1-----
</tls-crypt>
<ca>
-----BEGIN CERTIFICATE-----
MII...I42
-----END CERTIFICATE-----
</ca>
<cert>
-----BEGIN CERTIFICATE-----
MII...==
-----END CERTIFICATE-----
</cert>
<key>
-----BEGIN ENCRYPTED PRIVATE KEY-----
MII...c=
-----END ENCRYPTED PRIVATE KEY-----
</key>

torvpnserver.ovpn
verb 3
nobind
dev tun #was missing tun
client
remote 192.168.0.252 666 udp  #was originally 172.16.0.1, missing port# and proto
fast-io
compress lzo #missing lzo
auth-nocache
remote-cert-tls server
<tls-crypt>
-----BEGIN OpenVPN Static key V1-----
5cb...714
-----END OpenVPN Static key V1-----
</tls-crypt>
<ca>
-----BEGIN CERTIFICATE-----
MII...Xw=
-----END CERTIFICATE-----
</ca>
<cert>
-----BEGIN CERTIFICATE-----
MII...two
-----END CERTIFICATE-----
</cert>
<key>
-----BEGIN ENCRYPTED PRIVATE KEY-----
MII...OM=
-----END ENCRYPTED PRIVATE KEY-----
</key>

Here are the resulting config files.

vi /etc/config/network:

config interface 'loopback'
	option ifname 'lo'
	option proto 'static'
	option ipaddr '127.0.0.1'
	option netmask '255.0.0.0'

config globals 'globals'
	option ula_prefix 'fd1a:9011:f912::/48'

config interface 'lan'
	option type 'bridge'
	option ifname 'eth0.1'
	option proto 'static'
	option ipaddr '192.168.1.1'
	option netmask '255.255.255.0'
	option ip6assign '60'

config interface 'wan'
	option ifname 'eth1.2'
	option proto 'dhcp'

config interface 'wan6'
	option ifname 'eth1.2'
	option proto 'dhcpv6'

config switch
	option name 'switch0'
	option reset '1'
	option enable_vlan '1'

config switch_vlan
	option device 'switch0'
	option vlan '1'
	option ports '0 1 2 3 5t'

config switch_vlan
	option device 'switch0'
	option vlan '2'
	option ports '4 6t'

config interface 'lanvpnserver'
	option ifname 'tun0'
	option proto 'none'

config interface 'slave'
	option proto 'static'
	option ifname 'eth0'
	option ipaddr '172.16.0.1'
	option netmask '255.255.0.0'
	option gateway '172.16.0.1'
	option broadcast '172.16.255.255'

config interface 'tor'
	option proto 'static'
	option ifname 'eth0'
	option ipaddr '10.1.1.1'
	option netmask '255.0.0.0'
	option gateway '10.1.1.1'
	option broadcast '10.255.255.255'

config interface 'slavevpn'
	option proto 'none'
	option ifname 'tun1'

config interface 'torvpn'
	option proto 'none'
	option ifname 'tun2'


vi /etc/config/firewall:

config defaults
	option syn_flood '1'
	option input 'ACCEPT'
	option output 'ACCEPT'
	option forward 'REJECT'

config zone
	option name 'lan'
	option input 'ACCEPT'
	option output 'ACCEPT'
	option forward 'ACCEPT'
	option network 'lan'

config zone
	option name 'wan'
	option input 'REJECT'
	option output 'ACCEPT'
	option forward 'REJECT'
	option masq '1'
	option mtu_fix '1'
	option network 'wan wan6'

config forwarding
	option src 'lan'
	option dest 'wan'

config rule
	option name 'Allow-DHCP-Renew'
	option src 'wan'
	option proto 'udp'
	option dest_port '68'
	option target 'ACCEPT'
	option family 'ipv4'

config rule
	option name 'Allow-Ping'
	option src 'wan'
	option proto 'icmp'
	option icmp_type 'echo-request'
	option family 'ipv4'
	option target 'ACCEPT'

config rule
	option name 'Allow-IGMP'
	option src 'wan'
	option proto 'igmp'
	option family 'ipv4'
	option target 'ACCEPT'

config rule
	option name 'Allow-DHCPv6'
	option src 'wan'
	option proto 'udp'
	option src_ip 'fc00::/6'
	option dest_ip 'fc00::/6'
	option dest_port '546'
	option family 'ipv6'
	option target 'ACCEPT'

config rule
	option name 'Allow-MLD'
	option src 'wan'
	option proto 'icmp'
	option src_ip 'fe80::/10'
	list icmp_type '130/0'
	list icmp_type '131/0'
	list icmp_type '132/0'
	list icmp_type '143/0'
	option family 'ipv6'
	option target 'ACCEPT'

config rule
	option name 'Allow-ICMPv6-Input'
	option src 'wan'
	option proto 'icmp'
	list icmp_type 'echo-request'
	list icmp_type 'echo-reply'
	list icmp_type 'destination-unreachable'
	list icmp_type 'packet-too-big'
	list icmp_type 'time-exceeded'
	list icmp_type 'bad-header'
	list icmp_type 'unknown-header-type'
	list icmp_type 'router-solicitation'
	list icmp_type 'neighbour-solicitation'
	list icmp_type 'router-advertisement'
	list icmp_type 'neighbour-advertisement'
	option limit '1000/sec'
	option family 'ipv6'
	option target 'ACCEPT'

config rule
	option name 'Allow-ICMPv6-Forward'
	option src 'wan'
	option dest '*'
	option proto 'icmp'
	list icmp_type 'echo-request'
	list icmp_type 'echo-reply'
	list icmp_type 'destination-unreachable'
	list icmp_type 'packet-too-big'
	list icmp_type 'time-exceeded'
	list icmp_type 'bad-header'
	list icmp_type 'unknown-header-type'
	option limit '1000/sec'
	option family 'ipv6'
	option target 'ACCEPT'

config rule
	option name 'Allow-IPSec-ESP'
	option src 'wan'
	option dest 'lan'
	option proto 'esp'
	option target 'ACCEPT'

config rule
	option name 'Allow-ISAKMP'
	option src 'wan'
	option dest 'lan'
	option dest_port '500'
	option proto 'udp'
	option target 'ACCEPT'

config include
	option path '/etc/firewall.user'

config rule
	option name 'Allow-LAN-OpenVPN'
	option src 'wan'
	option dest_port '1999'
	option proto 'tcp udp'
	option target 'ACCEPT'

config zone
	option name 'lanvpnserver'
	option input 'ACCEPT'
	option output 'ACCEPT'
	option forward 'REJECT'
	option network 'lanvpnserver'

config forwarding
	option src 'lanvpnserver'
	option dest 'wan'

config forwarding
	option src 'lanvpnserver'
	option dest 'lan'

config zone
	option name 'slave'
	option input 'ACCEPT'
	option forward 'REJECT'
	option output 'ACCEPT'
	option network 'slave'

config zone
	option name 'tor'
	option input 'ACCEPT'
	option forward 'REJECT'
	option output 'ACCEPT'
	option network 'tor'

config zone
	option input 'ACCEPT'
	option forward 'REJECT'
	option output 'ACCEPT'
	option network 'torvpn'
	option name 'torvpn'

config zone
	option name 'slavevpn'
	option input 'ACCEPT'
	option forward 'REJECT'
	option output 'ACCEPT'
	option network 'slavevpn'

config rule
	option src 'wan'
	option dest_port '1111'
	option proto 'tcp udp'
	option target 'ACCEPT'
	option name 'Allow-SLAVE-OpenVPN'

config forwarding
	option dest 'slave'
	option src 'slavevpn'

config forwarding
	option dest 'wan'
	option src 'slavevpn'

config forwarding
	option dest 'tor'
	option src 'torvpn'

config forwarding
	option dest 'wan'
	option src 'torvpn'

config rule
	option name 'Allow-tor-OpenVPN'
	option src 'wan'
	option dest_port '666'
	option proto 'tcp udp'
	option target 'ACCEPT'


vi /etc/cofnig/openvpn:

config openvpn 'custom_config'
	option enabled '0'
	option config '/etc/openvpn/my-vpn.conf'

config openvpn 'sample_server'
	option enabled '0'
	option port '1194'
	option proto 'udp'
	option dev 'tun'
	option ca '/etc/openvpn/ca.crt'
	option cert '/etc/openvpn/server.crt'
	option key '/etc/openvpn/server.key'
	option dh '/etc/openvpn/dh1024.pem'
	option server '10.8.0.0 255.255.255.0'
	option ifconfig_pool_persist '/tmp/ipp.txt'
	option keepalive '10 120'
	option compress 'lzo'
	option persist_key '1'
	option persist_tun '1'
	option user 'nobody'
	option status '/tmp/openvpn-status.log'
	option verb '3'

config openvpn 'sample_client'
	option enabled '0'
	option client '1'
	option dev 'tun'
	option proto 'udp'
	list remote 'my_server_1 1194'
	option resolv_retry 'infinite'
	option nobind '1'
	option persist_key '1'
	option persist_tun '1'
	option user 'nobody'
	option ca '/etc/openvpn/ca.crt'
	option cert '/etc/openvpn/client.crt'
	option key '/etc/openvpn/client.key'
	option compress 'lzo'
	option verb '3'

config openvpn 'lanvpnserver'
	option enabled '1'
	option verb '3'
	option dev 'tun0'
	option topology 'subnet'
	option port '1999'
	option proto 'udp'
	option server '192.168.200.0 255.255.255.0'
	option client_to_client '1'
	option compress 'lzo'
	option keepalive '10 120'
	option persist_tun '1'
	option persist_key '1'
	option dh '/etc/openvpn/lan/dh.pem'
	option tls_crypt '/etc/openvpn/lan/tc.pem'
	option ca '/etc/openvpn/lan/ca.crt'
	option cert '/etc/openvpn/lan/lanvpnserver.crt'
	option key '/etc/openvpn/lan/lanvpnserver.key'
	list push 'redirect-gateway def1'
	list push 'route 192.168.1.0 255.255.255.0'
	list push 'dhcp-option DNS 192.168.1.1'
	list push 'compress lzo'
	list push 'persist-tun'
	list push 'persist-key'
	list push 'dhcp-option DOMAIN lan'

config openvpn 'slavevpn'
	option enabled '1'
	option verb '3'
	option dev 'tun2'
	option topology 'subnet'
	option port '1111'
	option proto 'udp'
	option server '172.16.200.0 255.255.255.0'
	option client_to_client '1'
	option compress 'lzo'
	option keepalive '10 120'
	option persist_tun '1'
	option persist_key '1'
	option dh '/etc/openvpn/slave/dh.pem'
	option tls_crypt '/etc/openvpn/slave/tc.pem'
	option ca '/etc/openvpn/slave/ca.crt'
	option cert '/etc/openvpn/slave/slavevpnserver.crt'
	option key '/etc/openvpn/slave/slavevpnserver.key'
	list push 'redirect-gateway def1'
	list push 'route 172.16.0.0 255.255.0.0'
	list push 'dhcp-option DNS 172.16.0.1'
	list push 'compress lzo'
	list push 'persist-tun'
	list push 'persist-key'
	list push 'dhcp-option DOMAIN lan'

config openvpn 'torvpn'
	option enabled '1'
	option verb '3'
	option dev 'tun1'
	option topology 'subnet'
	option port '666'
	option proto 'udp'
	option server '10.1.200.0 255.255.255.0'
	option client_to_client '1'
	option compress 'lzo'
	option keepalive '10 120'
	option persist_tun '1'
	option persist_key '1'
	option dh '/etc/openvpn/tor/dh.pem'
	option tls_crypt '/etc/openvpn/tor/tc.pem'
	option ca '/etc/openvpn/tor/ca.crt'
	option cert '/etc/openvpn/tor/torvpnserver.crt'
	option key '/etc/openvpn/tor/torvpnserver.key'
	list push 'redirect-gateway def1'
	list push 'route 10.1.1.0 255.0.0.0'
	list push 'dhcp-option DNS 10.1.1.1'
	list push 'compress lzo'
	list push 'persist-tun'
	list push 'persist-key'
	list push 'dhcp-option DOMAIN lan'


So I have gotten it to work when connecting to the vpn on this router from within my LAN. I noticed if I was connected directly to the test router, the internet would not work. probably some add route or forwarding config that needs to be done to make that work.

Next steps: I will try and see if I can repair the scripts to mitigate these issues experienced with 2nd scripting causing the rotuer to go offline and script 3 to add the missing info. I will keep you posted.

If you, the community, sees antying wrong or would like to provide your feedback, I welcome it.

Thank you.

1 Like

Ok everyone,

I played around with the commands and it seems I cannot figure it out. It looks like I have to do both script and luci gui to make the vpn work. The script i have is listed below

masteter.script.create.configs1.sh
#!/bin/sh

#create slave network interface
uci set network.slave=interface
uci set network.slave.proto='static'
uci set network.slave.ifname='eth0'
uci set network.slave.ipaddr='172.16.0.1'
uci set network.slave.netmask='255.255.0.0'
uci set network.slave.gateway='172.16.0.1'
uci set network.slave.broadcast='172.16.255.255'

#create tor network interface
uci set network.tor=interface
uci set network.tor.proto='static'
uci set network.tor.ifname='eth0'
uci set network.tor.ipaddr='10.1.1.1'
uci set network.tor.netmask='255.0.0.0'
uci set network.tor.gateway='10.1.1.1'
uci set network.tor.broadcast='10.255.255.255'

# Configuring lanvpn network
uci set network.lanvpn="interface"
uci set network.lanvpn.ifname="tun0"
uci set network.lanvpn.proto="none"

# Configuring slavevpn network
uci set network.slavevpn="interface"
uci set network.slavevpn.ifname="tun1"
uci set network.slavevpn.proto="none"
 
# Configuring torvpn network
uci set network.torvpn="interface"
uci set network.torvpn.ifname="tun2"
uci set network.torvpn.proto="none"

uci commit network

# Configuring slave firewall
uci add firewall rule
uci set firewall.@zone[-1]=zone
uci set firewall.@zone[-1].name='slave'
uci set firewall.@zone[-1].input='ACCEPT'
uci set firewall.@zone[-1].forward='REJECT'
uci set firewall.@zone[-1].output='ACCEPT'
uci set firewall.@zone[-1].network='slave'

# Configuring tor firewall
uci add firewall rule
uci set firewall.@zone[-1]=zone
uci set firewall.@zone[-1].name='tor'
uci set firewall.@zone[-1].input='ACCEPT'
uci set firewall.@zone[-1].forward='REJECT'
uci set firewall.@zone[-1].output='ACCEPT'
uci set firewall.@zone[-1].network='tor'

# Configuring lanvpn firewall
uci add firewall rule
uci set firewall.@rule[-1].name="Allow-LAN-OpenVPN"
uci set firewall.@rule[-1].src="wan"
uci set firewall.@rule[-1].dest_port="1999"
uci set firewall.@rule[-1].proto="tcp udp"
uci set firewall.@rule[-1].target="ACCEPT"
 
uci add firewall zone
uci set firewall.@zone[-1].name="lanvpn"
uci add_list firewall.@zone[-1].network="lanvpn"
uci set firewall.@zone[-1].input="ACCEPT"
uci set firewall.@zone[-1].output="ACCEPT"
uci set firewall.@zone[-1].forward="REJECT"
 
uci add firewall forwarding
uci set firewall.@forwarding[-1].src="lanvpn"
uci set firewall.@forwarding[-1].dest="wan"
 
uci add firewall forwarding
uci set firewall.@forwarding[-1].src="lanvpn"
uci set firewall.@forwarding[-1].dest="lan"

# Configuring slavevpn firewall
uci add firewall rule
uci set firewall.@rule[-1].name="Allow-SLAVE-OpenVPN"
uci set firewall.@rule[-1].src="wan"
uci set firewall.@rule[-1].dest_port="1111"
uci set firewall.@rule[-1].proto="tcp udp"
uci set firewall.@rule[-1].target="ACCEPT"
 
uci add firewall zone
uci set firewall.@zone[-1].name="slavevpn"
uci add_list firewall.@zone[-1].network="slavevpn"
uci set firewall.@zone[-1].input="ACCEPT"
uci set firewall.@zone[-1].output="ACCEPT"
uci set firewall.@zone[-1].forward="REJECT"
 
uci add firewall forwarding
uci set firewall.@forwarding[-1].src="slavevpn"
uci set firewall.@forwarding[-1].dest="wan"
 
uci add firewall forwarding
uci set firewall.@forwarding[-1].src="slavevpn"
uci set firewall.@forwarding[-1].dest="slave"

# Configuring torvpn firewall
uci add firewall rule
uci set firewall.@rule[-1].name="Allow-tor-OpenVPN"
uci set firewall.@rule[-1].src="wan"
uci set firewall.@rule[-1].dest_port="666"
uci set firewall.@rule[-1].proto="tcp udp"
uci set firewall.@rule[-1].target="ACCEPT"
 
uci add firewall zone
uci set firewall.@zone[-1].name="torvpn"
uci add_list firewall.@zone[-1].network="torvpn"
uci set firewall.@zone[-1].input="ACCEPT"
uci set firewall.@zone[-1].output="ACCEPT"
uci set firewall.@zone[-1].forward="REJECT"
 
uci add firewall forwarding
uci set firewall.@forwarding[-1].src="torvpn"
uci set firewall.@forwarding[-1].dest="wan"
 
uci add firewall forwarding
uci set firewall.@forwarding[-1].src="torvpn"
uci set firewall.@forwarding[-1].dest="tor"
uci commit firewall

# Configuring OpenVPN Server for lanvpn
VPN_DIR="/etc/openvpn/lan"
uci set openvpn.lanvpn="openvpn"
uci set openvpn.lanvpn.enabled="1"
uci set openvpn.lanvpn.verb="3"
uci set openvpn.lanvpn.dev="tun0"
uci set openvpn.lanvpn.topology="subnet"
uci set openvpn.lanvpn.port="1999"
uci set openvpn.lanvpn.proto="udp"
uci set openvpn.lanvpn.server="192.168.200.0 255.255.255.0"
uci set openvpn.lanvpn.client_to_client="1"
uci set openvpn.lanvpn.compress="lzo"
uci set openvpn.lanvpn.keepalive="10 120"
uci set openvpn.lanvpn.persist_tun="1"
uci set openvpn.lanvpn.persist_key="1"
uci set openvpn.lanvpn.dh="$VPN_DIR/dh.pem"
uci set openvpn.lanvpn.tls_crypt="$VPN_DIR/tc.pem"
uci set openvpn.lanvpn.ca="$VPN_DIR/ca.crt"
uci set openvpn.lanvpn.cert="$VPN_DIR/lanvpnserver.crt"
uci set openvpn.lanvpn.key="$VPN_DIR/lanvpnserver.key"
 
uci add_list openvpn.lanvpn.push="redirect-gateway def1"
uci add_list openvpn.lanvpn.push="route 192.168.0.0 255.255.255.0"
uci add_list openvpn.lanvpn.push="dhcp-option DNS 192.168.0.1"
uci add_list openvpn.lanvpn.push="compress lzo"
uci add_list openvpn.lanvpn.push="persist-tun"
uci add_list openvpn.lanvpn.push="persist-key"
 
VPN_DOMAIN="$(uci -q get dhcp.@dnsmasq[0].domain)"
if [ -n "$VPN_DOMAIN" ]
then
    uci add_list openvpn.lanvpn.push="dhcp-option DOMAIN $VPN_DOMAIN"
fi

# Configuring OpenVPN Server for slavevpn
VPN_DIR="/etc/openvpn/slave"
uci set openvpn.slavevpn="openvpn"
uci set openvpn.slavevpn.enabled="1"
uci set openvpn.slavevpn.verb="3"
uci set openvpn.slavevpn.dev="tun2"
uci set openvpn.slavevpn.topology="subnet"
uci set openvpn.slavevpn.port="1111"
uci set openvpn.slavevpn.proto="udp"
uci set openvpn.slavevpn.server="172.16.200.0 255.255.255.0"
uci set openvpn.slavevpn.client_to_client="1"
uci set openvpn.slavevpn.compress="lzo"
uci set openvpn.slavevpn.keepalive="10 120"
uci set openvpn.slavevpn.persist_tun="1"
uci set openvpn.slavevpn.persist_key="1"
uci set openvpn.slavevpn.dh="$VPN_DIR/dh.pem"
uci set openvpn.slavevpn.tls_crypt="$VPN_DIR/tc.pem"
uci set openvpn.slavevpn.ca="$VPN_DIR/ca.crt"
uci set openvpn.slavevpn.cert="$VPN_DIR/slavevpnserver.crt"
uci set openvpn.slavevpn.key="$VPN_DIR/slavevpnserver.key"
 
uci add_list openvpn.slavevpn.push="redirect-gateway def1"
uci add_list openvpn.slavevpn.push="route 172.16.0.0 255.255.0.0"
uci add_list openvpn.slavevpn.push="dhcp-option DNS 172.16.0.1"
uci add_list openvpn.slavevpn.push="compress lzo"
uci add_list openvpn.slavevpn.push="persist-tun"
uci add_list openvpn.slavevpn.push="persist-key"
 
VPN_DOMAIN="$(uci -q get dhcp.@dnsmasq[0].domain)"
if [ -n "$VPN_DOMAIN" ]
then
    uci add_list openvpn.slavevpn.push="dhcp-option DOMAIN $VPN_DOMAIN"
fi

# Configuring OpenVPN Server for torvpn
VPN_DIR="/etc/openvpn/tor"
uci set openvpn.torvpn="openvpn"
uci set openvpn.torvpn.enabled="1"
uci set openvpn.torvpn.verb="3"
uci set openvpn.torvpn.dev="tun1"
uci set openvpn.torvpn.topology="subnet"
uci set openvpn.torvpn.port="666"
uci set openvpn.torvpn.proto="udp"
uci set openvpn.torvpn.server="10.1.200.0 255.255.255.0"
uci set openvpn.torvpn.client_to_client="1"
uci set openvpn.torvpn.compress="lzo"
uci set openvpn.torvpn.keepalive="10 120"
uci set openvpn.torvpn.persist_tun="1"
uci set openvpn.torvpn.persist_key="1"
uci set openvpn.torvpn.dh="$VPN_DIR/dh.pem"
uci set openvpn.torvpn.tls_crypt="$VPN_DIR/tc.pem"
uci set openvpn.torvpn.ca="$VPN_DIR/ca.crt"
uci set openvpn.torvpn.cert="$VPN_DIR/torvpnserver.crt"
uci set openvpn.torvpn.key="$VPN_DIR/torvpnserver.key"
 
uci add_list openvpn.torvpn.push="redirect-gateway def1"
uci add_list openvpn.torvpn.push="route 10.1.1.0 255.0.0.0"
uci add_list openvpn.torvpn.push="dhcp-option DNS 10.1.1.1"
uci add_list openvpn.torvpn.push="compress lzo"
uci add_list openvpn.torvpn.push="persist-tun"
uci add_list openvpn.torvpn.push="persist-key"
 
VPN_DOMAIN="$(uci -q get dhcp.@dnsmasq[0].domain)"
if [ -n "$VPN_DOMAIN" ]
then
    uci add_list openvpn.torvpn.push="dhcp-option DOMAIN $VPN_DOMAIN"
fi
uci commit openvpn
sleep 5
# Restarting services
service network restart
sleep 5
service firewall restart
sleep 5
service openvpn restart
sleep 5
# Restarting services
/etc/init.d/network restart
sleep 5
/etc/init.d/firewall restart
sleep 5
/etc/init.d/openvpn restart

and the second version was this one

masteter.script.create.configs2.sh
`#!/bin/sh

#create slave network interface
uci set network.slave=interface
uci set network.slave.proto='static'
uci set network.slave.ifname='eth0'
uci set network.slave.ipaddr='172.16.0.1'
uci set network.slave.netmask='255.255.0.0'
uci set network.slave.gateway='172.16.0.1'
uci set network.slave.broadcast='172.16.255.255'

#create tor network interface
uci set network.tor=interface
uci set network.tor.proto='static'
uci set network.tor.ifname='eth0'
uci set network.tor.ipaddr='10.1.1.1'
uci set network.tor.netmask='255.0.0.0'
uci set network.tor.gateway='10.1.1.1'
uci set network.tor.broadcast='10.255.255.255'

#create repair network interface
uci set firewall.@zone[1]=zone
uci set firewall.@zone[1].name='wan'
uci set firewall.@zone[1].network="$(uci set firewall.@zone[1].network) 'wan' 'wan6'"
uci set firewall.@zone[1].network='wan' 'wan6'
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'

# Configuring lanvpn network
uci set network.lanvpn="interface"
uci set network.lanvpn.ifname="tun0"
uci set network.lanvpn.proto="none"

# Configuring slavevpn network
uci set network.slavevpn="interface"
uci set network.slavevpn.ifname="tun1"
uci set network.slavevpn.proto="none"
 
# Configuring torvpn network
uci set network.torvpn="interface"
uci set network.torvpn.ifname="tun2"
uci set network.torvpn.proto="none"

uci commit network

# Configuring slave firewall
uci add firewall rule
uci set firewall.@zone[-1]=zone
uci set firewall.@zone[-1].name='slave'
uci set firewall.@zone[-1].input='ACCEPT'
uci set firewall.@zone[-1].forward='REJECT'
uci set firewall.@zone[-1].output='ACCEPT'
uci set firewall.@zone[-1].network='slave'

# Configuring tor firewall
uci add firewall rule
uci set firewall.@zone[-1]=zone
uci set firewall.@zone[-1].name='tor'
uci set firewall.@zone[-1].input='ACCEPT'
uci set firewall.@zone[-1].forward='REJECT'
uci set firewall.@zone[-1].output='ACCEPT'
uci set firewall.@zone[-1].network='tor'


# Configuring lanvpn firewall
uci add firewall rule
uci set firewall.@rule[-1].name="Allow-LAN-OpenVPN"
uci set firewall.@rule[-1].src="wan"
uci set firewall.@rule[-1].dest_port="1999"
uci set firewall.@rule[-1].proto="tcp udp"
uci set firewall.@rule[-1].target="ACCEPT"
 
uci add firewall zone
uci set firewall.@zone[-1].name="lanvpn"
uci add_list firewall.@zone[-1].network="lanvpn"
uci set firewall.@zone[-1].input="ACCEPT"
uci set firewall.@zone[-1].output="ACCEPT"
uci set firewall.@zone[-1].forward="REJECT"
 
uci add firewall forwarding
uci set firewall.@forwarding[-1].src="lanvpn"
uci set firewall.@forwarding[-1].dest="wan"
 
uci add firewall forwarding
uci set firewall.@forwarding[-1].src="lanvpn"
uci set firewall.@forwarding[-1].dest="lan"

# Configuring slavevpn firewall
uci add firewall rule
uci set firewall.@rule[-1].name="Allow-SLAVE-OpenVPN"
uci set firewall.@rule[-1].src="wan"
uci set firewall.@rule[-1].dest_port="1111"
uci set firewall.@rule[-1].proto="tcp udp"
uci set firewall.@rule[-1].target="ACCEPT"
 
uci add firewall zone
uci set firewall.@zone[-1].name="slavevpn"
uci add_list firewall.@zone[-1].network="slavevpn"
uci set firewall.@zone[-1].input="ACCEPT"
uci set firewall.@zone[-1].output="ACCEPT"
uci set firewall.@zone[-1].forward="REJECT"
 
uci add firewall forwarding
uci set firewall.@forwarding[-1].src="slavevpn"
uci set firewall.@forwarding[-1].dest="wan"
 
uci add firewall forwarding
uci set firewall.@forwarding[-1].src="slavevpn"
uci set firewall.@forwarding[-1].dest="slave"

# Configuring torvpn firewall
uci add firewall rule
uci set firewall.@rule[-1].name="Allow-tor-OpenVPN"
uci set firewall.@rule[-1].src="wan"
uci set firewall.@rule[-1].dest_port="666"
uci set firewall.@rule[-1].proto="tcp udp"
uci set firewall.@rule[-1].target="ACCEPT"
 
uci add firewall zone
uci set firewall.@zone[-1].name="torvpn"
uci add_list firewall.@zone[-1].network="torvpn"
uci set firewall.@zone[-1].input="ACCEPT"
uci set firewall.@zone[-1].output="ACCEPT"
uci set firewall.@zone[-1].forward="REJECT"
 
uci add firewall forwarding
uci set firewall.@forwarding[-1].src="torvpn"
uci set firewall.@forwarding[-1].dest="wan"
 
uci add firewall forwarding
uci set firewall.@forwarding[-1].src="torvpn"
uci set firewall.@forwarding[-1].dest="tor"
uci commit firewall

# Configuring OpenVPN Server for lanvpn
VPN_DIR="/etc/openvpn/lan"
uci set openvpn.lanvpn="openvpn"
uci set openvpn.lanvpn.enabled="1"
uci set openvpn.lanvpn.verb="3"
uci set openvpn.lanvpn.dev="tun0"
uci set openvpn.lanvpn.topology="subnet"
uci set openvpn.lanvpn.port="1999"
uci set openvpn.lanvpn.proto="udp"
uci set openvpn.lanvpn.server="192.168.200.0 255.255.255.0"
uci set openvpn.lanvpn.client_to_client="1"
uci set openvpn.lanvpn.compress="lzo"
uci set openvpn.lanvpn.keepalive="10 120"
uci set openvpn.lanvpn.persist_tun="1"
uci set openvpn.lanvpn.persist_key="1"
uci set openvpn.lanvpn.dh="$VPN_DIR/dh.pem"
uci set openvpn.lanvpn.tls_crypt="$VPN_DIR/tc.pem"
uci set openvpn.lanvpn.ca="$VPN_DIR/ca.crt"
uci set openvpn.lanvpn.cert="$VPN_DIR/lanvpnserver.crt"
uci set openvpn.lanvpn.key="$VPN_DIR/lanvpnserver.key"
 
uci add_list openvpn.lanvpn.push="redirect-gateway def1"
uci add_list openvpn.lanvpn.push="route 192.168.0.0 255.255.255.0"
uci add_list openvpn.lanvpn.push="dhcp-option DNS 192.168.0.1"
uci add_list openvpn.lanvpn.push="compress lzo"
uci add_list openvpn.lanvpn.push="persist-tun"
uci add_list openvpn.lanvpn.push="persist-key"
 
VPN_DOMAIN="$(uci -q get dhcp.@dnsmasq[0].domain)"
if [ -n "$VPN_DOMAIN" ]
then
    uci add_list openvpn.lanvpn.push="dhcp-option DOMAIN $VPN_DOMAIN"
fi

# Configuring OpenVPN Server for slavevpn
VPN_DIR="/etc/openvpn/slave"
uci set openvpn.slavevpn="openvpn"
uci set openvpn.slavevpn.enabled="1"
uci set openvpn.slavevpn.verb="3"
uci set openvpn.slavevpn.dev="tun2"
uci set openvpn.slavevpn.topology="subnet"
uci set openvpn.slavevpn.port="1111"
uci set openvpn.slavevpn.proto="udp"
uci set openvpn.slavevpn.server="172.16.200.0 255.255.255.0"
uci set openvpn.slavevpn.client_to_client="1"
uci set openvpn.slavevpn.compress="lzo"
uci set openvpn.slavevpn.keepalive="10 120"
uci set openvpn.slavevpn.persist_tun="1"
uci set openvpn.slavevpn.persist_key="1"
uci set openvpn.slavevpn.dh="$VPN_DIR/dh.pem"
uci set openvpn.slavevpn.tls_crypt="$VPN_DIR/tc.pem"
uci set openvpn.slavevpn.ca="$VPN_DIR/ca.crt"
uci set openvpn.slavevpn.cert="$VPN_DIR/slavevpnserver.crt"
uci set openvpn.slavevpn.key="$VPN_DIR/slavevpnserver.key"
 
uci add_list openvpn.slavevpn.push="redirect-gateway def1"
uci add_list openvpn.slavevpn.push="route 172.16.0.0 255.255.0.0"
uci add_list openvpn.slavevpn.push="dhcp-option DNS 172.16.0.1"
uci add_list openvpn.slavevpn.push="compress lzo"
uci add_list openvpn.slavevpn.push="persist-tun"
uci add_list openvpn.slavevpn.push="persist-key"
 
VPN_DOMAIN="$(uci -q get dhcp.@dnsmasq[0].domain)"
if [ -n "$VPN_DOMAIN" ]
then
    uci add_list openvpn.slavevpn.push="dhcp-option DOMAIN $VPN_DOMAIN"
fi

# Configuring OpenVPN Server for torvpn
VPN_DIR="/etc/openvpn/tor"
uci set openvpn.torvpn="openvpn"
uci set openvpn.torvpn.enabled="1"
uci set openvpn.torvpn.verb="3"
uci set openvpn.torvpn.dev="tun1"
uci set openvpn.torvpn.topology="subnet"
uci set openvpn.torvpn.port="666"
uci set openvpn.torvpn.proto="udp"
uci set openvpn.torvpn.server="10.1.200.0 255.255.255.0"
uci set openvpn.torvpn.client_to_client="1"
uci set openvpn.torvpn.compress="lzo"
uci set openvpn.torvpn.keepalive="10 120"
uci set openvpn.torvpn.persist_tun="1"
uci set openvpn.torvpn.persist_key="1"
uci set openvpn.torvpn.dh="$VPN_DIR/dh.pem"
uci set openvpn.torvpn.tls_crypt="$VPN_DIR/tc.pem"
uci set openvpn.torvpn.ca="$VPN_DIR/ca.crt"
uci set openvpn.torvpn.cert="$VPN_DIR/torvpnserver.crt"
uci set openvpn.torvpn.key="$VPN_DIR/torvpnserver.key"
 
uci add_list openvpn.torvpn.push="redirect-gateway def1"
uci add_list openvpn.torvpn.push="route 10.1.1.0 255.0.0.0"
uci add_list openvpn.torvpn.push="dhcp-option DNS 10.1.1.1"
uci add_list openvpn.torvpn.push="compress lzo"
uci add_list openvpn.torvpn.push="persist-tun"
uci add_list openvpn.torvpn.push="persist-key"
 
VPN_DOMAIN="$(uci -q get dhcp.@dnsmasq[0].domain)"
if [ -n "$VPN_DOMAIN" ]
then
    uci add_list openvpn.torvpn.push="dhcp-option DOMAIN $VPN_DOMAIN"
fi
uci commit openvpn
sleep 5
# Restarting services
service network restart
sleep 5
service firewall restart
sleep 5
service openvpn restart
sleep 5
# Restarting services
/etc/init.d/network restart
sleep 5
/etc/init.d/firewall restart
sleep 5
/etc/init.d/openvpn restart

 `

So I am not sure what went wrong with the script but I was working on a test router so i had to add the guest and tor vlan/network interfaces, because i want the vpn to bridge to those networks. these interfaces are already existing on my production router.

so when i ran the 1st script it seems to work out well but I need to manually configure the firewall settings on the network interface on the luci gui to create the firewall zone.

In the second script, I tried to include the firewall zone info for the newly created interfaces but they would delete the wan and lan firewall zones. I confirmed this by comparing the output of uci show command pre and post on the router.

I then tried to recreate the wan/wan6 interfaces by adding the uci commands to the 2nd script, but that failed because uci doesnt permit spaces in their commands. So i tried to pass the commands as an echo but that didnt work. It would end up taking my router offline and having to do a factory reset.

In addition, when trying to run service service_name restart commands, it didnt seem to work so I swapped it out with /etc/init.d/service_name restart which seemed to work.

So I guess there is no way to fully automate this process via the scripts and we have to do a combination of both script and luci gui, all within luci gui, or manually type out the configs in the config files?

On a side note, the vpn connects but it doesnt seem to work fully. I tried connecting my laptop to my phones hotspot and connecting to the vpn, it works and I get internet through it but when I try to connect to the tor network, it does not use the tor network and still uses my isp IP.

In addition, when I connect to the vpn via my smart phone, the internet doesnt work at all and I am not able to ping devices internally.

Would this be appropriate to discuss it here or would it be off topic and I should open a new discussion for that one? I have checked some sources but I wanted to check if I can talk about it here or if I needed to open a new forum to discuss there.

Thanks in advance.

hello wulfy,

here is my network config of my production router:

/etc/config/network
root@infraverse:/etc/config# cat network

config interface 'loopback'
        option ifname 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config globals 'globals'
        option ula_prefix 'fdfb:7e04:aca7::/48'

config interface 'lan'
        option type 'bridge'
        option ifname 'eth0.1'
        option proto 'static'
        option netmask '255.255.255.0'
        option ip6assign '60'
        option ipaddr '192.168.0.1'
        option gateway '192.168.0.1'
        option broadcast '192.168.0.255'
        option dns '8.8.8.8'

config interface 'wan'
        option ifname 'eth1.2'
        option proto 'dhcp'
        option hostname 'infraverse.network'

config interface 'wan6'
        option ifname 'eth1.2'
        option proto 'dhcpv6'

config switch
        option name 'switch0'
        option reset '1'
        option enable_vlan '1'

config switch_vlan
        option device 'switch0'
        option vlan '1'
        option vid '1'
        option ports '0t 1 2 3 5t'

config switch_vlan
        option device 'switch0'
        option vlan '2'
        option ports '4 6t'
        option vid '2'

config interface 'slave'
        option type 'bridge'
        option proto 'static'
        option ipaddr '172.16.0.1'
        option netmask '255.255.0.0'
        option ifname 'eth0.3 radio1'
        option gateway '172.16.0.1'
        option broadcast '172.16.255.255'

config interface 'tor'
        option proto 'static'
        option ipaddr '10.1.1.1'
        option netmask '255.0.0.0'
        option type 'bridge'
        option ifname 'eth0.4'

config switch_vlan
        option device 'switch0'
        option vlan '3'
        option vid '3'
        option ports '0t 5t'

config switch_vlan
        option device 'switch0'
        option vlan '4'
        option vid '4'
        option ports '0t 5t'

config interface 'lanvpn'
        option proto 'none'
        option type 'bridge'
        option ifname 'eth0.1 tun0'

config interface 'slavevpn'
        option proto 'none'
        option ifname 'tun1'

config interface 'torvpn'
        option proto 'none'
        option type 'bridge'
        option ifname 'eth0.4 tun2'

wan is still there, the interfaces I described are the internal networks/subnets/vlans.

I hope my firewall is alright, here is my firewall config:

/etc/config/firewall
root@infraverse:/etc/config# cat firewall

config defaults
        option syn_flood '1'
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'REJECT'

config zone
        option name 'lan'
        list network 'lan'
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'ACCEPT'

config zone
        option name 'wan'
        list network 'wan'
        list network 'wan6'
        option input 'REJECT'
        option output 'ACCEPT'
        option forward 'REJECT'
        option masq '1'
        option mtu_fix '1'

config forwarding
        option src 'lan'
        option dest 'wan'

config rule
        option name 'Allow-DHCP-Renew'
        option src 'wan'
        option proto 'udp'
        option dest_port '68'
        option target 'ACCEPT'
        option family 'ipv4'

config rule
        option name 'Allow-Ping'
        option src 'wan'
        option proto 'icmp'
        option icmp_type 'echo-request'
        option family 'ipv4'
        option target 'ACCEPT'

config rule
        option name 'Allow-IGMP'
        option src 'wan'
        option proto 'igmp'
        option family 'ipv4'
        option target 'ACCEPT'

config rule
        option name 'Allow-DHCPv6'
        option src 'wan'
        option proto 'udp'
        option src_ip 'fc00::/6'
        option dest_ip 'fc00::/6'
        option dest_port '546'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-MLD'
        option src 'wan'
        option proto 'icmp'
        option src_ip 'fe80::/10'
        list icmp_type '130/0'
        list icmp_type '131/0'
        list icmp_type '132/0'
        list icmp_type '143/0'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-ICMPv6-Input'
        option src 'wan'
        option proto 'icmp'
        list icmp_type 'echo-request'
        list icmp_type 'echo-reply'
        list icmp_type 'destination-unreachable'
        list icmp_type 'packet-too-big'
        list icmp_type 'time-exceeded'
        list icmp_type 'bad-header'
        list icmp_type 'unknown-header-type'
        list icmp_type 'router-solicitation'
        list icmp_type 'neighbour-solicitation'
        list icmp_type 'router-advertisement'
        list icmp_type 'neighbour-advertisement'
        option limit '1000/sec'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-ICMPv6-Forward'
        option src 'wan'
        option dest '*'
        option proto 'icmp'
        list icmp_type 'echo-request'
        list icmp_type 'echo-reply'
        list icmp_type 'destination-unreachable'
        list icmp_type 'packet-too-big'
        list icmp_type 'time-exceeded'
        list icmp_type 'bad-header'
        list icmp_type 'unknown-header-type'
        option limit '1000/sec'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-IPSec-ESP'
        option src 'wan'
        option dest 'lan'
        option proto 'esp'
        option target 'ACCEPT'

config rule
        option name 'Allow-ISAKMP'
        option src 'wan'
        option dest 'lan'
        option dest_port '500'
        option proto 'udp'
        option target 'ACCEPT'

config include
        option path '/etc/firewall.user'

config include 'miniupnpd'
        option type 'script'
        option path '/usr/share/miniupnpd/firewall.include'
        option family 'any'
        option reload '1'

config zone
        option name 'slave'
        option forward 'REJECT'
        option output 'ACCEPT'
        option network 'slave'
        option input 'REJECT'

config forwarding
        option dest 'wan'
        option src 'slave'

config rule
        option target 'ACCEPT'
        option proto 'tcp udp'
        option dest_port '53'
        option name 'Slave dns'
        option src 'slave'

config rule
        option target 'ACCEPT'
        option proto 'udp'
        option dest_port '67-68'
        option name 'slave dhcp'
        option src 'slave'

config zone
        option name 'tor'
        option forward 'REJECT'
        option output 'ACCEPT'
        option network 'tor'
        option input 'ACCEPT'
        option syn_flood '1'
        option conntrack '1'

config forwarding
        option dest 'wan'
        option src 'tor'

config forwarding
        option src 'wan'
        option dest 'tor'

config rule
        option src 'tor'
        option proto 'udp'
        option dest_port '67'
        option target 'ACCEPT'

config rule
        option src 'tor'
        option proto 'tcp'
        option dest_port '9040'
        option target 'ACCEPT'

config rule
        option src 'tor'
        option proto 'udp'
        option dest_port '9053'
        option target 'ACCEPT'

config redirect
        option name 'Redirect-Tor-Traffic'
        option src 'tor'
        option src_dip '!10.1.1.1'
        option dest_port '9040'
        option proto 'tcp'
        option target 'DNAT'

config redirect
        option name 'Redirect-Tor-DNS'
        option src 'tor'
        option src_dport '53'
        option dest_port '9053'
        option proto 'udp'
        option target 'DNAT'

config rule
        option name 'Allow-LAN-OpenVPN'
        option src 'wan'
        option dest_port '1999'
        option proto 'tcp udp'
        option target 'ACCEPT'

config zone
        option name 'lanvpn'
        list network 'lanvpn'
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'REJECT'

config rule
        option name 'Allow-SLAVE-OpenVPN'
        option src 'wan'
        option dest_port '1111'
        option proto 'tcp udp'
        option target 'ACCEPT'

config zone
        option name 'slavevpn'
        list network 'slavevpn'
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'REJECT'

config rule
        option name 'Allow-tor-OpenVPN'
        option src 'wan'
        option dest_port '666'
        option proto 'tcp udp'
        option target 'ACCEPT'

config zone
        option name 'torvpn'
        list network 'torvpn'
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'REJECT'

config forwarding
        option dest 'wan'
        option src 'torvpn'

config forwarding
        option dest 'wan'
        option src 'slavevpn'

config forwarding
        option dest 'lan'
        option src 'lanvpn'

config forwarding
        option dest 'wan'
        option src 'lanvpn'

config forwarding
        option dest 'lanvpn'
        option src 'lan'

Hello Community,

After many hours of plugging away at this, I was able to find a resolve. I think the problem was with my openvpn config file for the vpns were configured to point at an incorrect DNS server. My laptop is able to work but my iphone is having problems with the internet still, but that is minor. Getting my computer to vpn to the network was more critical.

I am posting the config files I have. Please not that I created a vpn to my private, guest, and tor networks.

/etc/config/network

config interface 'loopback'
	option ifname 'lo'
	option proto 'static'
	option ipaddr '127.0.0.1'
	option netmask '255.0.0.0'

config globals 'globals'
	option ula_prefix 'fdfb:7e04:aca7::/48'

config interface 'lan'
	option type 'bridge'
	option ifname 'eth0.1'
	option proto 'static'
	option netmask '255.255.255.0'
	option ip6assign '60'
	option ipaddr '192.168.0.1'
	option gateway '192.168.0.1'
	option broadcast '192.168.0.255'
	option dns '8.8.8.8'

config interface 'wan'
	option ifname 'eth1.2'
	option proto 'dhcp'
	option hostname 'infraverse.network'

config interface 'wan6'
	option ifname 'eth1.2'
	option proto 'dhcpv6'

config switch
	option name 'switch0'
	option reset '1'
	option enable_vlan '1'

config switch_vlan
	option device 'switch0'
	option vlan '1'
	option vid '1'
	option ports '0t 1 2 3 5t'

config switch_vlan
	option device 'switch0'
	option vlan '2'
	option ports '4 6t'
	option vid '2'

config interface 'slave'
	option type 'bridge'
	option proto 'static'
	option ipaddr '172.16.0.1'
	option netmask '255.255.0.0'
	option ifname 'eth0.3 radio1'
	option gateway '172.16.0.1'
	option broadcast '172.16.255.255'

config interface 'tor'
	option proto 'static'
	option ipaddr '10.1.1.1'
	option netmask '255.0.0.0'
	option type 'bridge'
	option ifname 'eth0.4'

config switch_vlan
	option device 'switch0'
	option vlan '3'
	option vid '3'
	option ports '0t 5t'

config switch_vlan
	option device 'switch0'
	option vlan '4'
	option vid '4'
	option ports '0t 5t'

config interface 'lanvpn'
	option proto 'none'
	option ifname 'tun0'

config interface 'slavevpn'
	option proto 'none'
	option ifname 'tun1'

config interface 'torvpn'
	option proto 'none'
	option ifname 'tun2'


/etc/config/firewall

config defaults
	option syn_flood '1'
	option input 'ACCEPT'
	option output 'ACCEPT'
	option forward 'REJECT'

config zone
	option name 'lan'
	list network 'lan'
	option input 'ACCEPT'
	option output 'ACCEPT'
	option forward 'ACCEPT'

config zone
	option name 'wan'
	list network 'wan'
	list network 'wan6'
	option input 'REJECT'
	option output 'ACCEPT'
	option forward 'REJECT'
	option masq '1'
	option mtu_fix '1'

config rule
	option name 'Allow-DHCP-Renew'
	option src 'wan'
	option proto 'udp'
	option dest_port '68'
	option target 'ACCEPT'
	option family 'ipv4'

config rule
	option name 'Allow-Ping'
	option src 'wan'
	option proto 'icmp'
	option icmp_type 'echo-request'
	option family 'ipv4'
	option target 'ACCEPT'

config rule
	option name 'Allow-IGMP'
	option src 'wan'
	option proto 'igmp'
	option family 'ipv4'
	option target 'ACCEPT'

config rule
	option name 'Allow-DHCPv6'
	option src 'wan'
	option proto 'udp'
	option src_ip 'fc00::/6'
	option dest_ip 'fc00::/6'
	option dest_port '546'
	option family 'ipv6'
	option target 'ACCEPT'

config rule
	option name 'Allow-MLD'
	option src 'wan'
	option proto 'icmp'
	option src_ip 'fe80::/10'
	list icmp_type '130/0'
	list icmp_type '131/0'
	list icmp_type '132/0'
	list icmp_type '143/0'
	option family 'ipv6'
	option target 'ACCEPT'

config rule
	option name 'Allow-ICMPv6-Input'
	option src 'wan'
	option proto 'icmp'
	list icmp_type 'echo-request'
	list icmp_type 'echo-reply'
	list icmp_type 'destination-unreachable'
	list icmp_type 'packet-too-big'
	list icmp_type 'time-exceeded'
	list icmp_type 'bad-header'
	list icmp_type 'unknown-header-type'
	list icmp_type 'router-solicitation'
	list icmp_type 'neighbour-solicitation'
	list icmp_type 'router-advertisement'
	list icmp_type 'neighbour-advertisement'
	option limit '1000/sec'
	option family 'ipv6'
	option target 'ACCEPT'

config rule
	option name 'Allow-ICMPv6-Forward'
	option src 'wan'
	option dest '*'
	option proto 'icmp'
	list icmp_type 'echo-request'
	list icmp_type 'echo-reply'
	list icmp_type 'destination-unreachable'
	list icmp_type 'packet-too-big'
	list icmp_type 'time-exceeded'
	list icmp_type 'bad-header'
	list icmp_type 'unknown-header-type'
	option limit '1000/sec'
	option family 'ipv6'
	option target 'ACCEPT'

config rule
	option name 'Allow-IPSec-ESP'
	option src 'wan'
	option dest 'lan'
	option proto 'esp'
	option target 'ACCEPT'

config rule
	option name 'Allow-ISAKMP'
	option src 'wan'
	option dest 'lan'
	option dest_port '500'
	option proto 'udp'
	option target 'ACCEPT'

config include
	option path '/etc/firewall.user'

config include 'miniupnpd'
	option type 'script'
	option path '/usr/share/miniupnpd/firewall.include'
	option family 'any'
	option reload '1'

config zone
	option name 'slave'
	option forward 'REJECT'
	option output 'ACCEPT'
	option network 'slave'
	option input 'REJECT'

config forwarding
	option dest 'wan'
	option src 'slave'

config rule
	option target 'ACCEPT'
	option proto 'tcp udp'
	option dest_port '53'
	option name 'Slave dns'
	option src 'slave'

config rule
	option target 'ACCEPT'
	option proto 'udp'
	option dest_port '67-68'
	option name 'slave dhcp'
	option src 'slave'

config zone
	option name 'tor'
	option forward 'REJECT'
	option output 'ACCEPT'
	option network 'tor'
	option input 'ACCEPT'
	option syn_flood '1'
	option conntrack '1'

config rule
	option src 'tor'
	option proto 'udp'
	option dest_port '67'
	option target 'ACCEPT'
	option name 'tor DHCP'

config rule
	option src 'tor'
	option proto 'tcp'
	option dest_port '9040'
	option target 'ACCEPT'
	option name 'tor transport'

config rule
	option src 'tor'
	option proto 'udp'
	option dest_port '9053'
	option target 'ACCEPT'
	option name 'tor dns'

config redirect
	option name 'Redirect-Tor-Traffic'
	option src 'tor'
	option src_dip '!10.1.1.1'
	option dest_port '9040'
	option proto 'tcp'
	option target 'DNAT'

config redirect
	option name 'Redirect-Tor-DNS'
	option src 'tor'
	option src_dport '53'
	option dest_port '9053'
	option proto 'udp'
	option target 'DNAT'

config rule
	option name 'Allow-LAN-OpenVPN'
	option src '*'
	option dest_port '1999'
	option proto 'tcp udp'
	option target 'ACCEPT'

config zone
	option name 'lanvpn'
	option network 'lanvpn'
	option masq '1'
	option output 'ACCEPT'
	option input 'ACCEPT'
	option forward 'ACCEPT'
	option mtu_fix '1'

config rule
	option name 'Allow-SLAVE-OpenVPN'
	option src '*'
	option dest_port '1111'
	option proto 'tcp udp'
	option target 'ACCEPT'

config zone
	option name 'slavevpn'
	option network 'slavevpn'
	option masq '1'
	option input 'ACCEPT'
	option output 'ACCEPT'
	option forward 'ACCEPT'
	option mtu_fix '1'

config rule
	option name 'Allow-tor-OpenVPN'
	option src '*'
	option dest_port '666'
	option proto 'tcp udp'
	option target 'ACCEPT'

config zone
	option name 'torvpn'
	option network 'torvpn'
	option masq '1'
	option input 'ACCEPT'
	option output 'ACCEPT'
	option forward 'ACCEPT'
	option mtu_fix '1'

config forwarding
	option dest 'wan'
	option src 'slavevpn'

config forwarding
	option dest 'wan'
	option src 'torvpn'

config forwarding
	option dest 'wan'
	option src 'lanvpn'

config forwarding
	option dest 'slave'
	option src 'slavevpn'

config forwarding
	option dest 'tor'
	option src 'torvpn'

config forwarding
	option dest 'lan'
	option src 'lanvpn'

config forwarding
	option dest 'lanvpn'
	option src 'wan'

config forwarding
	option dest 'wan'
	option src 'lan'

config forwarding
	option dest 'wan'
	option src 'tor'

config forwarding
	option dest 'tor'
	option src 'wan'

config rule
	option target 'ACCEPT'
	option dest_port '67'
	option name 'torvpn-DHCP'
	option src 'torvpn'
	option proto 'udp'

config rule
	option target 'ACCEPT'
	option proto 'tcp'
	option dest_port '9040'
	option name 'torvpn-transport'
	option src 'torvpn'

config rule
	option enabled '1'
	option target 'ACCEPT'
	option proto 'udp'
	option dest_port '9053'
	option name 'torvpn-DNS'
	option src 'torvpn'

config redirect
	option target 'DNAT'
	option dest_port '9040'
	option name 'Redirect-torvpn-Traffic'
	option proto 'tcp'
	option src 'torvpn'
	option src_dip '!10.1.200.1'
	option dest 'lan'

config redirect
	option target 'DNAT'
	option proto 'udp'
	option name 'Redirect-Tor-DNS'
	option src 'torvpn'
	option src_dport '53'
	option dest_port '9053'

/etc/firewall.user
# This file is interpreted as shell script.
# Put your custom iptables rules here, they will
# be executed with each firewall (re-)start.

# Internal uci firewall chains are flushed and recreated on reload, so
# put custom rules into the root chains e.g. INPUT or FORWARD or into the
# special user chains, e.g. input_wan_rule or postrouting_lan_rule.

iptables -A PREROUTING -t nat -p udp --dport 53 -i br-lan -j DNAT --to 192.168.0.1:53
iptables -t nat -A PREROUTING -i wlan1-2 -p udp --dport 53 -j REDIRECT --to-ports 9053
iptables -t nat -A PREROUTING -i wlan1-2 -p tcp --syn -j REDIRECT --to-ports 9040
iptables -t nat -A PREROUTING -i eth0.4 -p udp --dport 53 -j REDIRECT --to-ports 9053
iptables -t nat -A PREROUTING -i eth0.4 -p tcp --syn -j REDIRECT --to-ports 9040
iptables -t nat -A PREROUTING -i tun2 -p udp --dport 53 -j REDIRECT --to-ports 9053
iptables -t nat -A PREROUTING -i tun2 -p tcp --syn -j REDIRECT --to-ports 9040

/etc/config/openvpn

config openvpn 'custom_config'
	option config '/etc/openvpn/my-vpn.conf'

config openvpn 'sample_server'
	option port '1194'
	option proto 'udp'
	option dev 'tun'
	option ca '/etc/openvpn/ca.crt'
	option cert '/etc/openvpn/server.crt'
	option key '/etc/openvpn/server.key'
	option dh '/etc/openvpn/dh1024.pem'
	option server '10.8.0.0 255.255.255.0'
	option ifconfig_pool_persist '/tmp/ipp.txt'
	option keepalive '10 120'
	option compress 'lzo'
	option persist_key '1'
	option persist_tun '1'
	option user 'nobody'
	option status '/tmp/openvpn-status.log'
	option verb '3'

config openvpn 'sample_client'
	option client '1'
	option dev 'tun'
	option proto 'udp'
	list remote 'my_server_1 1194'
	option resolv_retry 'infinite'
	option nobind '1'
	option persist_key '1'
	option persist_tun '1'
	option user 'nobody'
	option ca '/etc/openvpn/ca.crt'
	option cert '/etc/openvpn/client.crt'
	option key '/etc/openvpn/client.key'
	option compress 'lzo'
	option verb '3'

config openvpn 'lanvpn'
	option enabled '1'
	option verb '11'
	option log '/var/log/openvpn/openvpn.log'
	option log_append '/var/log/openvpn/openvpn.log'
	option dev 'tun0'
	option port '1999'
	option proto 'udp'
	option server '192.168.200.0 255.255.255.0'
	option client_to_client '1'
	option compress 'lzo'
	option keepalive '10 120'
	option persist_tun '1'
	option persist_key '1'
	option dh '/etc/openvpn/lan/dh.pem'
	option tls_crypt '/etc/openvpn/lan/tc.pem'
	option ca '/etc/openvpn/lan/ca.crt'
	option cert '/etc/openvpn/lan/lanvpnserver.crt'
	option key '/etc/openvpn/lan/lanvpnserver.key'
	list push 'redirect-gateway def1'
	list push 'route 192.168.0.0 255.255.255.0'
	list push 'dhcp-option DNS 192.168.0.1'
	list push 'compress lzo'
	list push 'persist-tun'
	list push 'persist-key'
	list push 'dhcp-option DOMAIN lan'

config openvpn 'slavevpn'
	option enabled '1'
	option verb '3'
	option port '1111'
	option proto 'udp'
	option server '172.16.200.0 255.255.255.0'
	option client_to_client '1'
	option compress 'lzo'
	option keepalive '10 120'
	option persist_tun '1'
	option persist_key '1'
	option dh '/etc/openvpn/slave/dh.pem'
	option tls_crypt '/etc/openvpn/slave/tc.pem'
	option ca '/etc/openvpn/slave/ca.crt'
	option cert '/etc/openvpn/slave/slavevpnserver.crt'
	option key '/etc/openvpn/slave/slavevpnserver.key'
	list push 'redirect-gateway def1'
	list push 'route 172.16.0.0 255.255.0.0'
	list push 'dhcp-option DNS 192.168.0.1'
	list push 'compress lzo'
	list push 'persist-tun'
	list push 'persist-key'
	list push 'dhcp-option DOMAIN lan'
	option dev 'tun1'

config openvpn 'torvpn'
	option enabled '1'
	option verb '3'
	option port '666'
	option proto 'udp'
	option server '10.1.200.0 255.255.255.0'
	option client_to_client '1'
	option compress 'lzo'
	option keepalive '10 120'
	option persist_tun '1'
	option persist_key '1'
	option dh '/etc/openvpn/tor/dh.pem'
	option tls_crypt '/etc/openvpn/tor/tc.pem'
	option ca '/etc/openvpn/tor/ca.crt'
	option cert '/etc/openvpn/tor/torvpnserver.crt'
	option key '/etc/openvpn/tor/torvpnserver.key'
	list push 'redirect-gateway def1'
	list push 'route 10.1.1.0 255.0.0.0'
	list push 'dhcp-option DNS 10.1.1.1'
	list push 'compress lzo'
	list push 'persist-tun'
	list push 'persist-key'
	list push 'dhcp-option DOMAIN lan'
	option dev 'tun2'


and just in case you want to add your own tor vpn server to connect to remotely [Note: this requires you have installed tor via the opkg install tor tor-geoip command. notice the vpn subnet added to the bottom of the tor file]:

/etc/tor/torrc
type or paste code here## Configuration file for a typical Tor user
## Last updated 22 December 2017 for Tor 0.3.2.8-rc.
## (may or may not work for much older or much newer versions of Tor.)
##
## Lines that begin with "## " try to explain what's going on. Lines
## that begin with just "#" are disabled commands: you can enable them
## by removing the "#" symbol.
##
## See 'man tor', or https://www.torproject.org/docs/tor-manual.html,
## for more options you can use in this file.
##
## Tor will look for this file in various places based on your platform:
## https://www.torproject.org/docs/faq#torrc

## Tor opens a SOCKS proxy on port 9050 by default -- even if you don't
## configure one below. Set "SOCKSPort 0" if you plan to run Tor only
## as a relay, and not make any local application connections yourself.
#SOCKSPort 9050 # Default: Bind to localhost:9050 for local connections.
#SOCKSPort 192.168.0.1:9100 # Bind to this address:port too.

## Entry policies to allow/deny SOCKS requests based on IP address.
## First entry that matches wins. If no SOCKSPolicy is set, we accept
## all (and only) requests that reach a SOCKSPort. Untrusted users who
## can access your SOCKSPort may be able to learn about the connections
## you make.
#SOCKSPolicy accept 192.168.0.0/16
#SOCKSPolicy accept6 FC00::/7
#SOCKSPolicy reject *

## Logs go to stdout at level "notice" unless redirected by something
## else, like one of the below lines. You can have as many Log lines as
## you want.
##
## We advise using "notice" in most cases, since anything more verbose
## may provide sensitive information to an attacker who obtains the logs.
##
## Send all messages of level 'notice' or higher to /var/log/tor/notices.log
Log notice file /var/log/tor/notices.log
## Send every possible message to /var/log/tor/debug.log
#Log debug file /var/log/tor/debug.log
## Use the system log instead of Tor's logfiles
Log notice syslog
## To send all messages to stderr:
#Log debug stderr

## Uncomment this to start the process in the background... or use
## --runasdaemon 1 on the command line. This is ignored on Windows;
## see the FAQ entry if you want Tor to run as an NT service.
RunAsDaemon 1

## The directory for keeping all the keys/etc. By default, we store
## things in $HOME/.tor on Unix, and in Application Data\tor on Windows.
DataDirectory /var/lib/tor

## The port on which Tor will listen for local connections from Tor
## controller applications, as documented in control-spec.txt.
#ControlPort 9051
## If you enable the controlport, be sure to enable one of these
## authentication methods, to prevent attackers from accessing it.
#HashedControlPassword 16:872860B76453A77D60CA2BB8C1A7042072093276A3D701AD684053EC4C
#CookieAuthentication 1

############### This section is just for location-hidden services ###

## Once you have configured a hidden service, you can look at the
## contents of the file ".../hidden_service/hostname" for the address
## to tell people.
##
## HiddenServicePort x y:z says to redirect requests on port x to the
## address y:z.

#HiddenServiceDir /var/lib/tor/hidden_service/
#HiddenServicePort 80 127.0.0.1:80

#HiddenServiceDir /var/lib/tor/other_hidden_service/
#HiddenServicePort 80 127.0.0.1:80
#HiddenServicePort 22 127.0.0.1:22

################ This section is just for relays #####################
#
## See https://www.torproject.org/docs/tor-doc-relay for details.

## Required: what port to advertise for incoming Tor connections.
#ORPort 9001
## If you want to listen on a port other than the one advertised in
## ORPort (e.g. to advertise 443 but bind to 9090), you can do it as
## follows.  You'll need to do ipchains or other port forwarding
## yourself to make this work.
#ORPort 443 NoListen
#ORPort 127.0.0.1:9090 NoAdvertise

## The IP address or full DNS name for incoming connections to your
## relay. Leave commented out and Tor will guess.
#Address noname.example.com

## If you have multiple network interfaces, you can specify one for
## outgoing traffic to use.
## OutboundBindAddressExit will be used for all exit traffic, while
## OutboundBindAddressOR will be used for all OR and Dir connections
## (DNS connections ignore OutboundBindAddress).
## If you do not wish to differentiate, use OutboundBindAddress to
## specify the same address for both in a single line.
#OutboundBindAddressExit 10.0.0.4
#OutboundBindAddressOR 10.0.0.5

## A handle for your relay, so people don't have to refer to it by key.
## Nicknames must be between 1 and 19 characters inclusive, and must
## contain only the characters [a-zA-Z0-9].
#Nickname ididnteditheconfig

## Define these to limit how much relayed traffic you will allow. Your
## own traffic is still unthrottled. Note that RelayBandwidthRate must
## be at least 75 kilobytes per second.
## Note that units for these config options are bytes (per second), not
## bits (per second), and that prefixes are binary prefixes, i.e. 2^10,
## 2^20, etc.
#RelayBandwidthRate 100 KBytes  # Throttle traffic to 100KB/s (800Kbps)
#RelayBandwidthBurst 200 KBytes # But allow bursts up to 200KB (1600Kb)

## Use these to restrict the maximum traffic per day, week, or month.
## Note that this threshold applies separately to sent and received bytes,
## not to their sum: setting "40 GB" may allow up to 80 GB total before
## hibernating.
##
## Set a maximum of 40 gigabytes each way per period.
#AccountingMax 40 GBytes
## Each period starts daily at midnight (AccountingMax is per day)
#AccountingStart day 00:00
## Each period starts on the 3rd of the month at 15:00 (AccountingMax
## is per month)
#AccountingStart month 3 15:00

## Administrative contact information for this relay or bridge. This line
## can be used to contact you if your relay or bridge is misconfigured or
## something else goes wrong. Note that we archive and publish all
## descriptors containing these lines and that Google indexes them, so
## spammers might also collect them. You may want to obscure the fact that
## it's an email address and/or generate a new address for this purpose.
##
## If you are running multiple relays, you MUST set this option.
##
#ContactInfo Random Person <nobody AT example dot com>
## You might also include your PGP or GPG fingerprint if you have one:
#ContactInfo 0xFFFFFFFF Random Person <nobody AT example dot com>

## Uncomment this to mirror directory information for others. Please do
## if you have enough bandwidth.
#DirPort 9030 # what port to advertise for directory connections
## If you want to listen on a port other than the one advertised in
## DirPort (e.g. to advertise 80 but bind to 9091), you can do it as
## follows.  below too. You'll need to do ipchains or other port
## forwarding yourself to make this work.
#DirPort 80 NoListen
#DirPort 127.0.0.1:9091 NoAdvertise
## Uncomment to return an arbitrary blob of html on your DirPort. Now you
## can explain what Tor is if anybody wonders why your IP address is
## contacting them. See contrib/tor-exit-notice.html in Tor's source
## distribution for a sample.
#DirPortFrontPage /etc/tor/tor-exit-notice.html

## Uncomment this if you run more than one Tor relay, and add the identity
## key fingerprint of each Tor relay you control, even if they're on
## different networks. You declare it here so Tor clients can avoid
## using more than one of your relays in a single circuit. See
## https://www.torproject.org/docs/faq#MultipleRelays
## However, you should never include a bridge's fingerprint here, as it would
## break its concealability and potentially reveal its IP/TCP address.
##
## If you are running multiple relays, you MUST set this option.
##
#MyFamily $keyid,$keyid,...

## Uncomment this if you do *not* want your relay to allow any exit traffic.
## (Relays allow exit traffic by default.)
#ExitRelay 0

## Uncomment this if you want your relay to allow IPv6 exit traffic.
## (Relays only allow IPv4 exit traffic by default.)
#IPv6Exit 1

## A comma-separated list of exit policies. They're considered first
## to last, and the first match wins.
##
## If you want to allow the same ports on IPv4 and IPv6, write your rules
## using accept/reject *. If you want to allow different ports on IPv4 and
## IPv6, write your IPv6 rules using accept6/reject6 *6, and your IPv4 rules
## using accept/reject *4.
##
## If you want to _replace_ the default exit policy, end this with either a
## reject *:* or an accept *:*. Otherwise, you're _augmenting_ (prepending to)
## the default exit policy. Leave commented to just use the default, which is
## described in the man page or at
## https://www.torproject.org/documentation.html
##
## Look at https://www.torproject.org/faq-abuse.html#TypicalAbuses
## for issues you might encounter if you use the default exit policy.
##
## If certain IPs and ports are blocked externally, e.g. by your firewall,
## you should update your exit policy to reflect this -- otherwise Tor
## users will be told that those destinations are down.
##
## For security, by default Tor rejects connections to private (local)
## networks, including to the configured primary public IPv4 and IPv6 addresses,
## and any public IPv4 and IPv6 addresses on any interface on the relay.
## See the man page entry for ExitPolicyRejectPrivate if you want to allow
## "exit enclaving".
##
#ExitPolicy accept *:6660-6667,reject *:* # allow irc ports on IPv4 and IPv6 but no more
#ExitPolicy accept *:119 # accept nntp ports on IPv4 and IPv6 as well as default exit policy
#ExitPolicy accept *4:119 # accept nntp ports on IPv4 only as well as default exit policy
#ExitPolicy accept6 *6:119 # accept nntp ports on IPv6 only as well as default exit policy
#ExitPolicy reject *:* # no exits allowed

## Bridge relays (or "bridges") are Tor relays that aren't listed in the
## main directory. Since there is no complete public list of them, even an
## ISP that filters connections to all the known Tor relays probably
## won't be able to block all the bridges. Also, websites won't treat you
## differently because they won't know you're running Tor. If you can
## be a real relay, please do; but if not, be a bridge!
#BridgeRelay 1
## By default, Tor will advertise your bridge to users through various
## mechanisms like https://bridges.torproject.org/. If you want to run
## a private bridge, for example because you'll give out your bridge
## address manually to your friends, uncomment this line:
#PublishServerDescriptor 0

## Configuration options can be imported from files or folders using the %include
## option with the value being a path. If the path is a file, the options from the
## file will be parsed as if they were written where the %include option is. If
## the path is a folder, all files on that folder will be parsed following lexical
## order. Files starting with a dot are ignored. Files on subfolders are ignored.
## The %include option can be used recursively.
#%include /etc/torrc.d/
#%include /etc/torrc.custom

User tor
PidFile /var/run/tor.pid
Log notice file /var/log/tor/notices.log
Log debug file /var/log/tor/debug.log
GeoIPFile /usr/share/tor/geoip
GeoIPv6File /usr/share/tor/geoip6
MaxCircuitDirtiness 60
ExitNodes {us}
StrictNodes 1

VirtualAddrNetworkIPv4 10.192.0.0/10
AutomapHostsSuffixes .onion,.exit
AutomapHostsOnResolve 1

#tor vlan
TransPort 10.1.1.1:9040
DNSPort 10.1.1.1:9053
SocksPort 10.1.1.1:9050

#torvpn
TransPort 10.1.200.1:9040
DNSPort 10.1.200.1:9053
SocksPort 10.1.200.1:9050

#SocksBindAddress 192.168.2.1:9050
#SocksBindAddress 192.168.1.1:9050

I will be creating documentation on how to create this network infrastructure for the community as promised. If you have any questions or feedback to improve this build, please feel free to pm me.

Thanks again to this awesome community and the people at openwrt/lede for makin a great product and working on an awesome project. This truly is wireless Freedom!

Sincerely,

A hummbly commited student

[UPDATE] As promised, I created the how-to on the OpenWrt wiki:
How to Setup Multiple OpenVPN Server to Different VLANs

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.