Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision Next revisionBoth sides next revision | ||
| docs:guide-user:services:vpn:openconnect:server [2020/10/17 06:50] – [Server] optimize code vgaetera | docs:guide-user:services:vpn:openconnect:server [2023/03/25 10:46] – [2. Key management] vgaetera | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== OpenConnect server ====== | + | ====== 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. | + | {{section> |
| - | (GlobalProtect mode is new in OpenConnect 8.0 and is not yet fully integrated into OpenWrt). | + | |
| - | A companion VPN server '' | + | |
| - | The rest of this page describes the ocserv server. | + | |
| - | To set up an OpenConnect client, see [[docs:guide-user:services: | + | |
| - | This is a beginner' | + | ===== Introduction ===== |
| + | * This how-to describes the method for setting up [[wp>OpenConnect|OpenConnect]] server | ||
| + | * Follow [[docs: | ||
| - | 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:// | + | ===== Goals ===== |
| + | {{section> | ||
| - | ===== Use case (the beginner' | + | ===== Command-line instructions |
| - | 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. | + | ==== 1. Preparation ==== |
| - | 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, | + | Install |
| + | Specify configuration parameters for VPN server. | ||
| - | 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. | + | <code bash> |
| + | # Install packages | ||
| + | opkg update | ||
| + | opkg install ocserv | ||
| - | 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 insecure. | + | # Configuration parameters |
| - | You 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. | + | VPN_PORT=" |
| + | VPN_POOL=" | ||
| + | VPN_DNS=" | ||
| + | VPN_USER=" | ||
| + | VPN_PASS=" | ||
| + | </ | ||
| - | ===== Why use OpenConnect ===== | + | ==== 2. Key management |
| - | * Your network provider is BLOCKING IPSEC traffic. This is apparently POLICY | + | Generate password hash for VPN client. |
| - | * Your client | + | |
| - | * You just want a secure SSL-based VPN to your LAN. | + | |
| - | + | ||
| - | [[http:// | + | |
| - | + | ||
| - | ===== Server ===== | + | |
| - | You will want the following packages: [[packages: | + | |
| - | + | ||
| - | One of the easiest setups is to configure the VPN as a pseudo-bridge with Proxy ARP. | + | |
| - | What 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 there. | + | |
| - | The configuration is described in this recipe[[http:// | + | |
| - | + | ||
| - | Router is configured at 192.168.1.1 | + | |
| - | DHCP hosts are configured to use the range 192.168.1.2-192.168.1.50 | + | |
| - | 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 VPN service configuration: | + | |
| <code bash> | <code bash> | ||
| - | # / | + | # Generate password hash |
| - | + | ocpasswd ${VPN_USER} << EOI | |
| - | config ocserv ' | + | ${VPN_PASS} |
| - | | + | ${VPN_PASS} |
| - | | + | EOI |
| - | | + | VPN_HASH=" |
| - | option ipaddr ' | + | |
| - | option zone ' | + | |
| </ | </ | ||
| - | This will put your VPN clients at 192.168.1.100+. | + | ==== 3. Firewall ==== |
| - | Note that the netmask limits the # of clients you can have to TWO. | + | Consider VPN network |
| - | Change | + | Assign VPN interface to LAN zone to minimize firewall setup. |
| - | + | Allow access | |
| - | NOTE: the above suggests port 443 as the preferred port. | + | |
| - | This is to support MOBILE clients. | + | |
| - | Many mobile network operators are blocking other ports (despite the FCC open internet order), but they cannot block port 443, therefore 443 is more likely | + | |
| - | + | ||
| - | 2) Add your DNS server: | + | |
| <code bash> | <code bash> | ||
| - | config dns | + | # Configure firewall |
| - | | + | uci rename firewall.@zone[0]=" |
| + | uci rename firewall.@zone[1]=" | ||
| + | uci del_list firewall.lan.device=" | ||
| + | uci add_list firewall.lan.device=" | ||
| + | uci -q delete firewall.oc | ||
| + | uci set firewall.oc=" | ||
| + | uci set firewall.oc.name=" | ||
| + | uci set firewall.oc.src=" | ||
| + | uci set firewall.oc.dest_port=" | ||
| + | uci set firewall.oc.proto=" | ||
| + | uci set firewall.oc.target=" | ||
| + | uci commit firewall | ||
| + | / | ||
| </ | </ | ||
| - | 3) Edit firewall configuration: | + | ==== 4. VPN service ==== |
| + | Configure VPN service. | ||
| <code bash> | <code bash> | ||
| - | # /etc/config/firewall | + | # Configure VPN service |
| - | + | uci -q delete ocserv.config.enable | |
| - | config | + | uci -q delete ocserv.config.zone |
| - | | + | uci set ocserv.config.port=" |
| - | | + | uci set ocserv.config.ipaddr=" |
| - | | + | uci set ocserv.config.netmask=" |
| - | | + | uci -q delete ocserv.@routes[0] |
| - | | + | uci -q delete ocserv.@dns[0] |
| + | uci set ocserv.dns=" | ||
| + | uci set ocserv.dns.ip=" | ||
| + | uci -q delete ocserv.@ocservusers[0] | ||
| + | uci set ocserv.client=" | ||
| + | uci set ocserv.client.name=" | ||
| + | uci set ocserv.client.password=" | ||
| + | uci commit ocserv | ||
| + | / | ||
| </ | </ | ||
| - | What this does is accept traffic for SSL on the WAN side. | + | ===== Testing ===== |
| + | {{section> | ||
| - | 4) Add custom firewall rules: | + | ===== Troubleshooting ===== |
| + | Collect and analyze the following information. | ||
| <code bash> | <code bash> | ||
| - | cat << EOF >> | + | # Restart services |
| - | iptables -A input_rule -i vpns+ -j ACCEPT | + | /etc/init.d/log restart; |
| - | iptables -A forwarding_rule -i vpns+ -j ACCEPT | + | |
| - | iptables -A forwarding_rule -o vpns+ -j ACCEPT | + | |
| - | iptables -A output_rule -o vpns+ -j ACCEPT | + | |
| - | EOF | + | |
| - | / | + | |
| - | </ | + | |
| - | What these do is allow traffic from the VPN interface(s). | + | # Log and status |
| + | logread -e ocserv; netstat -l -n -p | grep -e ocserv | ||
| - | 5) Modify kernel parameters: | + | # Runtime configuration |
| + | pgrep -f -a ocserv | ||
| + | ip address show; ip route show table all | ||
| + | ip rule show; ip -6 rule show; nft list ruleset | ||
| - | <code bash> | + | # Persistent configuration |
| - | cat << EOF >> / | + | uci show network; uci show firewall; uci show ocserv |
| - | net.ipv4.conf.all.proxy_arp=1 | + | |
| - | EOF | + | |
| - | / | + | |
| </ | </ | ||
| - | |||
| - | 5) Add users (and passwords) to your OpenConnect service. | ||
| - | I find LuCI to be pretty easy to use for all of these steps. | ||
| - | |||
| - | FINALLY: Fire up the OpenConnect server to test it out. | ||
| - | That's all there is to it! | ||