Community discussions

MikroTik App
 
yastt
just joined
Topic Author
Posts: 9
Joined: Wed Oct 24, 2018 10:45 pm

WAN failover - IPSec does not work on second link

Mon Apr 15, 2024 1:58 am

The hAP ax3 ROS 7.12 router operates a switching mechanism between two public Internet links called "public" and "backup". This is managed by a script based on Netwatch and routing table rules that was once published on this forum. For simplicity, I omitted it in the description below, because my problem occurs when only a single backup link is raised.

The solution worked perfectly, but it had one drawback - if the public interface was raised, the backup interface did not respond to ping.
Since this exact problem was described in this thread: viewtopic.php?t=166417, I used the entries provided there - but only for the backup interface.
In the listing below, these additional lines have been marked with the comment "added".

After this, both interfaces started pinging correctly from outside, even when both were active. However, a new problem appeared - when I turned off the public interface (i.e. when working only on the backup connection), the ipsec tunnel to our office stopped being established.

I am asking for help or at least a hint on what I should modify in my configuration to achieve:
- both public links should respond to ping,
- the ipsec tunnel must work properly on each of these two links.


Below is my configuration (omitting irrelevant lines):
/ip firewall filter
	add chain=input action=accept connection-state=established,related,untracked comment="accept established,related, untracked"
	add chain=input action=accept log-prefix="winbox - administration" port=4000,4443,8291 protocol=tcp src-address-list=Trusted comment="remote administration https 4443 WinBox 4000,8291"
	add chain=input action=accept ipsec-policy=in,ipsec log-prefix="incoming ipsec:" comment="accept in ipsec policy to router"	
	add chain=input action=accept in-interface-list=WAN protocol=icmp comment="accept ICMP"
	add chain=input action=drop in-interface-list=WAN log-prefix="dropped in WAN:" comment="drop all from WAN"

	add chain=forward action=accept ipsec-policy=in,ipsec comment="accept in ipsec"
	add chain=forward action=accept ipsec-policy=out,ipsec comment="accept out ipsec"
	add chain=forward action=fasttrack-connection connection-state=established,related comment="defconf: fasttrack"
	add chain=forward action=accept connection-state=established,related,untracked comment="accept established,related, untracked"
	add chain=forward action=drop connection-state=invalid log=no log-prefix="invalid fw:" comment="drop invalid forward"
	add chain=forward action=accept connection-nat-state=dstnat log-prefix="port_forwards:" comment="accept port forwards"
	add chain=forward action=drop in-interface-list=WAN ipsec-policy=in,none src-address-list=NotPublic log-prefix="!public from WAN:" comment="drop all packets from internet which should not exist in public network and not ipsec"
	add chain=forward action=drop connection-nat-state=!dstnat connection-state=new in-interface-list=WAN log-prefix="!NAT from WAN:" comment="drop new from WAN not DSTNATed" 

/ip ipsec profile
	add dh-group=modp2048 dpd-interval=30s enc-algorithm=aes-256 hash-algorithm=sha256 lifetime=8h name=sophos
/ip ipsec peer
	add address=headoffice_ip exchange-mode=ike2 name=ITSA profile=sophos
/ip ipsec proposal
	add auth-algorithms=sha256 enc-algorithms=aes-256-cbc lifetime=8h name=sophos pfs-group=modp2048
/ip ipsec identity
	add my-id=fqdn:sko217 peer=ITSA remote-id=fqdn:centrala
/ip ipsec policy
	set 0 disabled=yes dst-address=0.0.0.0/32 src-address=0.0.0.0/32
	add action=none comment=LAN dst-address=10.0.25.0/24 src-address=10.0.25.0/24
	add comment=ITSA dst-address=10.0.0.0/8 level=unique peer=ITSA proposal=sophos src-address=10.0.25.0/24 tunnel=yes

/ip firewall nat
	add chain=srcnat action=masquerade out-interface-list=WAN ipsec-policy=out,none comment=";;; defconf masquerade"

#NETWATCH
/tool netwatch
	add comment=public disabled=no host=9.9.9.9 interval=30s packet-count=20 packet-interval=1s startup-delay=30s type=icmp
	add comment=public disabled=no host=208.67.220.220 interval=30s packet-count=20 packet-interval=1s startup-delay=30s type=icmp
	add comment=backup disabled=no host=9.9.9.10 interval=30s packet-count=20 packet-interval=1s startup-delay=30s type=icmp
	add comment=backup disabled=no host=208.67.220.222 interval=2m packet-count=20 packet-interval=5s startup-delay=30s type=icmp

