Community discussions

MikroTik App
 
uberwebguru
Member Candidate
Member Candidate
Topic Author
Posts: 173
Joined: Sat Feb 26, 2022 12:05 pm

mikrotik firewall not working as expected

Sun Apr 17, 2022 8:53 pm

So i have setup a destination nat to route traffic from public ip 98.137.11.164 directly to a private ip 192.168.10.111 and works fine
Now i want to restrict traffic so that only my internet public ip 172.217.14.174 can access this destination nat public ip
but it is not working, am not sure what else i need to do or why this is not so straight forward

Here is what i have as firewall rule, i even moved it to the very top of all firewall rules
but i can access the destination nat public ip by anyone on internet still

172.217.14.174 is my internet public ip, only this ip should be allowed, others DROP
98.137.11.164 is destination nat public ip which routes to local ip 192.168.10.111
chain: input
src address: !172.217.14.174
dst address: 98.137.11.164
action: drop

this rule does not work, so why is it not working?
 
msatter
Forum Guru
Forum Guru
Posts: 2942
Joined: Tue Feb 18, 2014 12:56 am
Location: Netherlands / Nīderlande

Re: mikrotik firewall not working as expected

Sun Apr 17, 2022 9:01 pm

I only hope the IP addresses are not real IP adresses that you use/have.

Never ever put real IP on the internet unless you like to receive many 'visitors'!

The one that going to snitch on you...Users browsing this forum: Ahrefs [Bot], Baidu [Spider],etc. mentioned at the bottom of the page.
 
Sob
Forum Guru
Forum Guru
Posts: 9188
Joined: Mon Apr 20, 2009 9:11 pm

Re: mikrotik firewall not working as expected

Sun Apr 17, 2022 9:04 pm

Because chain=input has nothing to do with it, connections to forwarded ports go in chain=forward. And if you want it for only one address, you can do it directly in dstnat rule, e.g.:
/ip firewall nat
add chain=dstnat dst-address=98.x.x.x src-address=172.x.x.x <conditions for protocol and port if you're not forwarding everything> action=dst-nat to-addresses=192.168.10.111
 
uberwebguru
Member Candidate
Member Candidate
Topic Author
Posts: 173
Joined: Sat Feb 26, 2022 12:05 pm

Re: mikrotik firewall not working as expected

Sun Apr 17, 2022 9:05 pm

I only hope the IP addresses are not real IP adresses that you use/have.

Never ever put real IP on the internet unless you like to receive many 'visitors'!

The one that going to snitch on you...Users browsing this forum: Ahrefs [Bot], Baidu [Spider],etc. mentioned at the bottom of the page.
lol, ofcourse those are google and yahoo ips!!!
 
uberwebguru
Member Candidate
Member Candidate
Topic Author
Posts: 173
Joined: Sat Feb 26, 2022 12:05 pm

Re: mikrotik firewall not working as expected

Sun Apr 17, 2022 9:07 pm

Because chain=input has nothing to do with it, connections to forwarded ports go in chain=forward. And if you want it for only one address, you can do it directly in dstnat rule, e.g.:
/ip firewall nat
add chain=dstnat dst-address=98.x.x.x src-address=172.x.x.x <conditions for protocol and port if you're not forwarding everything> action=dst-nat to-addresses=192.168.10.111
I want to separate the NAT rules from firewall rules
So how do i do this with firewall rules?
Better to separate them, so that way i make management easy for me
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 22081
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: mikrotik firewall not working as expected

Sun Apr 17, 2022 9:09 pm

sob nailed it.......... add source address to the dst-nat rule which limits access to that source IP.
If you have several IPs, then one can use a source-address-list!

The good thing about using source in a destination nat rule is that the port will not be visible on scans!!
If you DONT use source, then the port will appear (visible) on scans but will appear closed.
 
Sob
Forum Guru
Forum Guru
Posts: 9188
Joined: Mon Apr 20, 2009 9:11 pm

Re: mikrotik firewall not working as expected

Sun Apr 17, 2022 9:18 pm

Main part is to use correct chain (forward instead of input), correct addresses (forward no longer sees original destination, but 192.168.10.111), then if you want to do it properly, you need to do it only for dstnatted connections, otherwise it may block (depends on your other rules) also connections from internal server to that external address (if you ever wanted that). So something like:
/ip firewall filter
add chain=forward src-address=!172.x.x.x dst-address=192.168.10.111 connection-state=dstnat action=drop
I find the way with limited dstnat rule simpler and easier to understand, but it's up to you.
 
