![](https://habrastorage.org/getpro/habr/upload_files/01a/340/be5/01a340be51bec638270f524cd13df830.png)
Introduction
The idea of ββthe article arose from the desire to pass certain sites through the VPN tunnel directly through the router, since there are a large number of devices at home, and it is inconvenient to let all traffic through the VPN due to the low bandwidth of the tunnel. The article was written immediately after creating the configuration. The configuration will take place in Winbox MikroTik.
StrongSwan
StrongSwan, .
/etc/ipsec.conf
config setup
charondebug="ike 2, knl 2, cfg 2, net 2, esp 2, dmn 2, mgr 2"
uniqueids=never
conn ikev2-vpn
auto=add
compress=no
type=tunnel
keyexchange=ikev2
fragmentation=yes
forceencaps=yes
dpdaction=clear
dpddelay=300s
rekey=no
left=%any
leftid=
leftcert=server-cert.pem
leftsendcert=always
leftsubnet=0.0.0.0/0
right=%any
rightid=%any
rightauth=eap-mschapv2
rightsourceip=10.10.10.0/24
rightdns=8.8.8.8,8.8.4.4
rightsendcert=never
eap_identity=%identity
/etc/ipsec.secrets
# This file holds shared secrets or RSA private keys for authentication.
# RSA private key for this host, authenticating it to any other host
# which knows the public part.
# this file is managed with debconf and will contain the automatically created $
include /var/lib/strongswan/ipsec.secrets.inc
: RSA "server-key.pem"
user1 : EAP "password1"
user2 : EAP "password2"
iptables VPS
-A FORWARD -s 10.10.10.0/24 -o eth0 -p tcp -m policy --dir in --pol ipsec -m tcp --tcp-flags SYN,RST SYN -m tcpmss --mss 1361:1536 -j TCPMSS --set-mss 1360
-A POSTROUTING -s 10.10.10.0/24 -o eth0 -m policy --dir out --pol ipsec -j ACCEPT
-A POSTROUTING -s 10.10.10.0/24 -o eth0 -j MASQUERADE
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p udp -m udp --dport 500 -j ACCEPT
-A INPUT -p udp -m udp --dport 4500 -j ACCEPT
-A INPUT -j DROP
-A FORWARD -s 10.10.10.0/24 -m policy --dir in --pol ipsec --proto esp -j ACCEPT
-A FORWARD -d 10.10.10.0/24 -m policy --dir out --pol ipsec --proto esp -j ACCEPT
-A FORWARD -j DROP
IPSec MikroTik
, MikroTik Files.
![](https://habrastorage.org/getpro/habr/upload_files/2f0/f5e/b6f/2f0f5eb6f4e3d76e19a84ab071a78691.png)
System -> Certificates
VPS StrongSwan.
![](https://habrastorage.org/getpro/habr/upload_files/027/304/5c6/0273045c6fc0b9afc0e2ceb11c21730b.png)
StrongSwan.
![](https://habrastorage.org/getpro/habr/upload_files/446/469/52b/44646952b42ce0523be9460d920fc379.png)
![](https://habrastorage.org/getpro/habr/upload_files/fc4/ddd/316/fc4ddd316a1699de629a1f03f49a4be1.png)
IPsec
IP -> IPsec
StrongSwan, .
![](https://habrastorage.org/getpro/habr/upload_files/505/6d9/7a8/5056d97a8a535a6e5519d239ccfd2682.png)
, VPN-.
![](https://habrastorage.org/getpro/habr/upload_files/852/1f6/a55/8521f6a555c4cf03be831ae8cc91f119.png)
![](https://habrastorage.org/getpro/habr/upload_files/42c/a5f/7fb/42ca5f7fbcea9820609b2136c04d16ee.png)
![](https://habrastorage.org/getpro/habr/upload_files/e56/2f5/c2b/e562f5c2b55907151be81a51d2774885.png)
![](https://habrastorage.org/getpro/habr/upload_files/e71/ed2/785/e71ed27855dcf4b7f92640e5d1967b46.png)
"VPS IP" , StrongSwan.
![](https://habrastorage.org/getpro/habr/upload_files/6e4/5c1/524/6e45c152426843648d3f5cadc289faf7.png)
IPsec Idenity , .
![](https://habrastorage.org/getpro/habr/upload_files/0f1/055/64d/0f105564d8854ec717256f6ff4a868ad.png)
MikroTik StrongSwan .
![Output in the Log section upon successful authorization Output in the Log section upon successful authorization](https://habrastorage.org/getpro/habr/upload_files/68f/bd2/aae/68fbd2aae9c0f0d2a96836888e0f65b3.png)
IP -> Addresses , IP StrongSwan.
![](https://habrastorage.org/getpro/habr/upload_files/bf8/269/195/bf8269195847807018e0f538977cfc7e.png)
IP -> Firewall
NAT .
![](https://habrastorage.org/getpro/habr/upload_files/ea7/d55/437/ea7d554378d77727a002740e8d110c61.png)
.
local - .
List1 - .
![](https://habrastorage.org/getpro/habr/upload_files/052/69a/348/05269a348a42cf0fcc9ec17e1fc03aa3.png)
(IP StrongSwan)
![](https://habrastorage.org/getpro/habr/upload_files/5dc/5a3/06e/5dc5a306e0260de45a0525d28dd58b73.png)
IP -> Firewall
Address Lists :
local - the subnet of the router, in my case 192.168.1.0/24
List1 - list of sites. For example habr.com, you can add a site using fqdn, the ip address will be determined automatically.
![](https://habrastorage.org/getpro/habr/upload_files/d74/c19/172/d74c19172181fc7520c93b4f7ddf5aba.png)
List1 - list of sites. For example habr.com, you can add a site using fqdn, the ip address will be determined automatically.
![](https://habrastorage.org/getpro/habr/upload_files/06b/44a/d74/06b44ad749078200e2053e9b5514c1fa.png)
Conclusion
In this article, I tried to describe in detail the configuration of the tunnel between MicroTik and StrongSwan. I really look forward to your feedback and your constructive criticism.