# ROUTING LOGIC
/routing table
	add disabled=no fib name=to_public
	add disabled=no fib name=to_backup
# added whole line
	add disabled=no fib name=to_isp2
/routing rule
	add action=lookup-only-in-table disabled=no dst-address=9.9.9.9/32 table=to_public
	add action=lookup-only-in-table disabled=no dst-address=9.9.9.10/32 table=to_backup
	add action=lookup-only-in-table disabled=no dst-address=208.67.220.220/32 table=to_public
	add action=lookup-only-in-table disabled=no dst-address=208.67.220.222/32 table=to_backup
# added whole line
	add action=lookup-only-in-table disabled=no src-address=ip_of_backup_interface table=to_isp2
/ip route
	add comment=public disabled=no distance=1 dst-address=0.0.0.0/0 gateway="$PublicGateway"
# added routing-table to existing line
	add comment=backup disabled=no distance=2 dst-address=0.0.0.0/0 gateway="$BackupGateway"  routing-table=to_isp2
	add comment="test_public" disabled=no distance=1 dst-address=0.0.0.0/0 gateway="$PublicGateway" routing-table=to_public
	add comment="test_backup" disabled=no distance=2 dst-address=0.0.0.0/0 gateway="$BackupGateway" routing-table=to_backup
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 19644
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: WAN failover - IPSec does not work on second link

Mon Apr 15, 2024 3:17 am

What makes you thing you know the relevant lines, if you dont know what the problem is??
Suggest full config is more useful and perhaps a network diagram.
I never look at snippets, not worth my time,based on answering 1000s of posts.

/export file=anynameyouwish (minus router serial number and any public WANIP information, keys etc. )
 
yastt
just joined
Topic Author
Posts: 9
Joined: Wed Oct 24, 2018 10:45 pm

Re: WAN failover - IPSec does not work on second link

Mon Apr 15, 2024 2:47 pm

Ok I see. I did not want to attach the full configuration, because it is highly expanded with additional functionalities that may complicate the analysis of the main problem.
Following your advice, I dumped the configuration of one of our routers into a file. I only changed our public IP addresses and domain names.
I would be very grateful for further help.
You do not have the required permissions to view the files attached to this post.
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 19644
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: WAN failover - IPSec does not work on second link

Mon Apr 15, 2024 4:25 pm

First thing to fix. Use only one bridge!!
viewtopic.php?t=143620

Simplify your life by defining at least two vlans
vlan10 is trusted or home vlan
vlan20 is guest wifi vlan
you can add if you wish to separate out servers, or multimedia, or video cameras or other equipment that should not be on the trusted LAN.
you can add more vlans for different wifi needs as well,
RP filter strict is a BAD idea especially with multiple WANS, change to loose.
Your WAN IP address and dhcp client were confusing until I realized you had one of each them disabled.
Please clean up a config so you dont have such confusion existing............

Firewall address lists for local subnets are a waste, unless its a remote subnet that doesnt exist on the router.
Your firewall rules have very little to do with needed traffic and more on blocking crap.
Suggest its a waste of time at least in getting a working config going. You can add some things back if you need to.....
AKA........... default rules plus what is needed for traffic. Hint at end of forward chain drop all traffic.

Having www and telnet setup for services is not a secure methodology to use and recommend disabling those.
IP Routes are messy.
Not clear what you are trying to do with routing rules either.
Out of control scripts
Overboard netwatch.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

The main focus should be go back to basics, get the config working then add back in what is needed, not what you think is nice to have.
To do so, clearly state your requirements so a clean practical config can be developed.
Identify all user(s)/device(s), including the Admin
Identify all traffic they require to have. ( without mention of the config )

For the two WANS, are they both public IPs, or private IPs, static or dynamic?
I gather WAN1 is primary and WAN2 is secondary and you dont want to share the load at all time so both WAN1 and WAN2 are used at the same time?
(throughput of each?)
I see you do have external users that need to reach router services (IPSEC), any reason why much simpler and very secure Wireguard is not being used..........???
Do you have any external traffic going to the LAN........aka any servers on the LAN??

What would you like to do with netwatch purpose of its use at the moment.
Purpose of all the scripts??

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], johnson73, marko982, youngster2002 and 61 guests