Torna agli aggiornamenti
New releaseSep 8, 2026

strongswan v6.1.0

strongSwan - VPN basata su IPsec

Condividi

Configurazione di strongSwan

Panoramica

strongSwan è una soluzione VPN OpenSource basata su IPsec.

Questo documento è solo una breve introduzione al comando swanctl di strongSwan, che usa la moderna vici Versatile IKE Configuration Interface. Il comando ipsec deprecato, che usa l'interfaccia di configurazione legacy stroke, è descritto qui. Per informazioni più dettagliate consultare le pagine man, il nostro nuovo sito di documentazione e la wiki legacy.

Avvio rapido

I certificati per utenti, host e gateway sono emessi da una fittizia CA strongSwan. Negli scenari di esempio, il certificato CA strongswanCert.pem deve essere presente su tutti gli endpoint VPN per poter autenticare i peer. Per la vostra specifica applicazione VPN potete usare certificati di una qualsiasi CA di terze parti oppure generare voi stessi le chiavi private e i certificati necessari con lo strumento pki di strongSwan, il cui utilizzo verrà spiegato in una delle sezioni seguenti.

Caso Site-to-Site

In questo scenario due security gateway moon e sun collegano tra loro le due sottoreti moon-net e sun-net attraverso un tunnel VPN instaurato tra i due gateway:

10.1.0.0/16 -- | 192.168.0.1 | === | 192.168.0.2 | -- 10.2.0.0/16
  moon-net          moon                 sun           sun-net

Configurazione sul gateway moon:

/etc/swanctl/x509ca/strongswanCert.pem
/etc/swanctl/x509/moonCert.pem
/etc/swanctl/private/moonKey.pem

/etc/swanctl/swanctl.conf:

    connections {
        net-net {
            remote_addrs = 192.168.0.2

            local {
                auth = pubkey
                certs = moonCert.pem
            }
            remote {
                auth = pubkey
                id = "C=CH, O=strongSwan, CN=sun.strongswan.org"
            }
            children {
                net-net {
                    local_ts  = 10.1.0.0/16
                    remote_ts = 10.2.0.0/16
                    start_action = trap
                }
            }
        }
    }

Configurazione sul gateway sun:

/etc/swanctl/x509ca/strongswanCert.pem
/etc/swanctl/x509/sunCert.pem
/etc/swanctl/private/sunKey.pem

/etc/swanctl/swanctl.conf:

    connections {
        net-net {
            remote_addrs = 192.168.0.1

            local {
                auth = pubkey
                certs = sunCert.pem
            }
            remote {
                auth = pubkey
                id = "C=CH, O=strongSwan, CN=moon.strongswan.org"
            }
            children {
                net-net {
                    local_ts  = 10.2.0.0/16
                    remote_ts = 10.1.0.0/16
                    start_action = trap
                }
            }
        }
    }

Le identità locali e remote usate in questo scenario sono i subjectDistinguishedNames contenuti nei certificati end entity. I certificati e le chiavi private vengono caricati nel demone charon con il comando

swanctl --load-creds

mentre

swanctl --load-conns

carica le connessioni definite in swanctl.conf. Con start_action = trap la connessione IPsec viene stabilita automaticamente al primo pacchetto IP in chiaro che vuole attraversare il tunnel.

Caso Host-to-Host

Questa è una configurazione tra due singoli host che non hanno una sottorete alle loro spalle. Sebbene la modalità transport IPsec sarebbe sufficiente per le connessioni host-to-host, useremo la modalità tunnel IPsec predefinita.

| 192.168.0.1 | === | 192.168.0.2 |
     moon                sun

Configurazione sull'host moon:

/etc/swanctl/x509ca/strongswanCert.pem
/etc/swanctl/x509/moonCert.pem
/etc/swanctl/private/moonKey.pem

/etc/swanctl/swanctl.conf:

    connections {
        host-host {
            remote_addrs = 192.168.0.2

            local {
                auth=pubkey
                certs = moonCert.pem
            }
            remote {
                auth = pubkey
                id = "C=CH, O=strongSwan, CN=sun.strongswan.org"
            }
            children {
                net-net {
                    start_action = trap
                }
            }
        }
    }

Configurazione sull'host sun:

/etc/swanctl/x509ca/strongswanCert.pem
/etc/swanctl/x509/sunCert.pem
/etc/swanctl/private/sunKey.pem

/etc/swanctl/swanctl.conf:

    connections {
        host-host {
            remote_addrs = 192.168.0.1

            local {
                auth = pubkey
                certs = sunCert.pem
            }
            remote {
                auth = pubkey
                id = "C=CH, O=strongSwan, CN=moon.strongswan.org"
            }
            children {
                host-host {
                    start_action = trap
                }
            }
        }
    }

Caso Roadwarrior

Questo è un caso molto comune in cui un gateway strongSwan serve un numero arbitrario di client VPN remoti, che in genere hanno indirizzi IP dinamici.

10.1.0.0/16 -- | 192.168.0.1 | === | x.x.x.x |
  moon-net          moon              carol

Configurazione sul gateway moon:

/etc/swanctl/x509ca/strongswanCert.pem
/etc/swanctl/x509/moonCert.pem
/etc/swanctl/private/moonKey.pem

/etc/swanctl/swanctl.conf:

    connections {
        rw {
            local {
                auth = pubkey
                certs = moonCert.pem
                id = moon.strongswan.org
            }
            remote {
                auth = pubkey
            }
            children {
                net-net {
                    local_ts  = 10.1.0.0/16
                }
            }
        }
    }

Configurazione sul roadwarrior carol:

/etc/swanctl/x509ca/strongswanCert.pem
/etc/swanctl/x509/carolCert.pem
/etc/swanctl/private/carolKey.pem

/etc/swanctl/swanctl.conf:

    connections {
        home {
            remote_addrs = moon.strongswan.org

            local {
                auth = pubkey
                certs = carolCert.pem
                id = [email protected]
            }
            remote {
                auth = pubkey
                id = moon.strongswan.org
            }
            children {
                home {
                    local_ts  = 10.1.0.0/16
                    start_action = start
                }
            }
        }
    }

Per remote_addrs è stato scelto il nome host moon.strongswan.org, che verrà risolto dal DNS in fase di esecuzione nel corrispondente indirizzo IP di destinazione. In questo scenario l'identità del roadwarrior carol è l'indirizzo email [email protected], che deve essere incluso come subjectAlternativeName nel certificato roadwarrior carolCert.pem.

Caso Roadwarrior con IP Virtuale

I roadwarrior di solito hanno indirizzi IP dinamici assegnati dall'ISP a cui sono attualmente collegati. Per semplificare il routing da moon-net verso il client di accesso remoto carol, sarebbe desiderabile che il roadwarrior avesse un indirizzo IP interno scelto da un pool predefinito.

10.1.0.0/16 -- | 192.168.0.1 | === | x.x.x.x | -- 10.3.0.1
  moon-net          moon              carol       virtual IP

Categorie