Skip to content

Instantly share code, notes, and snippets.

@jakubskrz
Last active August 15, 2023 19:19
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jakubskrz/b9f6a66591154d06573ee805dfb93608 to your computer and use it in GitHub Desktop.
Save jakubskrz/b9f6a66591154d06573ee805dfb93608 to your computer and use it in GitHub Desktop.
Turris - nastavení IKEv2 VPN

Nastavení IKEv2 VPN na routeru Turris

Tohle je krátký návod pro nastavení IKEv2 VPN pro router Turris, abych příště nemusel dlouze vzpomínat a řešit, jak jsem posledně vyřešil všechny problémy, aby mi to zatracené VPN konečně fungovalo. A možná to pomůže i někomu dalšímu.

Prerekvizity

V tomto návodu je předpokládáno, že Turris je dostupný na doméně vpn.turris.tld a využívá již existující SSL certifikát vydaný pro tuto doménu jinou CA. Nebudu se tedy již zabývat jak takový certifikát získat, ani postupem generování klientský certifikátů.

Ověřování klientů bude prováděno pouze pomocí kombinace jména a hesla, SSL certifikát je použit pouze pro ověření, že se připojujeme skutečně ke správnému routeru.

Instalace závislostí

V administračním rozhraní Foris povolíme balíky pro Rozšíření síťové podpory, tím dojde k instalaci všech potřebných balíků a navíc se nám Updater postará o jejich automatickou aktualizaci, oproti situaci, kdy balíky nainstalujeme ručně pomocí opkg.

Nastavení SSL certifikátu

Nahrajeme do routeru náš certifikát a veřejný certifikát naší CA. Osobně jsem použil certifikát od StartSSL, kde si můžete nechat vygenerovat jeden certifikát pro osobní potřebu zcela zdarma. Odpadá tak nutnost nahrávat vlastní veřejné certifikáty do klientů, kteří se budou připojovat k naší VPN, jelikož certifikáty od StartSSL jsou již ve většině zařízení obsaženy.

/etc/ipsec.d/private/privatekey.pem # Privátní klíč, který jsme použili při žádosti o náš certifikát
/etc/ipsec.d/cacerts/ca.crt # Veřejný certifikát naší CA pro ověření pravosti našeho certifikátu
/etc/ipsec.d/cacerts/intermediate.ca.crt # V závislosti na naší CA jich může být i více
/etc/ipsec.d/certs/vpn.turris.tld.crt # Privátní certifikát pro naši doménu

Nastavení IPSec

V souboru /etc/ipsec.secrets nastavíme uživatelská jména a hesla pro naše klienty a náš privátní klíč použitý k ověřování:

: RSA privatekey.pem

username : EAP "password"

V souboru /etc/ipsec.conf pak nastavíme parametry naší VPN:

config setup

	# Díky této volbě se bude moci jeden uživatel připojit z více zařízení najednou
	uniqueids=no
	strictcrlpolicy=no

conn %default

	dpdaction=clear
	dpddelay=35s
	dpdtimeout=2000s

	keyexchange=ikev2
	auto=add
	rekey=no
	reauth=no
	fragmentation=yes

	# left - nastavení serveru
	left=%any
	leftcert=vpn.turris.tld.crt
	leftsendcert=always
	leftsubnet=0.0.0.0/0
	
	# right - nastavení klienta
	right=%any
	eap_identity=%identity
	rightsourceip=%dhcp
	rightdns=192.168.1.1

conn IPSec-IKEv2-EAP
	leftid=vpn.turris.tld
	rightauth=eap-mschapv2
	rightsendcert=never

Jako DNS server využijeme přímo náš Turris, pokud jste si přenastavili výchozí rozsah IP adres pro LAN, nezapomeňte nahradit adresu 192.168.1.1 za správnou. Ve spoustě návodů je pro DNS uváděno nastavení na Google DNS (8.8.8.8), ale proč bychom to dělali, vždyť máme k dispozici takovou šikovnou mašinku jako je Turris, který podporuje i DNSSEC.