msatter
Forum Guru
Forum Guru
Posts: 2942
Joined: Tue Feb 18, 2014 12:56 am
Location: Netherlands / Nīderlande

Re: mikrotik firewall not working as expected

Sun Apr 17, 2022 9:33 pm

I only hope the IP addresses are not real IP adresses that you use/have.

Never ever put real IP on the internet unless you like to receive many 'visitors'!

The one that going to snitch on you...Users browsing this forum: Ahrefs [Bot], Baidu [Spider],etc. mentioned at the bottom of the page.
lol, ofcourse those are google and yahoo ips!!!
Nice going, Yahoo and Google will be pleased that they earn even more money from all those 'visitors'.
 
uberwebguru
Member Candidate
Member Candidate
Topic Author
Posts: 173
Joined: Sat Feb 26, 2022 12:05 pm

Re: mikrotik firewall not working as expected

Sun Apr 17, 2022 10:44 pm

Main part is to use correct chain (forward instead of input), correct addresses (forward no longer sees original destination, but 192.168.10.111), then if you want to do it properly, you need to do it only for dstnatted connections, otherwise it may block (depends on your other rules) also connections from internal server to that external address (if you ever wanted that). So something like:
/ip firewall filter
add chain=forward src-address=!172.x.x.x dst-address=192.168.10.111 connection-state=dstnat action=drop
I find the way with limited dstnat rule simpler and easier to understand, but it's up to you.
I tried forward also, the firewall rule does not work at all
i can access from anywhere still

i also tried what you have and added the connection NAT state to dstnat and does not work
but even the bigger rule without additional connection NAT state does not work

why is not working is my question? because this is an issue then because this is a simple rule that one should expect should work like 1, 2, 3
 
Sob
Forum Guru
Forum Guru
Posts: 9188
Joined: Mon Apr 20, 2009 9:11 pm

Re: mikrotik firewall not working as expected

Sun Apr 17, 2022 10:47 pm

Other rules. If this one doesn't block it, some other rule before this one already allowed it.
 
uberwebguru
Member Candidate
Member Candidate
Topic Author
Posts: 173
Joined: Sat Feb 26, 2022 12:05 pm

Re: mikrotik firewall not working as expected

Mon Apr 18, 2022 1:42 am

Other rules. If this one doesn't block it, some other rule before this one already allowed it.
I have this rule at the very top of firewall rules, i only have 3 rules in there, so not much
and the 2 other rules just allow traffic from one public ip to/fro another public ip via input and output chains, which works fine

yeah the whole thing is just weird, it looks so simple but i can access this ip from anywhere still
 
uberwebguru
Member Candidate
Member Candidate
Topic Author
Posts: 173
Joined: Sat Feb 26, 2022 12:05 pm

Re: mikrotik firewall not working as expected

Mon Apr 18, 2022 1:51 am

/ip firewall filter
add chain=forward src-address=!172.x.x.x dst-address=192.168.10.111 connection-state=dstnat action=drop
Ok now it blocks everyone including the public i need it not block
seems i missed the private ip in dst address, i thought that was the public ip
I really want to separate the NAT and firewall rules that is why
So i know NAT is for NAT and firewall rules are for the firewall rules
May not be generally easier, but for me it is


One other question, why is it that the first rule i had did not work?



172.217.14.174 is my internet public ip, only this ip should be allowed, others DROP
98.137.11.164 is destination nat public ip which routes to local ip 192.168.10.111
chain: input
src address: !172.217.14.174
dst address: 98.137.11.164
action: drop
 
Sob
Forum Guru
Forum Guru
Posts: 9188
Joined: Mon Apr 20, 2009 9:11 pm

Re: mikrotik firewall not working as expected

Mon Apr 18, 2022 2:00 am

Input chain is only for traffic to router itself, to server running on router, e.g. when you're connecting to router with WinBox or use WebFig. Traffic passing through router and going somewhere else uses forward chain.

And if I understood correctly that your whole firewall consists of only three rules including this one, there's no way it could be secure or correct.
 
uberwebguru
Member Candidate
Member Candidate
Topic Author
Posts: 173
Joined: Sat Feb 26, 2022 12:05 pm

