Hi guys,
Searching for a way to flush the connection tracking table like I used to under linux I stumbled upon this old thread.
In my past, mainly SIP posed a real issue when changing routes because of it's OPTIONS/keep alive packets for NAT traversal.
My current problem is similar: very high frequent UDP packet flows for an IPsec Tunnel from a device in LAN to a remote ipsec server.
So what I'd need is a real flush, not a sequential delete with error intolerance...
I tried it with the intuitive approach that @pe1chl also mentioned above, just removing '[ find ]', of course not removing more than a hand full of, before running in an error condition for a missing number.
Then I searched here and found this topic and @rextended 's approach. Using >10s as a condition "works", but as it doesn't clear everything and most importantly *not my ipsec connection* this approach doesn't work either.
The situation is:
* "router" is a 2216, behind that is a firewall (192.168.60.5) that is creating an ipsec tunnel to 11.22.33.44.
* Currently "router" doesn't have an internet connection, and is forwarding, without NAT the packets to an other router, that is NATing the traffic to the interwebs. This router is using an other public IP address.
What I want to do is:
* "router" got a physical connection to an ISP now (same ISP, different public IP)
* this connection is on sfp28-8
* there is _no default route_ yet and every time I add the new default route, some connections and most importantly this ipsec tunnel fails
Of course there is a NAT entry:
/ip/firewall/nat/export
# 2025-06-05 19:16:07 by RouterOS 7.16.1
/ip firewall nat
add action=src-nat chain=srcnat comment="NAT local networks" out-interface=sfp28-8 src-address=192.168.0.0/16 to-addresses=44.55.66.77
So, what I'm doing is setting a new default route over sfp28-8 to my gateway.
What I see is: packets take the new route and are being put on the wire -- unNATed with their original (LAN) source address.
[user@router] <SAFE> /ip firewall/connection/print count-only
39533
[user@router] <SAFE> /ip firewall connection remove [find where timeout>10 ]
[user@router] <SAFE> /ip firewall/connection/print count-only
12159
[user@router] <SAFE> /tool/sniffer/quick interface=sfp28-8 ip-address=10.0.0.0/8
Columns: INTERFACE, TIME, NUM, DIR, SRC-MAC, DST-MAC, SRC-ADDRESS, DST-ADDRESS, PROTOCOL, SIZE
INTERFA TIME NUM DI SRC-MAC DST-MAC SRC-ADDRESS DST-ADDRESS PROTOC SIZ
sfp28-8 8.095 11051 -> 48:B5:C4:32:25:F6 5C:76:AB:D3:14:02 192.168.60.5:4500 11.22.33.44:4500 ip:udp 210
sfp28-8 8.096 11052 -> 48:B5:C4:32:25:F6 5C:76:AB:D3:14:02 192.168.60.5:4500 11.22.33.44:4500 ip:udp 162
sfp28-8 8.097 11053 -> 48:B5:C4:32:25:F6 5C:76:AB:D3:14:02 192.168.60.5:4500 11.22.33.44:4500 ip:udp 146
sfp28-8 8.102 11054 -> 48:B5:C4:32:25:F6 5C:76:AB:D3:14:02 192.168.60.5:4500 11.22.33.44:4500 ip:udp 162
sfp28-8 8.106 11057 -> 48:B5:C4:32:25:F6 5C:76:AB:D3:14:02 192.168.60.5:4500 11.22.33.44:4500 ip:udp 226
sfp28-8 8.107 11058 -> 48:B5:C4:32:25:F6 5C:76:AB:D3:14:02 192.168.60.5:4500 11.22.33.44:4500 ip:udp 130
sfp28-8 8.107 11059 -> 48:B5:C4:32:25:F6 5C:76:AB:D3:14:02 192.168.60.5:4500 11.22.33.44:4500 ip:udp 226
sfp28-8 8.107 11060 -> 48:B5:C4:32:25:F6 5C:76:AB:D3:14:02 192.168.60.5:4500 11.22.33.44:4500 ip:udp 162
sfp28-8 8.107 11061 -> 48:B5:C4:32:25:F6 5C:76:AB:D3:14:02 192.168.60.5:4500 11.22.33.44:4500 ip:udp 162
sfp28-8 8.11 11062 -> 48:B5:C4:32:25:F6 5C:76:AB:D3:14:02 192.168.60.5:4500 11.22.33.44:4500 ip:udp 130
sfp28-8 8.113 11063 -> 48:B5:C4:32:25:F6 5C:76:AB:D3:14:02 192.168.60.5:4500 11.22.33.44:4500 ip:udp 130
sfp28-8 8.113 11064 -> 48:B5:C4:32:25:F6 5C:76:AB:D3:14:02 192.168.60.5:4500 11.22.33.44:4500 ip:udp 162
sfp28-8 8.119 11065 -> 48:B5:C4:32:25:F6 5C:76:AB:D3:14:02 192.168.60.5:4500 11.22.33.44:4500 ip:udp 802
sfp28-8 8.122 11066 -> 48:B5:C4:32:25:F6 5C:76:AB:D3:14:02 192.168.60.5:4500 11.22.33.44:4500 ip:udp 482
sfp28-8 8.13 11069 -> 48:B5:C4:32:25:F6 5C:76:AB:D3:14:02 192.168.60.5:4500 11.22.33.44:4500 ip:udp 578
sfp28-8 8.133 11070 -> 48:B5:C4:32:25:F6 5C:76:AB:D3:14:02 192.168.60.5:4500 11.22.33.44:4500 ip:udp 146
using shorter timeouts doesn't work of course:
[user@router] <SAFE> /ip firewall connection remove [find where timeout>2 ]
no such item (4)
Funny thing is.... in the "old" situation, the timeout is much larger than 10s:
[user@router] > /ip/firewall/connection/print where dst-address~"192.168.60.5.*" and src-address~"11.22.33.44.*"
Flags: S - SEEN-REPLY; A - ASSURED; C - CONFIRMED
Columns: PROTOCOL, SRC-ADDRESS, DST-ADDRESS, TIMEOUT, ORIG-RATE, REPL-RATE, ORIG-PACKETS, REPL-PACKETS, ORIG-BYTES, REPL-BYTES
# PROTOCOL SRC-ADDRESS DST-ADDRESS TIMEOUT ORIG-RATE REPL-RATE ORIG-PACKETS REPL-PACKETS ORIG-BYTES REPL-BYTES
92 SAC udp 11.22.33.44:4500 192.168.60.5:4500 3m 203.6kbps 163.0kbps 89 897 210 144 725 843 22 548 518 707 129 096 821 662
So, it _should_ be removed by above query.
I picked the UDP and ipsec connection here as an example, but of course there are others all over the protocol spectrum as well.
As internal clients will lose connection in that scenario, I can't test too long and failback by disabling the new default route.
Connection tracking is the only thing that came to my mind, but maybe I'm hunting for the wrong white rabbit?
If I'm looking in the right direction: is there some other way to really flush and not just clean up the table?
If you don't have any better idea, I will have to
* set the new default route
* reboot the router (maybe using it for a routeros update as well)
* hope that it works after reboot with a clean conntrack table...
Thanks for your ideas and help, very much appreciated!
Irrwitzer