Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revisionBoth sides next revision
docs:guide-user:services:vpn:openconnect [2020/10/05 01:46] – [Basic Configuration: Router as SERVER] update vgaeteradocs:guide-user:services:vpn:openconnect:server [2023/10/14 05:17] – use service invocation vgaetera
Line 1: Line 1:
-====== OpenConnect ======  +====== OpenConnect server ====== 
-OpenConnect is an SSL-based VPN client which is inter-operable with the commercial products Cisco AnyConnect, Juniper Pulse Connect Secure, and Palo Alto Networks GlobalProtect.  (GlobalProtect mode is new in OpenConnect 8.0 and is not yet fully integrated into OpenWrt).  A companion VPN server ''ocserv'' which implements the AnyConnect protocol is also available for OpenWrt.  The rest of this page describes the ocserv server.  To set up an OpenConnect client, see [[docs:guide-user:services:vpn:openconnect-client]]+{{section>meta:infobox:howto_links#basic_skills&noheader&nofooter&noeditbutton}}
  
-This is a beginner's guide to setting up OpenConnect as a SERVICE (ocserv) on OpenWRT for use with a client running either the OpenConnect client or Cisco's Anyconnect.+===== Introduction ===== 
 +  * This how-to describes the method for setting up [[wp>OpenConnect|OpenConnect]] server on OpenWrt. 
 +  * Follow [[docs:guide-user:services:vpn:openconnect:client|OpenConnect client]] for client setup and [[docs:guide-user:services:vpn:openconnect:extras|OpenConnect extras]] for additional tuning.
  
-The primary goal of this HOWTO is to get a working OpenConnect tunnel with the least amount of compatability issues. Note that the instructions provided [[https://github.com/openwrt/packages/tree/master/net/ocserv|here]] did NOT WORK for me, and it seemed like there is an easier, more elegant solution as described in the [[http://www.infradead.org/ocserv/recipes-ocserv-pseudo-bridge.html|OpenConnect documentation on Pseudo-Bridging]].+===== Goals ===== 
 +{{section>docs:guide-user:services:vpn:wireguard:server#goals&noheader&nofooter&noeditbutton}}
  
-For an overview of all VPN-related articles (including other VPN technologies), see [[docs:guide-user:services:vpn:overview]].+===== Command-line instructions ===== 
 +==== 1. Preparation ==== 
 +Install the required packages. 
 +Specify configuration parameters for VPN server.
  
-===== Use Case (the beginner's configuration) ===== +<code bash> 
-The user wants a client to access their OpenWrt router and the network it supports on the back securely with a minimum of compatibility issues and minimum configuration fuss. The client can be a mobile user roaming on a mobile network OR at a public wifi hotspot, and wants to EITHER secure their traffic from eavesdropping, or access their private network.+# Install packages 
 +opkg update 
 +opkg install ocserv
  
-The end result will be an encrypted connection directly between the client (on the WAN side) and LAN side of the OpenWRT, such that the client effectively has access to the LAN side as if they were local, PLUS the benefits of their OpenWRT firewall for browsing the Internet.+# Configuration parameters 
 +VPN_PORT="4443" 
 +VPN_POOL="192.168.7.0 255.255.255.0" 
 +VPN_DNS="${VPN_POOL%.* *}.1" 
 +VPN_USER="USERNAME" 
 +VPN_PASS="PASSWORD" 
 +</code>
  
-Note that this is a FULL tunnel, meaning all traffic is routed through the VPN once connected. This is, in my opinion, the only type of tunnel to use, as a split tunnel is inherently insecureYou cannot, for example, secure your traffic from a public hotspot using a split tunnel since your banking traffic will go through the PUBLIC hotspot and not through your VPN tunnel.+==== 2Key management ==== 
 +Generate password hash for VPN client.
  
-===== Why use OpenConnect ===== +<code bash> 
-1) Your network provider is BLOCKING IPSEC traffic. This is apparently POLICY for mobile carriers, though they deny it. OpenConnect is SSL. +# Generate password hash 
-2) Your client only supports AnyConnect or the OpenConnect Client. (Blackberry, for example, does not support OpenVPN). +ocpasswd ${VPN_USER} << EOI 
-3) You just want a secure SSL-based VPN to your LAN. +${VPN_PASS} 
-The official site for Openconnect is [[http://www.infradead.org/openconnect/|Here]]+${VPN_PASS} 
 +EOI 
 +VPN_HASH="$(sed -n -e "/^${VPN_USER}:.*:/s///p" /etc/ocserv/ocpasswd)" 
 +</code>
  
-===== Basic Configuration: Router as SERVER ===== +==== 3. Firewall ==== 
-You will want the following packages: [[packages:pkgdata:ocserv]] + [[packages:pkgdata:luci-app-ocserv]]+Consider VPN network as private. 
 +Assign VPN interface to LAN zone to minimize firewall setup. 
 +Allow access to VPN server from WAN zone.
  
-One of the easiest setups is to configure the VPN as a pseudo-bridge with Proxy ARPWhat this means is that you will connect and be on the LAN side of your router with no additional routing needed, as if you were thereThe configuration is described in this recipe[[http://www.infradead.org/ocserv/recipes-ocserv-pseudo-bridge.html|recipe: ocserv pseudo bridge]].+<code bash> 
 +# Configure firewall 
 +uci rename firewall.@zone[0]="lan" 
 +uci rename firewall.@zone[1]="wan" 
 +uci del_list firewall.lan.device="vpns+" 
 +uci add_list firewall.lan.device="vpns+" 
 +uci -q delete firewall.oc 
 +uci set firewall.oc="rule" 
 +uci set firewall.oc.name="Allow-OpenConnect" 
 +uci set firewall.oc.src="wan" 
 +uci set firewall.oc.dest_port="4443" 
 +uci set firewall.oc.proto="tcp udp" 
 +uci set firewall.oc.target="ACCEPT" 
 +uci commit firewall 
 +service firewall restart 
 +</code>
  
-Router is configured at 192.168.1.1 +==== 4VPN service ==== 
-DHCP hosts are configured to use the range 192.168.1.2-192.168.1.50 +Configure VPN service.
-You want your VPN hosts to use the range 192.168.1.100 and have only 1-2 hosts connecting at any given time+
  
-1) Edit /etc/config/ocserv as follows, or use LUCI: +<code bash> 
-      config ocserv 'config+# Configure VPN service 
-           option enable '1'                                          +uci -q delete ocserv.config.enable 
-           option port '443'                                          +uci -q delete ocserv.config.zone 
-           option netmask '255.255.255.253'                           +uci set ocserv.config.port="${VPN_PORT}" 
-           option ipaddr '192.168.1.100'                             +uci set ocserv.config.ipaddr="${VPN_POOL% *}" 
-           option zone 'lan'           +uci set ocserv.config.netmask="${VPN_POOL#* }" 
-This will put your VPN clients at 192.168.1.100+Note that the netmask limits the of clients you can have to TWOChange as necessary+uci -q delete ocserv.@routes[0] 
-   NOTE: the above suggests port 443 as the preferred portThis is to support MOBILE clients.  +uci -q delete ocserv.@dns[0] 
-   Many mobile network operators are blocking other ports (despite the FCC open internet order),  +uci set ocserv.dns="dns" 
-   but they cannot block port 443, therefore 443 is more likely to work for the majority of mobil users+uci set ocserv.dns.ip="${VPN_DNS}" 
-    +uci -q delete ocserv.@ocservusers[0] 
-2) Add your DNS server+uci set ocserv.client="ocservusers" 
 +uci set ocserv.client.name="${VPN_USER}" 
 +uci set ocserv.client.password="${VPN_HASH}" 
 +uci commit ocserv 
 +service ocserv restart 
 +</code>
  
-       config dns                                                         +===== Testing ===== 
-           option ip '192.168.1.1'      +{{section>docs:guide-user:services:vpn:wireguard:server#testing&noheader&nofooter&noeditbutton}}
-      +
-3) Edit /etc/config/firewall or use LUCI and add the following rules: +
-    config rule                       +
-        option name 'Allow SSL vpn in (tcp)' +
-        option src 'wan'                     +
-        option proto 'tcp'                   +
-        option dest_port '443'               +
-        option target 'ACCEPT'               +
-                                             +
-    config rule                                  +
-        option name 'Allow SSL vpn in (udp)' +
-        option src 'wan'                     +
-        option proto 'udp'                   +
-        option dest_port '443'               +
-        option target 'ACCEPT'     +
-         +
-What this does is accept traffic for SSL on the WAN side.+
  
-4) Add the following to /etc/firewall.user (or use LUCI):+===== Troubleshooting ===== 
 +Collect and analyze the following information.
  
-    iptables -A input_rule -i vpns+ -j ACCEPT +<code bash> 
-    iptables -A forwarding_rule -i vpns+ -j ACCEPT +# Restart services 
-    iptables -A forwarding_rule -o vpns+ -j ACCEPT +service log restart; service ocserv restart; sleep 10
-    iptables -A output_rule -o vpns+ -j ACCEPT+
  
-What these do is allow traffic from the VPN interface(s).+# Log and status 
 +logread -e ocserv; netstat -l -n -p | grep -e ocserv
  
-Lastly: +# Runtime configuration 
-5) Edit /etc/sysctl.conf and add the following line: +pgrep -f -a ocserv 
-     net.ipv4.conf.all.proxy_arp=1+ip address show; ip route show table all 
 +ip rule show; ip -6 rule show; nft list ruleset
  
-Then type sysctl -p to reload the configuration file. The purpose is described in the recipe above. +# Persistent configuration 
- +uci show network; uci show firewall; uci show ocserv 
-5) Add users(and passwords) to your OpenConnect service. I find LUCI to be pretty easy to use for all of these steps. +</code>
- +
-FINALLY: Restart your firewall service and fire up the openconnect server to test it out. +
-That's all there is to it!+
  
  • Last modified: 2024/10/17 17:27
  • by andrewz