Re: mikrotik firewall not working as expected

Mon Apr 18, 2022 2:51 am

Input chain is only for traffic to router itself, to server running on router, e.g. when you're connecting to router with WinBox or use WebFig. Traffic passing through router and going somewhere else uses forward chain.

And if I understood correctly that your whole firewall consists of only three rules including this one, there's no way it could be secure or correct.
Yeah just 3 rules, am still learning here but know a lot already
What rules do i need to be better secured?
 
Sob
Forum Guru
Forum Guru
Posts: 9188
Joined: Mon Apr 20, 2009 9:11 pm

Re: mikrotik firewall not working as expected

Mon Apr 18, 2022 3:27 am

Since default action is accept, i.e. if you don't block something, it's allowed, it's very likely that you have everything wide open to whole world.

Check this thread, it's rather long, so at least the example at the beginning (point 1). The idea is to use stateful firewall to allow packets for already established connections, drop packets seen by connection tracking as invalid, then the rest is new connections, so allow what should pass, and finally block the rest. It's not the only way, but to me it seems simple and easy to understand.
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 22081
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: mikrotik firewall not working as expected

Mon Apr 18, 2022 5:28 am

Checkout item B. here - viewtopic.php?t=182373

For port forwarding, unlike other routers I have used, only one firewall rule is needed and applies to all port forwarding (dst-nats of that ilk).
add chain=forward action=accept connection-nat-state=dstnat

The rest of the details per individual rule are done under the NAT rules..........
 
uberwebguru
Member Candidate
Member Candidate
Topic Author
Posts: 173
Joined: Sat Feb 26, 2022 12:05 pm

Re: mikrotik firewall not working as expected

Mon Apr 18, 2022 5:49 am

Yeah will have to focus on firewall for next 1 week before going PROD
I kind of have similar setup on my current Juniper SRX240 router also, and had it wide open too for like 8 years
But want a more security focused setup now
Will read up and work more on the firewall side now

Will post questions i have later
Thanks
 
Sob
Forum Guru
Forum Guru
Posts: 9188
Joined: Mon Apr 20, 2009 9:11 pm

Re: mikrotik firewall not working as expected

Mon Apr 18, 2022 6:27 am

It's not that keeping things open must inevitably bring troubles. At first sight, why couldn't e.g. WinBox be accessible, if you have strong password, perhaps you even do some rate limiting for new connections, etc. There's practically zero chance that anyone would get in by bruteforcing it. And then something like this happens. Nasty bug where one connection is enough. So it's safer to be a bit paranoid.
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 22081
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: mikrotik firewall not working as expected

Tue Apr 19, 2022 7:36 pm

If you don't trust certain IPs, just don't allow them to connect to WAN. Then they can't use fast track either. If you trust an IP, it doesn't matter which port that IP uses in case it is compromised. If you close down 443 inboout might use 85358 anyway.
Wrong approach Kate, I will never know all the things or ports or IPs I should block, BuT I DO know what I want to allow.
Thus as per the link above for firewalls the optimal approach is a DROP: ALL rule at the end of the input and forward chains.
In this regard I am forced to create the rules to allow traffic and this is a much smaller 'BUNCH OF THINGS" to know.

I CAN BLOCK EVERYTHING just by dropping everything
I can then allow only a few things and these are things I do know about.
DONE.
 
User avatar
dwnldr
Frequent Visitor
Frequent Visitor
Posts: 58
Joined: Sat Apr 11, 2020 10:06 am

Re: mikrotik firewall not working as expected

Sat Sep 23, 2023 12:18 pm

Dear community,

since my question is related to firewall issues, i set my question here instead of creating new topic. I would like to kindly ask you for assistance :

I recently switched from "hap ac" to "rb4011". The device was configured by myself, used in same place - with same clients and options as previous hap ac. Im struggling with Firewall function, however i had the same rules set on previous device, running without any problems.
We are talking only about 3+1 rules. Blocking internet connection for specific devices (created address list), blocking DNS request for the same devices-same address list, and KidControl for one device. None of those rules are "catching" any datas, packets. For the "blocklist" stays traffic always as "0 bytes-packets" and also the KidControl "device" does the same = no IP address visible under added device, no packets captured even if the device is used, KidControl not working. Normally under KidControl "device" tab was all my devices in network visible, i could grab and "save" any of them to apply the rule. This list has now only 1 entry added manually by myself, no devices are discovered. As i mentioned, i was using those rules for 2years under same conditions in hap ac. It is for sure some configuration fault, which i made during setup, but i have no idea what can affect the traffic in way, that isnt filtered by rules.

