Linux: Ubuntu 18.04.4 LTS (GNU/Linux 4.15.0-91-generic x86_64)
- Eth0 1.1.1.1/32 external IP
- ipip-ipsec0 192.168.0.1/30 will be our tunnel
Miktoik: CCR 1009, RouterOS 6.46.5
- Eth0 10.0.0.2/30 internal IP from the provider. The provider's external NAT IP is dynamic.
- ipip-ipsec0 192.168.0.2/30 will be our tunnel
We will set up an IPsec tunnel on a Linux machine using racoon. I will not describe the details, there is a good
Install the required packages:
sudo install racoon ipsec-tools
We configure racoon, it will conditionally act as an ipsec server. Since mikrotik in main mode cannot transmit an additional client identifier, and the external ip address through which it connects to Linux is dynamic, it will not work to use a preshared key (password authorization), since the password must be matched either with the ip address of the connecting host, or with identifier.
We will use authorization by RSA keys.
The racoon daemon uses RSA keys, while mikrotik uses PEM keys. If you generate keys with the plainrsa-gen utility that comes with racoon, then you will not be able to convert the public key for Mikrotika to PEM format with it - it only converts in one direction: PEM to RSA. The key generated by plainrsa-gen could not be read by either openssl or ssh-keygen, so they will also fail to convert.
We will generate a PEM key with openssl and then convert it for racoon with plainrsa-gen:
# ΠΠ΅Π½Π΅ΡΠΈΡΡΠ΅ΠΌ ΠΊΠ»ΡΡ
openssl genrsa -out server-name.pem 1024
# ΠΠ·Π²Π»Π΅ΠΊΠ°Π΅ΠΌ ΠΏΡΠ±Π»ΠΈΡΠ½ΡΠΉ ΠΊΠ»ΡΡ
openssl rsa -in server-name.pem -pubout > server-name.pub.pem
# ΠΠΎΠ½Π²Π΅ΡΡΠΈΡΡΠ΅ΠΌ
plainrsa-gen -i server-name.pem -f server-name.privet.key
plainrsa-gen -i server-name.pub.pem -f server-name.pub.key
We put the received keys in the folder: /etc/racoon/certs/server. Do not forget to set the owner of the user on whose behalf the racoon daemon is launched (usually root) to 600 rights.
I will describe the mikrotik setting when connecting via WinBox.
Upload the server-name.pub.pem key to mikrotik: Menu "Files" - "Upload".
Open the section "IP" - "IP sec" - tab "Keys". Now we generate the keys - the βGenerate Keyβ button, then we export the mikrotika public key βExpor Pub. Key", you can download it from the "Files" section, right-click on the file - "Download".
We import the racoon public key, βImportβ, in the drop-down list of the βFile nameβ field, look for the server-name.pub.pem we loaded earlier.
mikrotik public key needs to be converted
plainrsa-gen -i mikrotik.pub.pem -f mikrotik.pub.key
and put it in the /etc/racoon/certs folder without forgetting the owner and rights.
racoon config with comments: /etc/racoon/racoon.conf
log info; # Π£ΡΠΎΠ²Π΅Π½Ρ Π»ΠΎΠ³ΠΈΡΠΎΠ²Π°Π½ΠΈΡ, ΠΏΡΠΈ ΠΎΡΠ»Π°Π΄ΠΊΠ΅ ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΠ΅ΠΌ Debug ΠΈΠ»ΠΈ Debug2.
listen {
isakmp 1.1.1.1 [500]; # ΠΠ΄ΡΠ΅Ρ ΠΈ ΠΏΠΎΡΡ, Π½Π° ΠΊΠΎΡΠΎΡΠΎΠΌ Π±ΡΠ΄Π΅Ρ ΡΠ»ΡΡΠ°ΡΡ Π΄Π΅ΠΌΠΎΠ½.
isakmp_natt 1.1.1.1 [4500]; # ΠΠ΄ΡΠ΅Ρ ΠΈ ΠΏΠΎΡΡ, Π½Π° ΠΊΠΎΡΠΎΡΠΎΠΌ Π±ΡΠ΄Π΅Ρ ΡΠ»ΡΡΠ°ΡΡ Π΄Π΅ΠΌΠΎΠ½ Π΄Π»Ρ ΠΊΠ»ΠΈΠ΅Π½ΡΠΎΠ² Π·Π° NAT.
strict_address; # ΠΡΠΏΠΎΠ»Π½ΡΡΡ ΠΎΠ±ΡΠ·Π°ΡΠ΅Π»ΡΠ½ΡΡ ΠΏΡΠΎΠ²Π΅ΡΠΊΡ ΠΏΡΠΈΠ²ΡΠ·ΠΊΠΈ ΠΊ ΡΠΊΠ°Π·Π°Π½Π½ΡΠΌ Π²ΡΡΠ΅ IP.
}
path certificate "/etc/racoon/certs"; # ΠΡΡΡ Π΄ΠΎ ΠΏΠ°ΠΏΠΊΠΈ Ρ ΡΠ΅ΡΡΠΈΡΠΈΠΊΠ°ΡΠ°ΠΌΠΈ.
remote anonymous { # Π‘Π΅ΠΊΡΠΈΡ, Π·Π°Π΄Π°ΡΡΠ°Ρ ΠΏΠ°ΡΠ°ΠΌΠ΅ΡΡΡ Π΄Π»Ρ ΡΠ°Π±ΠΎΡΡ Π΄Π΅ΠΌΠΎΠ½Π° Ρ ISAKMP ΠΈ ΡΠΎΠ³Π»Π°ΡΠΎΠ²Π°Π½ΠΈΡ ΡΠ΅ΠΆΠΈΠΌΠΎΠ² Ρ ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠ°ΡΡΠΈΠΌΠΈΡΡ Ρ
ΠΎΡΡΠ°ΠΌΠΈ. Π’Π°ΠΊ ΠΊΠ°ΠΊ IP, Ρ ΠΊΠΎΡΠΎΡΠΎΠ³ΠΎ ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠ°Π΅ΡΡΡ Mikrotik, Π΄ΠΈΠ½Π°ΠΌΠΈΡΠ΅ΡΠΊΠΈΠΉ, ΡΠΎ ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΠ΅ΠΌ anonymous, ΡΡΠΎ ΡΠ°Π·ΡΠ΅ΡΠ°Π΅Ρ ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅ Ρ Π»ΡΠ±ΠΎΠ³ΠΎ Π°Π΄ΡΠ΅ΡΠ°. ΠΡΠ»ΠΈ IP Ρ Ρ
ΠΎΡΡΠΎΠ² ΡΡΠ°ΡΠΈΡΠ΅ΡΠΊΠΈΠΉ, ΡΠΎ ΠΌΠΎΠΆΠ½ΠΎ ΡΠΊΠ°Π·Π°ΡΡ ΠΊΠΎΠ½ΠΊΡΠ΅ΡΠ½ΡΠΉ Π°Π΄ΡΠ΅Ρ ΠΈ ΠΏΠΎΡΡ.
passive on; # ΠΠ°Π΄Π°Π΅Ρ "ΡΠ΅ΡΠ²Π΅ΡΠ½ΡΠΉ" ΡΠ΅ΠΆΠΈΠΌ ΡΠ°Π±ΠΎΡΡ Π΄Π΅ΠΌΠΎΠ½Π°, ΠΎΠ½ Π½Π΅ Π±ΡΠ΄Π΅Ρ ΠΏΡΡΠ°ΡΡΡΡ ΠΈΠ½ΠΈΡΠΈΠΈΡΠΎΠ²Π°ΡΡ ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠ΅Π½ΠΈΡ.
nat_traversal on; # ΠΠΊΠ»ΡΡΠ°Π΅Ρ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½ΠΈΠ΅ ΡΠ΅ΠΆΠΈΠΌΠ° NAT-T Π΄Π»Ρ ΠΊΠ»ΠΈΠ΅Π½ΡΠΎΠ², Π΅ΡΠ»ΠΈ ΠΎΠ½ΠΈ Π·Π° NAT.
exchange_mode main; # Π Π΅ΠΆΠΈΠΌ ΠΎΠ±ΠΌΠ΅Π½Π° ΠΏΠ°ΡΠ°ΠΌΠ΅ΡΡΠ°ΠΌΠΈ ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠ΅Π½ΠΈΡ, Π² Π΄Π°Π½Π½ΠΎΠΌ ΡΠ»ΡΡΠ°Π΅ ---ΡΠΎΠ³Π»Π°ΡΠΎΠ²Π°Π½ΠΈΠ΅.
my_identifier address 1.1.1.1; # ΠΠ΄Π΅Π½ΡΠΈΡΠΈΡΠΈΡΡΠ΅ΠΌ Π½Π°Ρ linux Ρ
ΠΎΡΡ ΠΏΠΎ Π΅Π³ΠΎ ip Π°Π΄ΡΠ΅ΡΡ.
certificate_type plain_rsa "server/server-name.priv.key"; # ΠΡΠΈΠ²Π°ΡΠ½ΡΠΉ ΠΊΠ»ΡΡ ΡΠ΅ΡΠ²Π΅ΡΠ°.
peers_certfile plain_rsa "mikrotik.pub.key"; # ΠΡΠ±Π»ΠΈΡΠ½ΡΠΉ ΠΊΠ»ΡΡ Mikrotik.
proposal_check claim; # Π Π΅ΠΆΠΈΠΌ ΡΠΎΠ³Π»Π°ΡΠΎΠ²Π°Π½ΠΈΡ ΠΏΠ°ΡΠ°ΠΌΠ΅ΡΡΠΎΠ² ISAKMP ΡΡΠ½Π½Π΅Π»Ρ. Racoon Π±ΡΠ΄Π΅Ρ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΡ Π·Π½Π°ΡΠ΅Π½ΠΈΡ ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠ°ΡΡΠ΅Π³ΠΎΡΡ Ρ
ΠΎΡΡΠ° (ΠΈΠ½ΠΈΡΠΈΠ°ΡΠΎΡΠ°) Π΄Π»Ρ ΡΡΠΎΠΊΠ° Π΄Π΅ΠΉΡΡΠ²ΠΈΡ ΡΠ΅ΡΡΠΈΠΈ ΠΈ Π΄Π»ΠΈΠ½Ρ ΠΊΠ»ΡΡΠ°, Π΅ΡΠ»ΠΈ Π΅Π³ΠΎ ΡΡΠΎΠΊ Π΄Π΅ΠΉΡΡΠ²ΠΈΡ ΡΠ΅ΡΡΠΈΠΈ Π±ΠΎΠ»ΡΡΠ΅, ΠΈΠ»ΠΈ Π΄Π»ΠΈΠ½Π° Π΅Π³ΠΎ ΠΊΠ»ΡΡΠ° ΠΊΠΎΡΠΎΡΠ΅, ΡΠ΅ΠΌ Ρ ΠΈΠ½ΠΈΡΠΈΠ°ΡΠΎΡΠ°. ΠΡΠ»ΠΈ ΡΡΠΎΠΊ Π΄Π΅ΠΉΡΡΠ²ΠΈΡ ΡΠ΅ΡΡΠΈΠΈ ΠΊΠΎΡΠΎΡΠ΅, ΡΠ΅ΠΌ Ρ ΠΈΠ½ΠΈΡΠΈΠ°ΡΠΎΡΠ°, racoon ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΠ΅Ρ ΡΠΎΠ±ΡΡΠ²Π΅Π½Π½ΠΎΠ΅ Π·Π½Π°ΡΠ΅Π½ΠΈΠ΅ ΡΡΠΎΠΊΠ° Π΄Π΅ΠΉΡΡΠ²ΠΈΡ ΡΠ΅ΡΡΠΈΠΈ ΠΈ Π±ΡΠ΄Π΅Ρ ΠΎΡΠΏΡΠ°Π²Π»ΡΡΡ ΡΠΎΠΎΠ±ΡΠ΅Π½ΠΈΠ΅ RESPONDER-LIFETIME.
proposal { # ΠΠ°ΡΠ°ΠΌΠ΅ΡΡΡ ISAKMP ΡΡΠ½Π½Π΅Π»Ρ.
encryption_algorithm aes; # ΠΠ΅ΡΠΎΠ΄ ΡΠΈΡΡΠΎΠ²Π°Π½ΠΈΡ ISAKMP ΡΡΠ½Π½Π΅Π»Ρ.
hash_algorithm sha512; # ΠΠ»Π³ΠΎΡΠΈΡΠΌ Ρ
Π΅ΡΠΈΡΠΎΠ²Π°Π½ΠΈΡ, ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΠ΅ΠΌΡΠΉ Π΄Π»Ρ ISAKMP ΡΡΠ½Π½Π΅Π»Ρ.
authentication_method rsasig; # Π Π΅ΠΆΠΈΠΌ Π°ΡΡΠ΅Π½ΡΠΈΡΠΈΠΊΠ°ΡΠΈΠΈ Π΄Π»Ρ ISAKMP ΡΡΠ½Π½Π΅Π»Ρ - ΠΏΠΎ RSA ΠΊΠ»ΡΡΠ°ΠΌ.
dh_group modp2048; # ΠΠ»ΠΈΠ½Π° ΠΊΠ»ΡΡΠ° Π΄Π»Ρ Π°Π»Π³ΠΎΡΠΈΡΠΌΠ° ΠΠΈΡΡΠΈ-Π₯Π΅Π»Π»ΠΌΠ°Π½Π° ΠΏΡΠΈ ΡΠΎΠ³Π»Π°ΡΠΎΠ²Π°Π½ΠΈΠΈ ISAKMP ΡΡΠ½Π½Π΅Π»Ρ.
lifetime time 86400 sec; ΠΡΠ΅ΠΌΡ Π΄Π΅ΠΉΡΡΠ²ΠΈΡ ΡΠ΅ΡΡΠΈΠΈ.
}
generate_policy on; # ΠΠ²ΡΠΎΠΌΠ°ΡΠΈΡΠ΅ΡΠΊΠΎΠ΅ ΡΠΎΠ·Π΄Π°Π½ΠΈΠ΅ ESP ΡΡΠ½Π½Π΅Π»Π΅ΠΉ ΠΈΠ· Π·Π°ΠΏΡΠΎΡΠ°, ΠΏΡΠΈΡΠ΅Π΄ΡΠ΅Π³ΠΎ ΠΎΡ ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠ°ΡΡΠ΅Π³ΠΎΡΡ Ρ
ΠΎΡΡΠ°.
}
sainfo anonymous { # ΠΠ°ΡΠ°ΠΌΠ΅ΡΡΡ ESP ΡΡΠ½Π½Π΅Π»Π΅ΠΉ, anonymous - ΡΠΊΠ°Π·Π°Π½Π½ΡΠ΅ ΠΏΠ°ΡΠ°ΠΌΠ΅ΡΡΡ Π±ΡΠ΄ΡΡ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½Ρ ΠΊΠ°ΠΊ ΠΏΠ°ΡΠ°ΠΌΠ΅ΡΡΡ ΠΏΠΎ ΡΠΌΠΎΠ»ΡΠ°Π½ΠΈΡ. ΠΠ»Ρ ΡΠ°Π·Π½ΡΡ
ΠΊΠ»ΠΈΠ΅Π½ΡΠΎΠ², ΠΏΠΎΡΡΠΎΠ², ΠΏΡΠΎΡΠΎΠΊΠΎΠ»ΠΎΠ² ΠΌΠΎΠΆΠ½ΠΎ Π·Π°Π΄Π°Π²Π°ΡΡ ΡΠ°Π·Π½ΡΠ΅ ΠΏΠ°ΡΠ°ΠΌΠ΅ΡΡΡ, ΡΠΎΠΏΠΎΡΡΠ°Π²Π»Π΅Π½ΠΈΠ΅ ΠΏΡΠΎΠΈΡΡ
ΠΎΠ΄ΠΈΡ ΠΏΠΎ ip Π°Π΄ΡΠ΅ΡΠ°ΠΌ, ΠΏΠΎΡΡΠ°ΠΌ, ΠΏΡΠΎΡΠΎΠΊΠΎΠ»Π°ΠΌ.
pfs_group modp2048; # ΠΠ»ΠΈΠ½Π° ΠΊΠ»ΡΡΠ° Π΄Π»Ρ Π°Π»Π³ΠΎΡΠΈΡΠΌΠ° ΠΠΈΡΡΠΈ-Π₯Π΅Π»Π»ΠΌΠ°Π½Π° Π΄Π»Ρ ESP ΡΡΠ½Π½Π΅Π»Π΅ΠΉ.
lifetime time 28800 sec; # Π‘ΡΠΎΠΊ Π΄Π΅ΠΉΡΡΠ²ΠΈΡ ESP ΡΡΠ½Π½Π΅Π»Π΅ΠΉ.
encryption_algorithm aes; # ΠΠ΅ΡΠΎΠ΄ ΡΠΈΡΡΠΎΠ²Π°Π½ΠΈΡ ESP ΡΡΠ½Π½Π΅Π»Π΅ΠΉ.
authentication_algorithm hmac_sha512; # ΠΠ»Π³ΠΎΡΠΈΡΠΌ Ρ
Π΅ΡΠΈΡΠΎΠ²Π°Π½ΠΈΡ, ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΠ΅ΠΌΡΠΉ Π΄Π»Ρ Π°ΡΡΠ΅Π½ΡΠΈΡΠΈΠΊΠ°ΡΠΈΠΈ ESP ΡΡΠ½Π½Π΅Π»Π΅ΠΉ.
compression_algorithm deflate; # Π‘ΠΆΠΈΠΌΠ°ΡΡ ΠΏΠ΅ΡΠ΅Π΄Π°Π²Π°Π΅ΠΌΡΠ΅ Π΄Π°Π½Π½ΡΠ΅, Π°Π»Π³ΠΎΡΠΈΡΠΌ ΡΠΆΠ°ΡΠΈΡ ΠΏΡΠ΅Π΄Π»Π°Π³Π°Π΅ΡΡΡ ΡΠΎΠ»ΡΠΊΠΎ ΠΎΠ΄ΠΈΠ½.
}
mikrotik config
We return to the section "IP" - "IPsec"
Profiles Tab
Parameter
Value
Name
At your discretion (default default)
Hash Algorithm
sha512
Encryption Algorithm
aes-128
D.H. Group
modp2048
Proposhal_check
claim
Lifetime
1d 00:00:00
NAT Traversal
true (tick)
DPD
120
DPD maximum failure
5
Peers tab
Parameter
Value
Name
At your discretion (hereinafter MyPeer)
Address
1.1.1.1 (IP linux machines)
Local address
10.0.0.2 (IP WAN interface mikrotik)
Profile
default
Exchange Mode
main
passive
false
Send INITIAL_CONTACT
true
Proposal Tab
Parameter
Value
Name
At your discretion (hereinafter MyPeerProposal)
Auth. Algorithms
sha512
Encr. Algorithms
aes-128-cbc
Lifetime
08:00:00
PFS Group
modp2048
Identities tab
Parameter
Value
Peer
MyPeer
Atuh. method
rsa key
Key
mikrotik.privet.key
remote key
server-name.pub.pem
Policy Template Group
default
Notrack Chain
is empty
My ID Type
auto
Remote ID Type
auto
Match By
remote id
Mode Configuration
is empty
Generate Policy
No.
Policies - General Tab
Parameter
Value
Peer
MyPeer
Tunnels
true
src. Address
192.168.0.0/30
Dest. address
192.168.0.0/30
Protocol
255 (all)
template
false
Policies - Action Tab
Parameter
Value
Action
encrypt
Level
require
IPsec Protocols
esp
Proposal
MyPeerProposal
Most likely, you, like me, have snat / masquerade configured on the WAN interface, this rule needs to be adjusted so that outgoing ipsec packets go to our tunnel:
Go to the "IP" - "Firewall" section.
Tab "NAT", open our snat/masquerade rule.
Advanced tab
Parameter
Value
IPsec Policy
out: none
Restarting the racoon daemon
sudo systemctl restart racoon
If racoon does not start when restarting, then there is an error in the config, in the syslog racoon displays information about the line number in which the error was found.
The racoon daemon, when the OS boots, starts before raising the network interfaces, and we specified the strict_address option in the listen section, it is necessary to add the racoon unit to the systemd file
/lib/systemd/system/racoon.service, to the [Unit] section, After=network.target line.
Now our ipsec tunnels should go up, we look at the output:
sudo ip xfrm policy
src 192.168.255.0/30 dst 192.168.255.0/30
dir out priority 2147483648
tmpl src 1.1.1.1 dst "IP NAT ΡΠ΅ΡΠ΅Π· ΠΊΠΎΡΠΎΡΡΠΉ ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠ°Π΅ΡΡΡ mikrotik"
proto esp reqid 0 mode tunnel
src 192.168.255.0/30 dst 192.168.255.0/30
dir fwd priority 2147483648
tmpl src "IP NAT ΡΠ΅ΡΠ΅Π· ΠΊΠΎΡΠΎΡΡΠΉ ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠ°Π΅ΡΡΡ mikrotik" dst 1.1.1.1
proto esp reqid 0 mode tunnel
src 192.168.255.0/30 dst 192.168.255.0/30
dir in priority 2147483648
tmpl src "IP NAT ΡΠ΅ΡΠ΅Π· ΠΊΠΎΡΠΎΡΡΠΉ ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠ°Π΅ΡΡΡ mikrotik" dst 1.1.1.1
proto esp reqid 0 mode tunnel
If the tunnels are not up, see syslog, or journalctl -u racoon.
Now you need to configure L3 interfaces so that traffic can be routed. There are different options, we will use IPIP, since mikrotik supports it, I would use vti, but, unfortunately, it has not yet been implemented in mikrotik. It differs from IPIP in that it can additionally encapsulate multicast and put labels (fwmark) on packets by which they can be filtered in iptables and iproute2 (policy-based routing). If you need maximum functionality, then, for example, GRE. But do not forget that for additional functionality we pay a big overhead.
Translation of a good overview of tunnel interfaces can be viewed
On Linux:
# Π‘ΠΎΠ·Π΄Π°Π΅ΠΌ ΠΈΠ½ΡΠ΅ΡΡΠ΅ΠΉΡ
sudo ip tunnel add ipip-ipsec0 local 192.168.255.1 remote 192.168.255.2 mode ipip
# ΠΠΊΡΠΈΠ²ΠΈΡΡΠ΅ΠΌ
sudo ip link set ipip-ipsec0 up
# ΠΠ°Π·Π½Π°ΡΠ°Π΅ΠΌ Π°Π΄ΡΠ΅Ρ
sudo ip addr add 192.168.255.1/30 dev ipip-ipsec0
Now you can add routes for networks for mikrotik
sudo ip route add A.B.C.D/Prefix via 192.168.255.2
In order for our interface and routes to rise after a reboot, we need to describe the interface in /etc/network/interfaces and add routes in post-up there, or write everything in one file, for example, /etc/ipip-ipsec0.conf and pull it through post-up, don't forget about file owner, permissions and make it executable.
Under the cut is an example file
#!/bin/bash
ip tunnel add ipip-ipsec0 local 192.168.255.1 remote 192.168.255.2 mode ipip
ip link set ipip-ipsec0 up
ip addr add 192.168.255.1/30 dev ipip-ipsec0
ip route add A.B.C.D/Prefix via 192.168.255.2
On Mikrotik:
Section "Interfaces", add a new interface "IP tunnel":
Tab "IP tunnel" - "General"
Parameter
Value
Name
At your discretion (hereinafter referred to as IPIP-IPsec0)
MTU
1480 (if not specified, then mikrotik starts cutting mtu to 68)
Local address
192.168.0.2
remote address
192.168.0.1
IPsec Secret
Deactivate the field (otherwise a new Peer will be created)
keepalive
Deactivate the field (otherwise the interface will be constantly turned off, since mikrotika has some kind of its own format for these packages and does not work with linux)
DSCP
Inherit
Don't Fragment
No.
Clamp TCP MSS
true
Allow Fast Path
true
Section "IP" - "Addresses", add the address:
Parameter
Value
Address
192.168.0.2/30
Interface
IPIP-IPsec0
Now you can add routes on the network behind the linux machine, when adding a route, gateway will be our IPIP-IPsec0 interface.
PS
Since our linux server is transit, it makes sense to set the Clamp TCP MSS parameter for ipip interfaces on it:
create a file /etc/iptables.conf with the following content:
*mangle
-A POSTROUTING -o ipip+ -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
COMMIT
and in /etc/network/interfaces
post-up iptables-restore < /etc/iptables.conf
On the network behind mikrotik, nginx works for me (ip 10.10.10.1), we make it available from the Internet, add it to /etc/iptables.conf:
*nat
-A PREROUTING -d 1.1.1.1/32 -p tcp -m multiport --dports 80,443 -j DNAT --to-destination 10.10.10.1
#ΠΠ° mikrotik, Π² ΡΠ°Π±Π»ΠΈΡΠ΅ mangle, Π½Π°Π΄ΠΎ Π΄ΠΎΠ±Π°Π²ΠΈΡΡ ΠΏΡΠ°Π²ΠΈΠ»ΠΎ route Ρ Π½Π°Π·Π½Π°ΡΠ΅Π½ΠΈΠ΅ΠΌ 192.168.0.1 Π΄Π»Ρ ΠΏΠ°ΠΊΠ΅ΡΠΎΠ² Ρ Π°Π΄ΡΠ΅ΡΠΎΠΌ ΠΈΡΡΠΎΡΠ½ΠΈΠΊΠ° 10.10.10.1 ΠΈ ΠΏΠΎΡΡΠΎΠ² 80, 443.
# Π’Π°ΠΊ ΠΆΠ΅ Π½Π° linux ΡΠ°Π±ΠΎΡΠ°Π΅Ρ OpenVPN ΡΠ΅ΡΠ²Π΅Ρ 172.16.0.1/24, Π΄Π»Ρ ΠΊΠ»ΠΈΠ΅Π½ΡΠΎΠ² ΠΊΠΎΡΠΎΡΡΠ΅ ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΡΡ ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅ ΠΊ Π½Π΅ΠΌΡ Π² ΠΊΠ°ΡΠ΅ΡΡΠ²Π΅ ΡΠ»ΡΠ·Π° Π΄Π°Π΅ΠΌ Π΄ΠΎΡΡΡΠΏ Π² ΠΈΠ½ΡΠ΅ΡΠ½Π΅Ρ
-A POSTROUTING -s 172.16.0.0/24 -o eth0 -j SNAT --to-source 1.1.1.1
COMMIT
Don't forget to add the appropriate permissions to iptables if you have packet filters enabled.
Be healthy!
Source: habr.com