J'ai déjà détaillé dans un article précédent comment configurer un VPN IPsec multisite en combinant Racoon et strongSwan ici : Comment configurer un VPN IPsec multisite avec Racoon et strongSwan. Comme Racoon est désormais obsolète, je vais décrire ici comment configurer une architecture de VPN IPsec multisite, mais uniquement avec strongSwan.
Commençons par la configuration du site principal. Pour rappel, il s'agit du site qui centralise les connexions VPN pour tous les autres sites, et c'est également le site qui "autorise" les connexions (le réseau VoIP dans cette configuration) entre Agence 1 et Agence 2.
root@host:~# apt update && apt install strongswan
root@host:~# systemctl enable nftables.service
La configuration de nftables est ici ultra-simplifiée, permettant aux réseaux d'accéder à Internet et de communiquer entre eux. Dans un environnement de production, vous pouvez mettre en place un filtrage entre les VLANs.
#!/usr/sbin/nft -f
flush ruleset
table inet filter {
chain input {
type filter hook input priority 0; policy accept;
}
chain forward {
type filter hook forward priority 0; policy accept ;
}
chain output {
type filter hook output priority 0; policy accept;
}
}
#NAT for outgoing traffic.
table ip my_nat {
chain my_masquerade {
type nat hook postrouting priority 100;
ip daddr != { 10.1.0.1, 192.168.0.0/16 } oifname wan masquerade comment "output nat"
}
}
root@host:~# nft -f /etc/nftables.conf
Ici, nous configurons nos deux interfaces : lan et wan (Lisez cet article pour découvrir comment renommer les interfaces réseau sous Debian : Renommer les interfaces réseau sur Debian).
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
# This is an autoconfigured IPv6 interface
allow-hotplug wan
iface wan inet static
address 10.1.0.1
netmask 255.255.255.0
gateway 10.1.0.254
allow-hotplug lan
iface lan inet static
address 192.168.1.254
netmask 255.255.255.0
up /usr/local/sbin/ipconf.sh
root@host:~# systemctl restart networking
Le script /usr/local/sbin/ipconf.sh sera exécuté au démarrage. Il est utilisé pour configurer les interfaces VLAN.
#!/bin/sh
#SETTING UP VLANs ON THE lan INTERFACE
ip link add link lan name users type vlan id 2
ip link add link lan name voip type vlan id 3
ip link add link lan name wifi type vlan id 4
ip link add link lan name servers type vlan id 5
ip link set users up
ip link set voip up
ip link set wifi up
ip link set servers up
#VLAN INTERFACE IP ADDRESS SETTINGS
ip addr add 192.168.2.254/24 dev users
ip addr add 192.168.3.254/24 dev voip
ip addr add 192.168.4.254/22 dev wifi
ip addr add 192.168.5.254/24 dev servers
#ENABLE ROUTING
sysctl net.ipv4.ip_forward=1
root@host:~# chmod +x /usr/local/sbin/ipconf.sh
#####################################
#Headquarters to Branch Office 1 setup#
#####################################
conn hq-b1
authby = secret
auto = route
type = tunnel
keyexchange = ikev2
ike = aes256-sha256-modp1024!
esp = aes256-sha256-modp1024!
#DPD
dpdaction=restart
dpddelay=300s
dpdtimeout=60s
#headquarters
leftfirewall = yes
leftid = 10.1.0.1
left = 10.1.0.1
leftsubnet = 192.168.1.0/24
#Branch Office 1
rightfirewall = yes
rightid = 10.10.0.1
right = 10.10.0.1
rightsubnet = 192.168.10.0/24
#VoIP - Headquarters and Branch Office 1
conn hq-b1-voip
also=hq-b1
leftsubnet = 192.168.3.0/24
rightsubnet = 192.168.13.0/24
#Servers/Headquarters and Users/Branch Office 1
conn hq-b1-servers
also=hq-b1
leftsubnet = 192.168.5.0/24
rightsubnet = 192.168.12.0/24
#VoIP/Branch Office 1 - Headquarters - VoIP/Branch Office 2
conn b1-hq-b2-voip
also=hq-b1
leftsubnet = 192.168.23.0/24
rightsubnet = 192.168.13.0/24
#####################################
#Headquarters to Branch Office 2 setup#
#####################################
conn hq-b2
authby = secret
auto = route
type = tunnel
keyexchange = ikev2
ike = aes256-sha256-modp1024!
esp = aes256-sha256-modp1024!
#DPD
dpdaction=restart
dpddelay=300s
dpdtimeout=60s
#Branch Office 2
rightfirewall = yes
rightid = 10.20.0.1
right = 10.20.0.1
rightsubnet = 192.168.20.0/24
#headquarters
leftfirewall = yes
leftid = 10.1.0.1
left = 10.1.0.1
leftsubnet = 192.168.1.0/24
#VoIP - Headquarters and Branch Office 2
conn hq-b2-voip
also=hq-b2
leftsubnet = 192.168.3.0/24
rightsubnet = 192.168.23.0/24
#Servers/Headquarters and Users/Branch Office 2
conn hq-b2-servers
also=hq-b2
leftsubnet = 192.168.5.0/24
rightsubnet = 192.168.22.0/24
#VoIP/Branch Office 2 - Headquarters - VoIP/Branch Office 1
conn b2-hq-b1-voip
also=hq-b2
rightsubnet = 192.168.23.0/24
leftsubnet = 192.168.13.0/24
Nous allons configurer notre PSK (Pre-Shared Key), qui sera utilisée pour authentifier les routeurs des autres sites.
: PSK password_PSK4231
root@host:~# systemctl restart ipsec.service
Passons maintenant à la configuration de la première agence. La configuration est similaire à celle du site principal, car elle implique également la configuration des interfaces réseau et du service strongSwan.
root@host:~# apt update && apt install strongswan
root@host:~# systemctl enable nftables.service
Comme pour le site principal, la configuration de nftables est ici simplifiée. Aucun filtrage ne sera effectué.
#!/usr/sbin/nft -f
flush ruleset
table inet filter {
chain input {
type filter hook input priority 0; policy accept;
}
chain forward {
type filter hook forward priority 0; policy accept ;
}
chain output {
type filter hook output priority 0; policy accept;
}
}
#NAT for outgoing traffic.
table ip my_nat {
chain my_masquerade {
type nat hook postrouting priority 100;
ip daddr != { 10.10.0.1, 192.168.0.0/16 } oifname wan masquerade comment "output nat"
}
}
root@host:~# nft -f /etc/nftables.conf
Nous configurons nos deux interfaces : lan et wan.
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
# This is an autoconfigured IPv6 interface
allow-hotplug wan
iface wan inet static
address 10.10.0.1
netmask 255.255.255.0
gateway 10.10.0.254
allow-hotplug lan
iface lan inet static
address 192.168.10.254
netmask 255.255.255.0
up /usr/local/sbin/ipconf.sh
Le script /usr/local/sbin/ipconf.sh sera exécuté au démarrage. Il est utilisé pour configurer les interfaces VLAN.
#!/bin/sh
#SETTING UP VLANs ON THE lan INTERFACE
modprobe 8021q
ip link add link lan name users type vlan id 2
ip link add link lan name voip type vlan id 3
ip link add link lan name wifi type vlan id 4
ip link set users up
ip link set voip up
ip link set wifi up
#VLAN INTERFACE IP ADDRESS SETTINGS
ip addr add 192.168.12.254/24 dev users
ip addr add 192.168.13.254/24 dev voip
ip addr add 192.168.14.254/22 dev wifi
#ENABLE ROUTING
sysctl net.ipv4.ip_forward=1
root@host:~# chmod +x /usr/local/sbin/ipconf.sh
#####################################
#Branch Office 1 to Headquarters setup#
#####################################
conn b1-hq
authby = secret
auto = route
type = tunnel
keyexchange = ikev2
ike = aes128-sha1-modp1024!
esp = aes128-sha1-modp1024!
#DPD
dpdaction=restart
dpddelay=300s
dpdtimeout=60s
#Branch Office 1
leftfirewall = yes
left = 10.10.0.1
leftid = 10.10.0.1
leftsubnet = 192.168.10.0/24
#headquarters
rightfirewall = yes
rightid = 10.1.0.1
right = 10.1.0.1
rightsubnet = 192.168.1.0/24
#VoIP - Branch Office 1 and Headquarters
conn b1-hq-voip
also=b1-hq
leftsubnet = 192.168.13.0/24
rightsubnet = 192.168.3.0/24
#Users/Branch Office 1 and Servers/Headquarters
conn b1-hq-servers
also=b1-hq
leftsubnet = 192.168.12.0/24
rightsubnet = 192.168.5.0/24
#VoIP/Branch Office 1 - Headquarters - VoIP/Branch Office 2
conn b1-hq-b2-voip
also=b1-hq
leftsubnet = 192.168.13.0/24
rightsubnet = 192.168.23.0/24
Nous utiliserons la même PSK (Pre-Shared Key) que pour le site principal.
: PSK password_PSK4231
root@host:~# systemctl restart ipsec.service
root@host:~# apt update && apt install strongswan
root@host:~# systemctl enable nftables.service
#!/usr/sbin/nft -f
flush ruleset
table inet filter {
chain input {
type filter hook input priority 0; policy accept;
}
chain forward {
type filter hook forward priority 0; policy accept ;
}
chain output {
type filter hook output priority 0; policy accept;
}
}
#NAT for outgoing traffic.
table ip my_nat {
chain my_masquerade {
type nat hook postrouting priority 100;
ip daddr != { 10.20.0.1, 192.168.0.0/16 } oifname wan masquerade comment "output nat"
}
}
root@host:~# nft -f /etc/nftables.conf
Ici encore, nous configurons nos deux interfaces (lan et wan).
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
allow-hotplug wan
iface wan inet static
address 10.0.10.12
netmask 255.255.255.0
allow-hotplug lan
iface lan inet static
address 192.168.21.254
netmask 255.255.255.0
up /usr/local/sbin/ipconf.sh
Le script /usr/local/sbin/ipconf.sh sera exécuté au démarrage. Il est utilisé pour configurer les interfaces VLAN.
#!/bin/sh
#SETTING UP VLANs ON THE lan INTERFACE
modprobe 8021q
ip link add link lan name users type vlan id 2
ip link add link lan name voip type vlan id 3
ip link add link lan name wifi type vlan id 4
ip link set users up
ip link set voip up
ip link set wifi up
#VLAN INTERFACE IP ADDRESS SETTINGS
ip addr add 192.168.22.254/24 dev users
ip addr add 192.168.23.254/24 dev voip
ip addr add 192.168.24.254/22 dev wifi
#ENABLE ROUTING
sysctl net.ipv4.ip_forward=1
root@host:~# chmod +x /usr/local/sbin/ipconf.sh
#####################################
#Branch Office 2 to Headquarters setup#
#####################################
conn b2-hq
authby = secret
auto = route
type = tunnel
keyexchange = ikev2
ike = aes128-sha1-modp1024!
esp = aes128-sha1-modp1024!
#DPD
dpdaction=restart
dpddelay=300s
dpdtimeout=60s
#Branch Office 2
leftfirewall = yes
left = 10.20.0.1
leftid = 10.20.0.1
leftsubnet = 192.168.20.0/24
#headquarters
rightfirewall = yes
rightid = 10.1.0.1
right = 10.1.0.1
rightsubnet = 192.168.1.0/24
#VoIP - Branch Office 2 and Headquarters
conn b2-hq-voip
also=b2-hq
leftsubnet = 192.168.23.0/24
rightsubnet = 192.168.3.0/24
#Users/Branch Office 2 and Servers/Headquarters
conn b2-hq-servers
also=b2-hq
leftsubnet = 192.168.22.0/24
rightsubnet = 192.168.5.0/24
#VoIP/Branch Office 2 - Headquarters - VoIP/Branch Office 1
conn b2-hq-b1-voip
also=b2-hq
leftsubnet = 192.168.23.0/24
rightsubnet = 192.168.13.0/24
Nous utilisons la même PSK (Pre-Shared Key) que pour les autres sites.
: PSK password_PSK4231
root@host:~# systemctl restart ipsec.service
root@host:~# ping 192.168.21.254 -I 192.168.1.254
root@host:~# ping 192.168.5.254 -I 192.168.12.254
root@host:~# ping 192.168.13.254 -I 192.168.23.254
root@host:~# journalctl --grep "ipsec|charon"
root@host:~# ipsec status
root@host:~# ipsec statusall
Contact :