My configuration is pretty basic :
- only one subnet/DHCP is used
- all devices used in firewall rules has fixed IPs, are visible under DHCP lease, traffic is visible
- using latest ROS
- no other network device, DHCP server is present in this network
- no VLANs used
- internet connection is established via PPPoE from ether1, where ISP ONT is connected

Print from my firewall rules. The address list for blocking is called "block" :)
/ip firewall filter
add action=drop chain=input dst-port=53 in-interface-list=WAN protocol=tcp src-address-list=block
add action=drop chain=input dst-port=53 in-interface-list=WAN protocol=udp src-address-list=block
add action=drop chain=forward in-interface-list=WAN src-address-list=block
add action=jump chain=forward comment="jump to kid-control rules" jump-target=kid-control
/ip firewall nat
add action=masquerade chain=srcnat out-interface-list=WAN
/ip kid-control device
add mac-address=30:74:67:F3:6D:07 name="Samsung Galaxy A52" user="Kid Control"
Thank you very much !
 
User avatar
mkx
Forum Guru
Forum Guru
Posts: 13044
Joined: Thu Mar 03, 2016 10:23 pm

Re: mikrotik firewall not working as expected

Sat Sep 23, 2023 12:35 pm

If firewall rules you posted (and I quoted below) are indeed all of them ... then no wonder it doesn't work for you. I highlited the rule which makes me think you've had many more rules on your old device ... it refers to kid-control firewall chain ... which doesn't exist in shown config.
/ip firewall filter
add action=drop chain=input dst-port=53 in-interface-list=WAN protocol=tcp src-address-list=block
add action=drop chain=input dst-port=53 in-interface-list=WAN protocol=udp src-address-list=block
add action=drop chain=forward in-interface-list=WAN src-address-list=block
add action=jump chain=forward comment="jump to kid-control rules" jump-target=kid-control

If I were you, I'd take this router off-line imediately and rework the config. This time keeping as much default setup as possible and only add what's necessary.
 
User avatar
dwnldr
Frequent Visitor
Frequent Visitor
Posts: 58
Joined: Sat Apr 11, 2020 10:06 am

Re: mikrotik firewall not working as expected

Sat Sep 23, 2023 1:13 pm

@mkx - Thank you very much for your reply. I have no other firewall rules, only the posted ones. The KidControl rule appears dynamically, if i set the rule to "ON" or "Resume", so if i would block the connection of my childrens device. Otherwise it is empty. But also the previous rules for blocking my IoT devices from connection are not working here :/ Maybe the order is confusing you, which was done by me as a try to get work the previous ones, but it didnt helped... Normally is the KidControl on first position.
The configuration was done exactly like that. Configured from scratch, only the needed options. The additional part are only those 3rules rules. I dont understand why should i take it offline immediately.........
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 22081
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: mikrotik firewall not working as expected

Sat Sep 23, 2023 3:10 pm

When you decide to take advice and put a proper firewall on your device, I would be interested, but it seems you are here to prove your 3 rules iare good enough or something chow!
 
User avatar
dwnldr
Frequent Visitor
Frequent Visitor
Posts: 58
Joined: Sat Apr 11, 2020 10:06 am

Re: mikrotik firewall not working as expected

Sat Sep 23, 2023 4:27 pm

@anav - Thank you for your reply !
Exactly as you described. Im here ONLY to kindly ask for assistance about 4 mentioned items in my firewall, and nothing else ! But this forum behaves as usually, as its well known :) Im not interested with "support" like this anymore
 
User avatar
mkx
Forum Guru
Forum Guru
Posts: 13044
Joined: Thu Mar 03, 2016 10:23 pm

Re: mikrotik firewall not working as expected

Sat Sep 23, 2023 10:48 pm

The configuration was done exactly like that. Configured from scratch, only the needed options. The additional part are only those 3rules rules. I dont understand why should i take it offline immediately.........
So what is the posted config: complete config or "additional part"? If the former, then your router is pretty much wide open to the attacks from internet.

