This is an old revision of the document!
Table of Contents
IPsec VPN Strongswan su Debian 10 Buster
Pacchetti da installare:
- strongswan - Metapacchetto: serve a installare i pacchetti realmente necessari grazie al meccanismo delle dipendenze.
- strongswan-starter - Interpreta i file di configurazione
/etc/ipsec.conf
e avvia il demonecharon
, installato per dipendenza diretta dastrongswan
estrongswan-charon
. - strongswan-charon - Demone Internet Key Exchange, installato per dipendenza diretta da
strongswan
.
La soluzione Debian supporta le connessioni IKEv1 e IKEv2.
In alternativa al pacchetto strongswan è possibile installare charon-systemd, che offre alcuni vantaggi in termini di semplicità di integrazione con systemd, ma non utilizza il tradizionale file di configurazione /etc/ipsec.conf né i tradizionali processi /usr/lib/ipsec/starter e /usr/lib/ipsec/charon.
Abilitare e avviare il servizio
In Debian 10 i servizi sono gestiti da systemd: ricordarsi di abilitare il servizio e se necessario avviarlo:
systemctl is-enabled strongswan.service systemctl enable strongswan.service systemctl start strongswan.service
Verifica
Per verificare lo stato della VPN si utilizza il comando ipsec statusall, ecco un esempio di output per una connessione funzionante:
ipsec statusall Status of IKE charon daemon (strongSwan 5.7.2, Linux 4.19.0-12-amd64, x86_64): uptime: 31 seconds, since Feb 04 09:53:12 2021 malloc: sbrk 2437120, mmap 0, used 601632, free 1835488 worker threads: 11 of 16 idle, 5/0/0/0 working, job queue: 0/0/0/0, scheduled: 3 loaded plugins: charon aes rc2 sha2 sha1 md5 mgf1 random nonce x509 .... Listening IP addresses: 132.82.168.98 192.168.1.2 Connections: office1-office2: 132.82.168.98...134.191.21.5 IKEv2, dpddelay=30s office1-office2: local: [132.82.168.98] uses pre-shared key authentication office1-office2: remote: [134.191.21.5] uses pre-shared key authentication office1-office2: child: 172.16.48.96/29 === 172.16.48.80/28 TUNNEL, dpdaction=restart Security Associations (1 up, 0 connecting): office1-office2[1]: ESTABLISHED 31 seconds ago, 132.82.168.98[132.82.168.98]...134.191.21.5[134.191.21.5] office1-office2[1]: IKEv2 SPIs: 16a74d9307ac7ef5_i* 40fc0fa3a279e9f9_r, pre-shared key reauthentication in 23 hours office1-office2[1]: IKE proposal: AES_CBC_256/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/MODP_1536 office1-office2{1}: INSTALLED, TUNNEL, reqid 1, ESP in UDP SPIs: cdd18e01_i 866f2f1a_o office1-office2{1}: AES_CBC_256/HMAC_SHA2_256_128, 578 bytes_i (10 pkts, 21s ago), ... office1-office2{1}: 172.17.48.96/29 === 172.17.48.80/28
Se la VPN non è attiva, l'output è vuoto.
Per avviare la VPN si può utilizzare il comando ipsec start (attenzione, perché questo comando avvia il demone fuori dal controllo di systemd).
ipsec start Starting strongSwan 5.7.2 IPsec [starter]...
In syslog si trovano le seguenti righe:
charon: 00[DMN] Starting IKE charon daemon (strongSwan 5.7.2, Linux 4.19.0-12-amd64, x86_64) charon: 07[IKE] initiating IKE_SA office1-office2[1] to 134.191.21.5 charon: 07[NET] sending packet: from 132.82.168.98[500] to 134.191.21.5[500] (932 bytes) charon: 09[NET] received packet: from 134.191.21.5[500] to 132.82.168.98[500] (360 bytes) charon: 09[IKE] authentication of '132.82.168.98' (myself) with pre-shared key charon: 09[IKE] establishing CHILD_SA office1-office2{1} charon: 10[IKE] CHILD_SA office1-office2{1} established with SPIs cdd18e01_i ...
In Debian 10, che utilizza systemd, è opportuno utilizzare systemctl invece di invocare direttamente ipsec (che supporta gli eventuali parametri stop
, restart
, status
, statusall
). Vedere sopra come abilitare e avviare il servizio.
Connessione PSK fallita
Ecco cosa appare in syslog quando una connessione fallisce per via della chiave condivisa PSK:
charon: 13[NET] received packet: from 134.191.21.5[500] to 132.82.168.98[500] (376 bytes) charon: 13[IKE] 134.191.21.5 is initiating an IKE_SA charon: 13[CFG] selected proposal: IKE:AES_CBC_256/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/MODP_1536 charon: 13[IKE] remote host is behind NAT charon: 14[CFG] looking for peer configs matching 132.82.168.98[%any]...134.191.21.5[134.191.21.5] charon: 14[CFG] selected peer config 'office1-office2' charon: 14[IKE] no shared key found for '%any' - '134.191.21.5' charon: 14[ENC] generating IKE_AUTH response 1 [ N(AUTH_FAILED) ]
Servizi systemd
- strongswan.service - Installato dal pacchetto
strongswan-starter
, è responsabile dell'avvio del processo/usr/lib/ipsec/starter
. - ipsec.service - Installato dal pacchetto
strongswan-starter
. Questo servizio viene abilitato, disabilitato, avviato o fermato automaticamente quando si agisce sustrongswan.service
.
Processi in esecuzione
- /usr/lib/ipsec/starter - Installato dal pacchetto
strongswan-starter
, è un processo invocato dal serviziostrongswan.service
che provvede a leggere/etc/ipsec.conf
. - /usr/lib/ipsec/charon - Installato dal pacchetto
strongswan-charon
, è il demone che provvede alla gestione di IKE (il protocollo per lo scambio delle chiavi).
Tool da riga di comando
- /usr/sbin/ipsec - Installato dal pacchetto
strongswan-starter
, viene utilizzato per invocare vari tool per la gestione di IPsec. A seconda del parametro passato interagisce con il processo starter oppure charon.
Alternativa charon-systemd
Questo demone, fornito dal pacchetto Debian charon-systemd, è alternativo al pacchetto strongswan; non utilizza le configurazioni di /etc/ipsec.conf né fa affidamento a /usr/lib/ipsec/starter. Il programma charon-systemd si interfaccia direttamente con systemd e utilizza il tool da riga di comando swanctl per configurare e comandare IPsec.
Il vantaggio di charon-systemd
rispetto a strongswan
è una maggiore integrazione con systemd
, per cui il servizio relativo ha una implementazione più semplice.
Pacchetti da installare per charon-systemd
- charon-systemd - Supporto systemd per IPsec client. Svolge funzioni analoghe al pacchetto
strongswan-charon
. - strongswan-swanctl - Viene installato per dipendenza diretta da
charon-systemd
. Contiene l'eseguibileswanctl
che è il tool da riga di comando per configurare, comandare e monitorare la VPN IPsec.
Servizi systemd per charon-systemd
- strongswan-swanctl.service - Installato dal pacchetto
charon-systemd
, il nome indica che il servizio basa il suo funzionamento sul toolswanctl
.
Processi in esecuzione per charon-systemd
- /usr/sbin/charon-systemd - Installato dal pacchetto
charon-systemd
, viene avviato dalstrongswan-swanctl.service
.
Debug charon-system
Nel caso in cui si sia fatta una configurazione tradizionale con /etc/ipsec.conf, ma si avvia il servizio charon-systemd, questo è il syslog con gli errori (il demone rileva lo scambio IKE, ma fallisce perché manca la configurazione):
charon-systemd[851]: received packet: from 134.191.21.5[500] to 132.82.168.98[500] (376 bytes) charon-systemd[851]: parsed IKE_SA_INIT request 0 [ SA KE No N(NATD_S_IP) N(NATD_D_IP) N(FRAG_SUP) ] charon-systemd[851]: no IKE config found for 132.82.168.98...134.191.21.5, sending NO_PROPOSAL_CHOSEN charon-systemd[851]: generating IKE_SA_INIT response 0 [ N(NO_PROP) ] charon-systemd[851]: sending packet: from 132.82.168.98[500] to 134.191.21.5[500] (36 bytes)