User Tools

Site Tools


doc:appunti:linux:sa:ipsec

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
doc:appunti:linux:sa:ipsec [2015/09/21 18:36] – [Client Router DrayTek Vigor 2500/2600 con IP statico e LAN] niccolodoc:appunti:linux:sa:ipsec [2018/01/08 12:24] (current) – [Configurazione Debian 8 Jessie] niccolo
Line 1: Line 1:
 ====== IPSEC con Debian GNU/Linux ====== ====== IPSEC con Debian GNU/Linux ======
  
 +===== Configurazione Debian 8 Jessie =====
 +
 +IPSEC - su una distribuzione Debian moderna - si basa sui servizi **Setkey** e **Racoon**, questi servizi si avviano con **systemd**.
 +
 +Configuriamo ad esempio  una VPN con nome **static-psk-test**, con indirizzi IP statici e pre-shared key. Gli indirizzi IP privati e pubblici in questione sono:
 +
 +(LAN 192.168.10.0/24) -> (Firewall 5.10.168.170)  <->  (Firewall 5.20.195.220) <- (LAN 192.168.20.0/24)
 +
 +In generale i file di configurazione sono questi (si esamina il firewall 5.10.168.170):
 +
 +**/etc/ipsec-tools.d/static-psk-test.conf**
 +
 +<file>
 +spdadd 192.168.10.0/24  192.168.20.0/24  any -P out ipsec esp/tunnel/5.10.168.170-5.20.195.220/unique;
 +spdadd 192.168.20.0/24  192.168.10.0/24  any -P in  ipsec esp/tunnel/5.20.195.220-5.10.168.170/unique;
 +</file>
 +
 +**/etc/racoon/racoon.conf**
 +
 +<file>
 +include "/etc/racoon/static-psk-test.conf";
 +</file>
 +
 +**/etc/racoon/static-psk-test.conf**
 +
 +<file>
 +remote 5.20.195.220 {
 +    exchange_mode main;
 +    proposal {
 +        encryption_algorithm 3des;
 +        hash_algorithm md5;
 +        authentication_method pre_shared_key;
 +        dh_group modp1024;
 +    }
 +    # Verifica l'identita' del peer su psk.txt con l'indirizzo IP.
 +    peers_identifier address "5.20.195.220";
 +    verify_identifier on;
 +    initial_contact on;
 +    lifetime time 86400 seconds;
 +    #proposal_check obey;
 +    #nat_traversal on;
 +}
 +
 +sainfo address 192.168.10.0/24 any address 192.168.20.0/24 any {
 +    encryption_algorithm 3des;
 +    authentication_algorithm hmac_md5,hmac_sha1;
 +    compression_algorithm deflate;
 +    lifetime time 43200 seconds;
 +}
 +</file>
 +
 +**NOTA**: Se non si usa l'opzione **proposal_check obey** è necessario impostare le stesse identiche opzioni tra le due parti, compresi i **lifetime time**, ecc., altrimenti la connessione fallisce. Per effettuare il debug dei parametri non corrispondenti è necessario impostare almeno **log debug** in **/etc/racoon/racoon.conf**.
 +
 +**/etc/racoon/psk.txt**
 +
 +<file>
 +5.20.195.220    nai5Ohmo
 +</file>
 +
 +Per fermare e riavviare il servizio:
 +
 +<code>
 +systemctl stop racoon
 +systemctl stop setkey
 +
 +systemctl start setkey
 +systemctl start racoon
 +</code>
 +
 +Il traffico IPSEC va ovviamente gestito in maniera opportuna poiché non corrisponde al criterio standard MASQUERADE di iptables. Ad esempio [[#configurazione_firewall_shorewall|Shorewall]] ha delle direttive apposite per gestire IPSEC.
 +
 +In generale si potrà testare la VPN con un ping, a patto di usare gli indirizzi IP sul lato LAN:
 +
 +<code>
 +ping -I 192.168.10.254 192.168.20.1
 +</code>
 ===== Pezzi di IPSEC per Linux ===== ===== Pezzi di IPSEC per Linux =====
  
Line 368: Line 444:
 } }
  
-# 
-# Connection mariabarbara 
-# 
 remote 217.19.150.165 { remote 217.19.150.165 {
         proposal {         proposal {
Line 445: Line 518:
 </file> </file>
  
 +==== Initiator dietro NAT verso server passivo ====
 +
 +Se il cliente/initiator non ha un IP pubblico, ma sta dietro il NAT di un router, occorrono alcuni aggiustamenti alla configurazione.
 +
 +L'indirizzo del client è **10.0.1.2** (IP privato, dietro NAT), il server ha indirizzo **82.63.172.2**, la PSK è associata a tale IP in **''/etc/racoon/psk.txt''**, la rete privata da raggiungere presso il server è **192.168.100.0/24**.
 +
 +<file>
 +listen {
 +        isakmp 10.0.1.2;
 +        isakmp_natt 10.0.1.2 [4500];
 +        strict_address;
 +}
 +
 +remote 82.63.172.2 {
 +        nat_traversal on;
 +        exchange_mode aggressive;
 +        my_identifier fqdn "vpn.nat-client.net";
 +        # Verifica l'identita' del peer su /etc/racoon/psk.txt con l'indirizzo IP.
 +        peers_identifier address "82.63.172.2";
 +        lifetime time 21600 sec;
 +        proposal_check strict;
 +        proposal {
 +                encryption_algorithm 3des;
 +                hash_algorithm md5;
 +                authentication_method pre_shared_key;
 +                # For aggressive mode, it must be the same on both ends.
 +                dh_group modp1024;
 +        }
 +}
 +
 +sainfo address 10.0.1.0/24 any address 192.168.100.0/24 any {
 +        pfs_group modp1024;
 +        lifetime time 12 hour;
 +        encryption_algorithm 3des, blowfish, des, rijndael;
 +        authentication_algorithm hmac_sha1, hmac_md5;
 +        compression_algorithm deflate;
 +}
 +</file>
 +
 +Nel file **''/etc/ipsec-tools.d/82.63.172.2.conf''** si mette:
 +
 +<file>
 +spdadd 10.0.1.0/24       192.168.100.0/24  any -P out ipsec esp/tunnel/10.0.1.2-82.63.172.2/unique;
 +spdadd 192.168.100.0/24  10.0.1.0/24       any -P in  ipsec esp/tunnel/82.63.172.2-10.0.1.2/unique;
 +</file>
 ===== Configurazione firewall Shorewall ===== ===== Configurazione firewall Shorewall =====
  
doc/appunti/linux/sa/ipsec.1442853372.txt.gz · Last modified: 2015/09/21 18:36 by niccolo