If the later, I'll paraphrase a sentence, posted recently in another thread: how can you know what to take out if you didn't know what to put in? In other words: whole setup in ROS is interleaved and if you don't show us the whole of it, we can't get the big picture and we can't help you. In essence you're wasting our time. Since you're asking for hell and we're the kind volunterrs trying to help you, you should at least respect our attempts.
 
User avatar
dwnldr
Frequent Visitor
Frequent Visitor
Posts: 58
Joined: Sat Apr 11, 2020 10:06 am

Re: mikrotik firewall not working as expected

Sun Sep 24, 2023 12:47 am

@mkx - Thank you for your feedback !

The posted config is the full config of my FW rules. KidControl is on last position just because of my attempts to make first three work... I dont have any FW rules, because my router is behind ISP ONT device with Dynamic IP changing couple of times per day, no ports on my router are opened-forwarded, and im charged monthly by ISP for "secure connection (whatever it means)" besides costs for fibre internet. I am connected like this to the web on two different locations for 7 / 3years without issues. My only connection from outside is via Zerotier (just because SmartHome control). Just to clarify, i dont say that any additional security is not welcome from my side, but i never had configured anything additional. Was not needed, had never troubles, and honestly i cant do that correctly. I was able on my previous router to block mentioned DNS requests and internet connection with same config for couple of devices from my network with those rules (only to avoid connecting IoT devices to cloud services, since im using them locally and they cant "talk" simoutaneusly to two destinations) and KidControl to have a magic weapon against my children :D Those are actually my goals only, to get back the "block" functionality.
If im wasting your time, please feel free to scroll further and please ignore my question. Im also pissed off, if somebody-something steals my time, of course. Since my lack of deeper knowledge here is a fact, i wasted lot of time to try searching for solution, documentations, made attemps to achieve my goal. Since i still failed, i made a last try here. The request was aimed for somebody, who can spend bit time and knowledges providing some assistance without feeling of waisting it.

Thank you !
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 22081
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: mikrotik firewall not working as expected

Sun Sep 24, 2023 5:16 pm

Nothing like a slovakian lovefest!

Regardless if nothing has happened, it only takes one incident to ruin ones life, what MKX is suggesting is common sense and prudent firewall rules, that are easy to implement and that ALSO include your blocking strategy by default.

THis is a stock setup that keeps the required default rules and keep access to the router, solely to the admin and blocks all traffic except that specifically permitted.
/ip firewall address-list
add address=admin-IP1  list=Authorized
add address=admin-IP2  list=Authorized
{ etc....... }
/ip firewall filter
{Input Chain}
(default rules to keep)
add action=accept chain=input comment="defconf: accept established,related,untracked" connection-state=established,related,untracked
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="defconf: accept to local loopback:"  dst-address=127.0.0.1
(user rules)
add action=accept chain=input src-address-list=Admin 
add action=accept chain=input comment="Allow LAN DNS queries-UDP" \ 
dst-port=53 in-interface-list=LAN protocol=udp
add action=accept chain=input comment="Allow LAN DNS queries - TCP" \
dst-port=53 in-interface-list=LAN protocol=tcp
add action=drop chain=input comment="drop all else"
{forward chain}
(default rules to keep)
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=fasttrack-connection chain=forward comment="defconf: fasttrack" connection-state=established,related
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
(user rules)
add action=accept chain=forward comment="allow internet traffic" in-interface-list=LAN out-interface-list=WAN
add action=accept chain=forward comment="allow port forwarding" connection-nat-state=dstnat  { disable or remove if not req'd }
add action=drop chain=forward comment="drop all else"
.........

It should be fairly easy to add what you mean by kid control, but you stated it in config speak and not requirement speak.

1. identify user(s)/device(s), groups of users/devices
2. identify what traffic they should be allowed to execute.
3. the rules above block all other traffic automatically.

For example the above rules
input chain --> allow the admin to config the router
input chain --> allow all LAN users access to router DNS services
forward chain --> allow all LAN users access to internet
forward chain --> allow port forwarding,, in case you have any port forwarding or dst-nat requirements ( can be disable or removed if not useful ).

What I dont understand is the purpose of kid control.
Are you attempting to control a number of IP/mac addresses as to
a. where they can go in terms of internet?
b. what time they can execute traffic?

etc.........

Who is online

Users browsing this forum: Guscht, ncats, sindy and 48 guests