Nastavení firewallu

VPN nám nebude fungovat, pokud ve firewallu nepovolíme UDP komunikaci na portech 500 a 4500.

screen firewall

Také jsem si pro VPN vytvořil samostatnou zónu pro firewall, i když už si nejsem úplně jistý z jakých důvodů jsem to vlastně provedl :) Vše by mělo správně fungovat i v případě, že zahrnete ipsec rozhraní do LAN zóny, ale takhle vypadá moje aktuální konfigurace.

Pro fyzické rozhraní ipsec0 (vznikne automaticky spuštěním ipsec služby) jsem si vytvořil síťový interface VPN, kterému jsem přidělil statickou IP 192.168.250.1, stejnou IP nastavíme jako DHCP server, jako adresu DNS pak 192.168.1.1. Prakticky jsem okopíroval nastavení LANu, jen s rozdílem že jsem VPN vyhradil samostatný subnet 192.168.250.0 ;)

Takhle vypadá nastavení pro VPN interface...

screen interface

...a na téhle záložce do něj zahrneme konkrétní fyzické rozhraní

screen interface2

Následně na obrazovce Network - Firewall přidáme novou zónu, jméno může být libovolné, já zcela originálně zvolil VPN a jako pokryté sítě zaškrtneme v předchozím kroku vytvořené rozhraní VPN. Poté je důležité nastavit forwading z nové VPN zóny do WANu, jinak se klienti nedostanou se do internetu, a také do LANu, jinak se nedostanou dále než na routeru. A také povolíme forwading z LAN do nové zóny VPN, aby zařízení z domácí sítě byla schopná komunikovat se zařízeními připojenými k VPN.

screen zone

screen zone

Řešení potíží

V dokonalém světě by nám již naše VPN měla krásně fungovat, realita je ale jako obvykle jiná. IPsec se totiž odmítá spustit s tvrzením, že nemůže nahrát některé pluginy. Protože tento návod píšu zpětně s odstupem několika týdnů a nenapsal jsem si konrétní poznámky, je možné že tato sekce návodu nebude úplně kompletní.

Ale pokud si správně pamatuji, problém byl s pluginy nonce a sha1. To jsem vyřešil vytvořením konfiguračních souborů pro tyto pluginy, ve kterých jsem zakázal jejich načtení.

Vytvoříme tedy soubor /etc/strongswan.d/charon/nonce.conf s obsahem:

nonce {

	# Whether to load the plugin. Can also be an integer to increase the
	# priority of this plugin.
	load = no

}

a soubor /etc/strongswan.d/charon/sha1.conf:

sha1 {

	# Whether to load the plugin. Can also be an integer to increase the
	# priority of this plugin.
	load = no

}

Hotovo

Tak, nyní by již mělo vše fungovat, na závěr jen povolíme aby ipsec spouštělo automaticky i po restartu:

/etc/init.d/ipsec enable

Je možné, že jsem něco vynechl, pokud budete následovat tento návod a nebude se vám dařit, dejte mi vědět, ať můžu nutné kroky doplnit, díky!

Na závěr chci poděkovat hlavně Ondřeji Caletkovi, neboť jsem při nastavování VPN a firewallu využil spoustu jeho rad z fóra a i nápad na využití certifikátu od StartSSL, namísto generování vlastního, jsem pochytil v nějakém z jeho starších příspěvků na fóru.

Zdroje

Seznam dalších zdrojů, z kterých jsem vycházel:

@iBobik
Copy link

iBobik commented Nov 14, 2016

@jakubskrz Zkoušel jsi to na Turris Omnia nebo na starém?

V Omnii to vypadá, že není nainstlaováno IPsec i se zapnutým Rozšíření síťové podpory (nenašel jsem /etc/ipsec.conf apod). Po vyhledání balíčků co mají v názvu "IPsec" jich to najde hodně, ale není mi jasné které z nich jsou ty pravé. Poradil bys, prosím?

