I have a router with 2 WAN: WAN1 and WAN2. Usually, all is using WAN2 because it’s faster.
On this router i’ve set a VPN IPSec to a database service.
Now I want add an IPSec Ikev2 to use the database service remotely but it not work.
Something is braking the IPSec.
I have to connect to the router in the same net of the lan, so IP of VPN are 192.168.1.XXX.
Client of IPSec Ike2 can connect correctly, but no traffic flow from router to client. After 2 min, the session expires because the token is not renewed.
I don’t figure out why. Firewall seems ok.
This is the settings of the router:
/interface bridge
add admin-mac=B8:69:XX:XX:XX:XX arp=proxy-arp auto-mac=no comment=defconf \
name=bridge
/interface ethernet
set [ find default-name=ether1 ] name=WAN1
set [ find default-name=ether2 ] comment="ROUTER FAST ISP" name=WAN2
set [ find default-name=ether9 ] arp=proxy-arp name=ether9-AP
/interface ovpn-server
add name=ovpn-ADMIN user=sysAdmin
/interface vlan
add interface=ether9-AP name=vlan-guest vlan-id=20
add interface=ether9-AP name=vlan-staff vlan-id=10
/interface ethernet switch port
set 0 default-vlan-id=0
set 1 default-vlan-id=0
set 2 default-vlan-id=0
set 3 default-vlan-id=0
set 4 default-vlan-id=0
set 5 default-vlan-id=0
set 6 default-vlan-id=0
set 7 default-vlan-id=0
set 8 default-vlan-id=0
set 9 default-vlan-id=0
set 10 default-vlan-id=0
set 11 default-vlan-id=0
/interface list
add comment=defconf name=WAN
add comment=defconf name=LAN
/interface wireless security-profiles
set [ find default=yes ] supplicant-identity=MikroTik
/ip ipsec policy group
add name="group vpn.XXXXXXXX.com"
/ip ipsec profile
add dh-group=modp1024 enc-algorithm=aes-256 name=DB_SERVICE-IPSEC
add dh-group=modp2048,modp1536,modp1024 enc-algorithm=aes-256,aes-192,aes-128 \
hash-algorithm=sha256 name="profile vpn.XXXXXXXX.com"
/ip ipsec peer
add address=185.XX.XX.XX/32 local-address=10.0.2.10 name=Peer-DB_SERVICE \
profile=DB_SERVICE-IPSEC
add exchange-mode=ike2 local-address=10.0.2.10 name="peer vpn ikev2" passive=\
yes profile="profile vpn.XXXXXXXX.com"
/ip ipsec proposal
add enc-algorithms=aes-256-cbc,aes-256-ctr,aes-256-gcm lifetime=2h10m name=\
DB_SERVICE-proposal
add auth-algorithms=sha512,sha256,sha1 enc-algorithms="aes-256-cbc,aes-256-ctr\
,aes-256-gcm,aes-192-ctr,aes-192-gcm,aes-128-cbc,aes-128-ctr,aes-128-gcm" \
lifetime=8h name="proposal vpn.XXXXXXXX.com" pfs-group=none
/ip pool
add name=default-dhcp ranges=192.168.88.10-192.168.88.254
add name=dhcp_pool1 ranges=192.168.1.2-192.168.1.254
add name=Pool-OVPN ranges=10.255.255.2-10.255.255.254
add name=pool-guest ranges=192.168.2.2-192.168.2.254
/ip dhcp-server
add add-arp=yes address-pool=dhcp_pool1 disabled=no interface=bridge \
lease-time=30m name=dhcp_server_local
add add-arp=yes address-pool=pool-guest disabled=no interface=vlan-guest \
lease-time=30m name=dhcp-guest
/ip ipsec mode-config
add address-pool=dhcp_pool1 address-prefix-length=32 name=\
"modeconf vpn.XXXXXXXX.com" split-include=\
192.168.1.0/24,10.0.1.0/24,10.0.2.0/24 static-dns=192.168.1.1 system-dns=\
no
/ppp profile
add interface-list=LAN local-address=dhcp_pool1 name=ProfileOVPN \
remote-address=dhcp_pool1
/queue tree
add disabled=yes max-limit=3700k name=uploadWAN2 parent=WAN2
add limit-at=1M max-limit=3700k name=Voip_upload_WAN2 packet-mark=fromVoip \
parent=uploadWAN2 priority=3
add bucket-size=0.2 limit-at=1M max-limit=3700k name=otherClientWAN2 \
packet-mark=no-mark parent=uploadWAN2
/queue type
add kind=pfifo name=queue-OVPN_250 pfifo-limit=250
/queue interface
set ovpn-ADMIN queue=queue-OVPN_250
/interface bridge port
add bridge=bridge comment=defconf interface=ether3
add bridge=bridge comment=defconf interface=ether4
add bridge=bridge comment=defconf interface=ether5
add bridge=bridge comment=defconf interface=ether7
add bridge=bridge comment=defconf interface=ether8
add bridge=bridge comment=defconf interface=sfp-sfpplus1
add bridge=bridge frame-types=admit-only-untagged-and-priority-tagged \
interface=ether9-AP
add bridge=bridge frame-types=admit-only-vlan-tagged interface=vlan-staff \
pvid=10
/interface bridge settings
set use-ip-firewall=yes
/ip neighbor discovery-settings
set discover-interface-list=LAN
/interface list member
add comment=defconf interface=bridge list=LAN
add comment=defconf interface=WAN1 list=WAN
add interface=WAN2 list=WAN
add interface=vlan-guest list=WAN
add interface=ether9-AP list=LAN
add interface=vlan-staff list=LAN
add interface=vlan-guest list=LAN
/interface ovpn-server server
set auth=sha1 certificate=Server cipher=aes256 default-profile=ProfileOVPN \
enabled=yes port=1200 require-client-certificate=yes
/ip address
add address=192.168.1.1/24 comment=defconf interface=bridge network=\
192.168.1.0
add address=192.168.2.1/24 interface=vlan-guest network=192.168.2.0
/ip arp
add address=192.168.1.246 interface=bridge mac-address=9C:75:14:20:89:90
/ip cloud
set ddns-enabled=yes
/ip dhcp-client
add comment=defconf default-route-distance=2 disabled=no interface=WAN1
add dhcp-options=hostname disabled=no interface=WAN2
/ip dhcp-server network
add address=192.168.1.0/24 comment=defconf dns-server=\
8.8.8.8,8.8.4.4,10.0.1.1,10.0.2.1 gateway=192.168.1.1 netmask=24
add address=192.168.2.0/24 dns-server=10.0.1.1,10.0.2.1 gateway=192.168.2.1
add address=192.168.11.0/24 dns-server=8.8.8.8,10.0.1.1,10.0.2.1 gateway=\
192.168.11.1
add address=192.168.178.0/24 dns-server=8.8.8.8,8.8.4.4 gateway=192.168.178.1
/ip dns
set allow-remote-requests=yes servers=8.8.8.8,8.8.4.4
/ip dns static
add address=192.168.88.1 name=router.lan
/ip firewall filter
add action=accept chain=input comment=\
"defconf: accept established,related,untracked" connection-state=\
established,related,untracked
add action=accept chain=input comment="OVPN Server Accept" connection-state=\
new dst-port=1200 in-interface-list=WAN protocol=tcp
add action=accept chain=input comment="Accept input form VPN IPSEC IKEv2" \
ipsec-policy=in,ipsec src-address=192.168.1.0/24
add action=drop chain=input comment="defconf: drop invalid" connection-state=\
invalid
add action=accept chain=input comment="defconf: accept ICMP" protocol=icmp
add action=accept chain=input comment=\
"Allow UDP 500,4500 IPSec for 10.0.2.10" dst-address=10.0.2.10 dst-port=\
500,4500 protocol=udp
add action=accept chain=input comment="Allow IPSec-esp for 10.0.2.10" \
dst-address=10.0.2.10 protocol=ipsec-esp
add action=drop chain=input comment="BLOCK UDP DNS request da WAN1" \
disabled=yes dst-port=53 in-interface=WAN1 protocol=udp
add action=drop chain=input comment="BLOCK UDP DNS request da WAN2 - FTTH" \
disabled=yes dst-port=53 in-interface=WAN2 protocol=udp
add action=drop chain=input comment="BLOCK TCP DNS request da WAN1" \
disabled=yes dst-port=53 in-interface=WAN1 protocol=tcp
add action=drop chain=input comment="BLOCK TCP DNS request da WAN2 - FTTH" \
disabled=yes dst-port=53 in-interface=WAN2 protocol=tcp
add action=drop chain=input comment="defconf: drop all not coming from LAN" \
in-interface-list=!LAN log=yes log-prefix="Not coming LAN"
add action=drop chain=forward comment=\
"DROP FROM DB_SERVICE a LAN interna" connection-state=new \
dst-address=192.168.1.0/24 src-address=192.168.27.48/29
add action=drop chain=forward comment=\
"DROP FROM LAN ad AP-guest" connection-state=new \
dst-address=192.168.2.0/24 src-address=192.168.1.0/24
add action=drop chain=forward comment=\
"DROP FROM AP-guest a LAN" connection-state=new \
dst-address=192.168.1.0/24 src-address=192.168.2.0/24
add action=accept chain=forward in-interface=vlan-guest src-address=\
192.168.2.0/24
add action=accept chain=forward comment="defconf: accept in ipsec policy" \
ipsec-policy=in,ipsec
add action=accept chain=forward comment="defconf: accept out ipsec policy" \
ipsec-policy=out,ipsec
add action=accept chain=forward comment="IntercomunicationPOOL VPN OpenVPN" \
dst-address=10.255.255.0/24 src-address=192.168.1.0/24
add action=accept chain=forward comment="IntercomunicationPOOL VPN OpenVPN" \
dst-address=192.168.1.0/24 src-address=10.255.255.0/24
add action=accept chain=forward comment=\
"defconf: accept established,related, untracked" connection-state=\
established,related,untracked
add action=drop chain=forward comment="defconf: drop invalid" \
connection-state=invalid
add action=fasttrack-connection chain=forward comment="defconf: fasttrack" \
connection-state=established,related disabled=yes
add action=drop chain=forward comment=\
"defconf: drop all from WAN not DSTNATed" connection-nat-state=!dstnat \
connection-state=new in-interface-list=WAN
/ip firewall mangle
add action=accept chain=prerouting comment="Accept da WAN1" dst-address=\
10.0.1.0/24
add action=accept chain=prerouting comment="Accept da WAN2" dst-address=\
10.0.2.0/24
add action=mark-connection chain=prerouting connection-mark=no-mark \
dst-address-type=!local in-bridge-port=vlan-staff in-interface=bridge \
new-connection-mark=WAN1 passthrough=yes
add action=mark-connection chain=prerouting connection-mark=no-mark \
in-interface=vlan-guest new-connection-mark=WAN1 passthrough=yes \
tcp-flags=""
add action=mark-connection chain=prerouting connection-mark=no-mark \
in-interface=WAN1 new-connection-mark=WAN1 passthrough=yes
add action=mark-connection chain=prerouting connection-mark=no-mark \
in-interface=WAN2 new-connection-mark=WAN2 passthrough=yes
add action=mark-routing chain=prerouting connection-mark=WAN1 in-interface=\
vlan-guest new-routing-mark=WAN1-mark passthrough=yes
add action=mark-routing chain=prerouting connection-mark=WAN1 in-interface=\
bridge new-routing-mark=WAN1-mark passthrough=yes
add action=mark-routing chain=prerouting connection-mark=WAN2 in-interface=\
bridge new-routing-mark=WAN2-mark passthrough=yes
add action=mark-connection chain=forward in-interface=vlan-guest \
new-connection-mark=WAN1 passthrough=yes
add action=mark-connection chain=forward in-interface=WAN1 \
new-connection-mark=WAN1 passthrough=yes
add action=mark-connection chain=forward in-interface=WAN2 \
new-connection-mark=WAN2 passthrough=yes
/ip firewall nat
add action=accept chain=srcnat dst-address=192.168.27.48/29 src-address=\
192.168.1.0/24
add action=masquerade chain=srcnat ipsec-policy=out,none out-interface=WAN1
add action=masquerade chain=srcnat ipsec-policy=out,none out-interface=WAN2
add action=dst-nat chain=dstnat comment="Server on WAN1 tcp" \
dst-port=25184 in-interface=WAN1 ipsec-policy=in,none protocol=tcp \
to-addresses=192.168.1.253 to-ports=443
add action=dst-nat chain=dstnat comment="Server on WAN2 tcp" \
dst-port=25184 in-interface=WAN2 ipsec-policy=in,none protocol=tcp \
src-port="" to-addresses=192.168.1.253 to-ports=443
add action=dst-nat chain=dstnat comment="443 TCP" dst-port=443 \
in-interface-list=WAN ipsec-policy=in,none protocol=tcp to-addresses=\
192.168.1.5 to-ports=443
add action=dst-nat chain=dstnat comment="5060 TCP" dst-port=5060 \
in-interface-list=WAN ipsec-policy=in,none protocol=tcp to-addresses=\
192.168.1.5 to-ports=5060
add action=dst-nat chain=dstnat comment="5060 UDP" dst-port=5060 \
in-interface-list=WAN ipsec-policy=in,none protocol=udp to-addresses=\
192.168.1.5 to-ports=5060
add action=dst-nat chain=dstnat comment="5061 TCP" dst-port=5061 \
in-interface-list=WAN ipsec-policy=in,none protocol=tcp to-addresses=\
192.168.1.5 to-ports=5061
add action=dst-nat chain=dstnat comment="Range 10000-15000 UDP" \
dst-port=10000-15000 in-interface-list=WAN ipsec-policy=in,none protocol=\
udp to-addresses=192.168.1.5 to-ports=10000-15000
/ip firewall service-port
set sip disabled=yes
/ip ipsec identity
add peer=Peer-DB_SERVICE
add auth-method=digital-signature certificate=vpn.XXXXXXXX.com \
generate-policy=port-strict match-by=certificate mode-config=\
"modeconf vpn.XXXXXXXX.com" peer="peer vpn ikev2" policy-template-group=\
"group vpn.XXXXXXXX.com" remote-certificate=tech@vpn.XXXXXXXX.com \
remote-id=user-fqdn:tech@vpn.XXXXXXXX.com
/ip ipsec policy
set 0 disabled=yes
add dst-address=192.168.27.48/29 peer=Peer-DB_SERVICE proposal=DB_SERVICE-proposal \
sa-dst-address=185.XX.XX.XX sa-src-address=10.0.2.10 src-address=\
192.168.1.0/24 tunnel=yes
add dst-address=192.168.1.0/24 group="group vpn.XXXXXXXX.com" proposal=\
"proposal vpn.XXXXXXXX.com" src-address=0.0.0.0/0 template=yes
/ip route
add check-gateway=ping comment="WAN 1 marked route" distance=2 gateway=\
10.0.1.1 routing-mark=WAN1-mark
add check-gateway=ping comment="WAN 2 marked route" distance=1 gateway=\
10.0.2.1 routing-mark=WAN2-mark
add comment="Defult route WAN 2" distance=1 gateway=10.0.2.1
add comment="Defult route WAN 2" distance=1 gateway=10.0.2.1
add comment="Default route WAN 1" distance=2 gateway=10.0.1.1
add comment="Default route WAN 1" distance=2 gateway=10.0.1.1
/ip ssh
set forwarding-enabled=remote
/ppp secret
add name=sysAdmin profile=ProfileOVPN service=ovpn
/system clock
set time-zone-name=Europe/Rome
/system logging
add topics=ipsec,!packet
/system ntp client
set enabled=yes server-dns-names=ntp1.inrim.it,time.inrim.it,pool.ntp.org
/tool mac-server
set allowed-interface-list=LAN
/tool mac-server mac-winbox
set allowed-interface-list=LAN
/tool sniffer
set filter-ip-address=192.168.1.253/32

