We created a VPN Site to site, phase 1 and phase 2 ok. However, I don’t understand how to create the routes.
Subnet A: 172.16.0.0/29
Subnet B: 10.198.8.0/22
What I would like to know is: Does this subnet A need to be on some routerboard interface? Or can I create a route between it and my subnet in use 192.168.0.0/24?
A subnet matching to a policy need not be local, it is enough that there was a route to it.
So the router X, on which subnet A is the src-address of the IPsec policy, must have a regular route to 172.16.0.0/29 via some gateway in its 192.168.0.0/24, and devices in 172.16.0.0/29 must have a route to 10.198.8.0/22 via some gateway in 172.16.0.0/29 that itself has a route there via router X (both may be their default routes).
Also router X must have some route to 10.198.8.0/22 (again it may be the default one) as IPsec policy matching takes place as the very last step of packet processing, just before the packet would be sent out the chosen interface. So if there is no route, the packet never reaches the policy matching stage, and if there is src-nat, the policy may not match the packet.
This ipsec vpn was created between a fortigate and mikrotik. From the fortigate side it is possible to access our internal servers, however I cannot ping and telnet to any IP and port on that side.
If “the fortigate side” means one of the two subnets you’ve mentioned in the OP and “our internal servers” means the other one of those two subnets, what you just wrote means that both the IPsec policy and the routing at your side are correct but firewall rules on your devices or on the Fortigate site prevent connections from “your internal side” to “the fortigate side” from establishing. One common omission is that you do not exempt traffic that should get matched by an IPsec policy from getting src-nated - IPsec policy matching takes place as the very last step before the packet would get sent via the out-interface chosen by regular routing. If the only route to the subnet on the Fortigate side is the default one via WAN, the src-nat or masquerade rule changes the source address for connections initiated from your side to the address associated to the WAN interface and the policy thus ignores the packet.
According to the person responsible for the network on the other side, there is nothing in the logs with my origin. Do I need to dial the connection so that it reaches it via VPN? We only have one Link that authenticates through a pppoe dialer.
The world is full of misunderstandings. As you say that incoming connections to servers on your side from servers at their side are possible, I assume that the “nothing in the logs” is not related to establishing the IPsec communication channel but to the requests delivered via that channel.
But to answer your questions, there is no need to dial anything, Mikrotik keeps trying to establish the IPsec Phase 1 all the time and Phase 2 in the beginning and then every time it needs to deliver a payload packet if the peer has torn down the Phase 2 in the meantime.
What do /ip ipsec active-peers print and /ip ipsec installed-sa print show?
Your action=masquerade in chain srcnat of table nat is not selective which probably causes additional issues. But for your purpose, place a rule chain=srcnat action=accept ipsec-policy=out,ipsec before (above) the action=masquerade one. I would also add out-interface=ether1 or out-interface-list=WAN depending on your actual configuration, and src-address-type=!local, to the action=masquerade rule, to limit its effect only to the traffic where it is actually needed. And since the tracked connections in the firewall survive for 3 minutes since seeing last packet from either side, which effectively means forever, you have to get rid of them after the changes. The easiest way is to reboot the router. If it is not possible, I will explain how to remove them selectively.
It should have said src-address-type=**!**local - the exclamation mark is important (it is a logical “not”), and on the GUI (Winbox/Webfig), there is a rectangle like for a checkmark before the value; if you tick it, the exclamation mark appears there rather than the checkmark.
Great, and has it changed anything? I suppose you did reboot the router again after the change? So show me the output of /ip ipsec active-peers print and /ip ipsec installed-sa print again, once taken before you attempt to connect from your location to the remote one and once after such an attempt.
[admin@MikroTik] > ip ipsec active-peers print
Flags: R - responder, N - natt-peer
# ID STATE UPTIME PH2-TOTAL
0 R OTHER SIDE established 2h40m44s 1
1 RN OTHER SIDE established 2h40m38s 1
[admin@MikroTik] > /ip ipsec installed-sa print
Flags: H - hw-aead, A - AH, E - ESP
0 HE spi=0x1F9FF38 src-address=OTHER SIDE dst-address=MY SIDE
state=mature auth-algorithm=sha1 enc-algorithm=aes-cbc enc-key-size=256
auth-key="608de8a79140d8cff2d7729131827682dfde1422"
enc-key="431996c9140b8480da20ae46b43de1f56230025e9d8eae930e15e55a8dad289d"
add-lifetime=6h24m4s/8h6s replay=128
1 HE spi=0x3852FE74 src-address=MY SIDE dst-address=OTHER SIDE
state=mature auth-algorithm=sha1 enc-algorithm=aes-cbc enc-key-size=256
auth-key="ca2ec38799bedc50910c098a8e4a0395949fe9b7"
enc-key="8173124f5e2c35ce4737534f4eebab4aec4d3cbf18a0e0a1f1b3eb7d3534f6d4"
add-lifetime=6h24m4s/8h6s replay=128
2 HE spi=0x18EBD7A src-address=OTHER SIDE:4500 dst-address=MY SIDE:4500
state=mature auth-algorithm=sha256 enc-algorithm=aes-cbc enc-key-size=256
auth-key="4f790228aab8a0e2977a71aa5f42f9452cf0f6265b6e5325dc5f2cee6f378110"
enc-key="6bfbb1ab30be8084131dcf2c6b57c605235c8d729a8d9162091bb1925be272dc"
add-lifetime=48m20s/1h25s replay=128
3 HE spi=0xF7CE6E6E src-address=MY SIDE:4500 dst-address=OTHER SIDE:4500
state=mature auth-algorithm=sha256 enc-algorithm=aes-cbc enc-key-size=256
auth-key="f6eb61c08a6e764041fa999500f75f786cb28f6031b5f63206fdc9b35703baea"
enc-key="4e243acebdb0719fef5d04a0b93b3790ed651b473558a22c928df62472006b6f"
add-lifetime=48m20s/1h25s replay=128
I’ve asked for prints “before” and “after” an attempt to connect from a device at your end to a device at the Fortigate end, you have only posted one. So:
if what you have posted is “after”, it means the firewall or routing at your end do not let the initial request through, as all the SAs show no traffic at all.
if what you’ve posted is “before”, it doesn’t say anything about how the connection attempt went.
What it shows regardless the above is that there is still something strange, as you have two active peers with the same address (unless OTHER SIDE actually stands for two different addresses), one of them treated as a NATed one and the other one as a directly routed one (without any NAT on the path). So it looks as if the Fortigate itself has established one tunnel and some other device behind it has established another one.
There really are two VPNs, but with the same problem. I’ll wait until the company’s business hours are over to restore the settings and do everything from the beginning.
Unless you have obfuscated the actual subnets involved and made a mistake in that process, the NAT rule that should exempt traffic matching the policy from getting masqueraded is wrong as it matches on src-address=192.168.0.0/24 whereas the policy has src-address=172.16.0.0/29. Matching on ipsec-policy=out,ipsec instead, as I suggested, aviods that type of mistakes.
But maybe I have completely misunderstood your original question and you actually want 192.168.0.0/24 to talk directly with 10.198.8.0/22? If so, the policy must be set to dst-address=10.198.8.0/22 src-address=192.168.0.0/24. My original understanding was that 192.168.0.0/24 was the LAN subnet on one of your routers, acting as an IPsec peer of the Fortigate, and 172.16.0.0/29 was the subnet on some other router reachable via 192.168.0.x.
If there is actually just one router on your side and 172.16.0.0/29 is some kind of virtual subnet that the Fortigate side forces you to use for the IPsec connection although you actually use the 192.168.0.0/24, you do need NAT between the subnets, but since you cannot map a /24 subnet to a /29 one 1:1, you have to specify individual dst-nat rules.
But neither of those explains how the access from the Fortigate side to your on-prem subnet works as you stated before. So please clarify the topology, otherwise we won’t get anywhere.