I've already detailed in a previous article how to set up a multi-site IPsec VPN combining Racoon and strongSwan here: How to set up a Multi-site IPsec VPN with Racoon and strongSwan. As Racoon is now deprecated, I will describe here how to set up a multi-site IPsec VPN architecture, but only with strongSwan.
Let's start with the main site configuration. As a reminder, this is the site that centralizes vpn connections for all other sites, and it's also the site that “authorizes” connections (the VoIP network in this configuration) between Branch Office 1 and Branch Office 2.
root@host:~# apt update && apt install strongswan
root@host:~# systemctl enable nftables.service
The configuration of nftables is ultra-simplified here, allowing networks to access the Internet and communicate with each other. In a production environment, you may set up filtering between 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
Here, we set up our two interfaces: lan and wan (Read this article to find out how to rename network interfaces under Debian: Renaming Network Interfaces on 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
The /usr/local/sbin/ipconf.sh script will be executed at startup. It is used to configure the VLAN interfaces.
#!/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
We're going to set up our PSK (Pre-Shared Key), which will be used to authenticate the routers on the other sites.
: PSK password_PSK4231
root@host:~# systemctl restart ipsec.service
Let's move on to configuring the first of the branch office. The configuration is similar to that of the main site, since it also involves setting the network interfaces and the strongSwan service.
root@host:~# apt update && apt install strongswan
root@host:~# systemctl enable nftables.service
As with the main site, nftables configuration is simplified here. We won't be doing any filtering.
#!/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
We set up our two interfaces: lan and 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
The /usr/local/sbin/ipconf.sh script will be executed at startup. It is used to configure the VLAN interfaces.
#!/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
We'll use the same PSK (Pre-Shared Key) as for the main site.
: 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
Here again, we set up our two interfaces (lan and 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
The /usr/local/sbin/ipconf.sh script will be executed at startup. It is used to configure the VLAN interfaces.
#!/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
We use the same PSK (Pre-Shared Key) as for other 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 :