- Název balíčku Verze Size (.ipk) Popis
Instalovat ipsec-tools 0.8.2-4 294672 IPsec management tools
Instalovat iptables-mod-ipsec 1.4.21-3 7180 iptables extensions for matching ipsec traffic. Matches: - ah - esp - policy
Instalovat kmod-crypto-authenc 4.4.13+9-1-05df79f635..6-9 4278 Combined mode wrapper for IPsec
Instalovat kmod-ipsec 4.4.13+9-1-05df79f635..6-9 34684 Kernel modules for IPsec support in both IPv4 and IPv6. Includes: - af_key - xfrm_ipcomp - xfrm_user
Instalovat kmod-ipsec4 4.4.13+9-1-05df79f635..6-9 13972 Kernel modules for IPsec support in IPv4. Includes: - ah4 - esp4 - ipcomp4 - xfrm4_mode_beet - xfrm4_mode_transport - xfrm4_mode_tunnel - xfrm4_tunnel
Instalovat kmod-ipsec6 4.4.13+9-1-05df79f635..6-9 14509 Kernel modules for IPsec support in IPv6. Includes: - ah6 - esp6 - ipcomp6 - xfrm6_mode_beet - xfrm6_mode_transport - xfrm6_mode_tunnel - xfrm6_tunnel
Instalovat kmod-ipt-ipsec 4.4.13+9-1-05df79f635..6-9 3981 Netfilter (IPv4) modules for matching IPSec packets Includes: - ah - esp - policy
Instalovat kmod-wireguard 4.4.13+0.0.20160630-1 56439 WireGuard is a novel VPN that runs inside the Linux Kernel and utilizes state-of-the-art cryptography. It aims to be faster, simpler, leaner, and more useful than IPSec, while avoiding the massive headache. It intends to be considerably more performant than OpenVPN. WireGuard is designed as a general purpose VPN for running on embedded interfaces and super computers alike, fit for many different circumstances. It runs over UDP. This package provides the kernel module for wireguard.
Instalovat opennhrp 0.14.1-3 46983 OpenNHRP implements NBMA Next Hop Resolution Protocol (as defined in RFC 2332). It makes it possible to create dynamic multipoint VPN Linux router using NHRP, GRE and IPsec. It aims to be Cisco DMVPN compatible.
Instalovat openvswitch-ipsec 2.5.0-22d4614ddf83988..55a 6408 The ovs-monitor-ipsec script provides support for encrypting GRE tunnels with IPsec.
Instalovat strongswan 5.3.5-1 138879 StrongSwan is an OpenSource IPsec implementation for the Linux operating system. This package contains shared libraries and scripts.
Instalovat strongswan-charon 5.3.5-1 190606 StrongSwan is an OpenSource IPsec implementation for the Linux operating system. This package contains charon, an IKEv2 keying daemon.
Instalovat strongswan-default 5.3.5-1 1211 StrongSwan is an OpenSource IPsec implementation for the Linux operating system. This meta-package contains only dependencies to match upstream defaults.
Instalovat strongswan-full 5.3.5-1 1474 StrongSwan is an OpenSource IPsec implementation for the Linux operating system. This meta-package contains dependencies for all of the strongswan plugins except kernel-libipsec, socket-dynamic and which are omitted in favor of the kernel-netlink and socket-default plugins.
Instalovat strongswan-isakmp 5.3.5-1 1238 StrongSwan is an OpenSource IPsec implementation for the Linux operating system. This meta-package contains only dependencies to establish ISAKMP / IKE PSK connections, dropping other capabilities in favor of small size Can fit most routers even with 4Mb flash (after removing IPv6 support).
Instalovat strongswan-libtls 5.3.5-1 35801 StrongSwan is an OpenSource IPsec implementation for the Linux operating system. This package contains libtls for strongSwan plugins eap-tls, eap-ttls, eap-peap, tnc-tnccs
Instalovat strongswan-minimal 5.3.5-1 1134 StrongSwan is an OpenSource IPsec implementation for the Linux operating system. This meta-package contains only dependencies for a minimal IKEv2 setup.
Instalovat strongswan-mod-kernel-libipsec 5.3.5-1 21366 StrongSwan libipsec kernel interface plugin
Instalovat strongswan-utils 5.3.5-1 42973 StrongSwan is an OpenSource IPsec implementation for the Linux operating system. This package contains the pki & scepclient utilities.
Instalovat uanytun 0.3.5-2 23558 uAnytun is a tiny implementation of SATP the secure anycast tunneling protocol. SATP defines a protocol used for communication between any combination of unicast and anycast tunnel endpoints. It has less protocol overhead than IPSec in Tunnel mode and allows tunneling of every ETHER TYPE protocol (e.g. ethernet, ip, arp ...). SATP directly includes cryptography and message authentication based on the methods used by SRTP. It is intended to deliver a generic, scalable and secure solution for tunneling and relaying of packets of any protocol. Unlike Anytun which is a full featured implementation uAnytun has no support for multiple connections or synchronisation. It is a small single threaded implementation intended to act as a client on small platforms.
Instalovat uanytun-nettle 0.3.5-2 22933 uAnytun is a tiny implementation of SATP the secure anycast tunneling protocol. SATP defines a protocol used for communication between any combination of unicast and anycast tunnel endpoints. It has less protocol overhead than IPSec in Tunnel mode and allows tunneling of every ETHER TYPE protocol (e.g. ethernet, ip, arp ...). SATP directly includes cryptography and message authentication based on the methods used by SRTP. It is intended to deliver a generic, scalable and secure solution for tunneling and relaying of packets of any protocol. Unlike Anytun which is a full featured implementation uAnytun has no support for multiple connections or synchronisation. It is a small single threaded implementation intended to act as a client on small platforms.
Instalovat uanytun-nocrypt 0.3.5-2 18432 uAnytun is a tiny implementation of SATP the secure anycast tunneling protocol. SATP defines a protocol used for communication between any combination of unicast and anycast tunnel endpoints. It has less protocol overhead than IPSec in Tunnel mode and allows tunneling of every ETHER TYPE protocol (e.g. ethernet, ip, arp ...). SATP directly includes cryptography and message authentication based on the methods used by SRTP. It is intended to deliver a generic, scalable and secure solution for tunneling and relaying of packets of any protocol. Unlike Anytun which is a full featured implementation uAnytun has no support for multiple connections or synchronisation. It is a small single threaded implementation intended to act as a client on small platforms.
Instalovat uanytun-sslcrypt 0.3.5-2 22912 uAnytun is a tiny implementation of SATP the secure anycast tunneling protocol. SATP defines a protocol used for communication between any combination of unicast and anycast tunnel endpoints. It has less protocol overhead than IPSec in Tunnel mode and allows tunneling of every ETHER TYPE protocol (e.g. ethernet, ip, arp ...). SATP directly includes cryptography and message authentication based on the methods used by SRTP. It is intended to deliver a generic, scalable and secure solution for tunneling and relaying of packets of any protocol. Unlike Anytun which is a full featured implementation uAnytun has no support for multiple connections or synchronisation. It is a small single threaded implementation intended to act as a client on small platforms.
Instalovat vpnc 0.5.3.r550-5 54538 A VPN client compatible with Cisco's EasyVPN equipment. Supports IPSec (ESP) with Mode Configuration and Xauth. Supports only shared-secret IPSec authentication with Xauth, AES (256, 192, 128), 3DES, 1DES, MD5, SHA1, DH1/2/5 and IP tunneling.
Instalovat wireguard-tools 0.0.20160630-1 20372 WireGuard is a novel VPN that runs inside the Linux Kernel and utilizes state-of-the-art cryptography. It aims to be faster, simpler, leaner, and more useful than IPSec, while avoiding the massive headache. It intends to be considerably more performant than OpenVPN. WireGuard is designed as a general purpose VPN for running on embedded interfaces and super computers alike, fit for many different circumstances. It runs over UDP. This package provides the userspace control program for wireguard: wg.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment