[SOLVED]Firewall script present, but doesn't do anything

Post new topic   Reply to topic    DD-WRT Forum Index -> Advanced Networking
Author Message
inetquestion
DD-WRT User


Joined: 24 Sep 2015
Posts: 67

PostPosted: Sat Jan 28, 2023 15:40    Post subject: [SOLVED]Firewall script present, but doesn't do anything Reply with quote
Saved an entry in Administration>Commands>Firewall

[code]
iptables -I FORWARD -m set --match-set BLOCKED src -j logdrop
[/code]


Verified the entry above was saved to /tmp/.rc_firewall.

[code]
cat /tmp/.rc_firewall
#!/bin/sh
iptables -I FORWARD -m set --match-set BLOCKED src -j logdrop
[/code]

When router is rebooted, looking at iptables FORWARD chain, there is no entry corresponding to what I expected from the firewall script. Appears it didn't run at all. If I run it manually, and then look at the FORWARD chain it's there. Why is this not running automatically at startup?
Sponsor
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12882
Location: Netherlands

PostPosted: Sat Jan 28, 2023 16:22    Post subject: Reply with quote
What router and which build number are you using?

How (and when) is the BLOCKED set made ?

_________________
Routers:Netgear R7000, R6400v1, R6400v2, EA6900 (XvortexCFE), E2000, E1200v1, WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
dale_gribble39
DD-WRT Guru


Joined: 11 Jun 2022
Posts: 1932

PostPosted: Sat Jan 28, 2023 18:23    Post subject: Reply with quote
Why are you setting match-set twice?

https://ipset.netfilter.org/iptables.man.html

_________________
"The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep." - Robert Frost

"I am one of the noticeable ones - notice me" - Dale Frances McKenzie Bozzio

<fact>code knows no gender</fact>

This is me, knowing I've ruffled your feathers, and not giving a ****
Some people are still hard-headed.

--------------------------------------
Mac Pro (Mid 2012) - Two 2.4GHz 6-Core Intel Xeon E5645 processors 64GB 1333MHz DDR3 ECC SDRAM OpenSUSE Leap 15.5
inetquestion
DD-WRT User


Joined: 24 Sep 2015
Posts: 67

PostPosted: Sat Jan 28, 2023 19:51    Post subject: firewall script not applied after reboot. Reply with quote
Currnetly running version: v3.0-r51306
Linksys WRT3200ACM

Many IPs were added to an ipset list named BLOCKED. This part is working. The part I'm confused about is why doesn't the rule below which is set in the firewall script section result in a rule within the FORWARD table. If I manually run the script it works, just not after a reboot.

Based on what's detailed here, I followed this example.
https://malware.expert/howto/ipset-with-iptables

iptables -I FORWARD -m set --match-set BLOCKED src -j logdrop

I agree, this looks duplicated/incorrect, but changing to anything simpler doesn't work. What is above does work, just not during reboots, which was the point of the post.
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12882
Location: Netherlands

PostPosted: Sat Jan 28, 2023 21:50    Post subject: Re: firewall script not applied after reboot. Reply with quote
inetquestion wrote:
Currnetly running version: v3.0-r51306
Linksys WRT3200ACM

Many IPs were added to an ipset list named BLOCKED. This part is working. The part I'm confused about is why doesn't the rule below which is set in the firewall script section result in a rule within the FORWARD table. If I manually run the script it works, just not after a reboot.

Based on what's detailed here, I followed this example.
https://malware.expert/howto/ipset-with-iptables

iptables -I FORWARD -m set --match-set BLOCKED src -j logdrop

I agree, this looks duplicated/incorrect, but changing to anything simpler doesn't work. What is above does work, just not during reboots, which was the point of the post.


I am familiar with IPSET, it is a sticky in this forum: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=327261

But my question was where is the BLOCKED list coming from, is it created with a script, if so what script and how is it executed or is the list restored from USB?

If the list is not available when the firewall rule is executed then the firewall rule will of course fail as there is no BLOCKED list (yet)

If you do not share the details we cannot help

_________________
Routers:Netgear R7000, R6400v1, R6400v2, EA6900 (XvortexCFE), E2000, E1200v1, WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
dale_gribble39
DD-WRT Guru


Joined: 11 Jun 2022
Posts: 1932

PostPosted: Sun Jan 29, 2023 2:34    Post subject: Reply with quote
It looks as if it is created via ipset itself, considering the example given.
_________________
"The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep." - Robert Frost

"I am one of the noticeable ones - notice me" - Dale Frances McKenzie Bozzio

<fact>code knows no gender</fact>

This is me, knowing I've ruffled your feathers, and not giving a ****
Some people are still hard-headed.

--------------------------------------
Mac Pro (Mid 2012) - Two 2.4GHz 6-Core Intel Xeon E5645 processors 64GB 1333MHz DDR3 ECC SDRAM OpenSUSE Leap 15.5
inetquestion
DD-WRT User


Joined: 24 Sep 2015
Posts: 67

PostPosted: Sun Jan 29, 2023 3:24    Post subject: Reply with quote
The ipset list is created by an external process which updates every minute with new entries. Think I see what you mean...

A test showed I'm unable to issue the iptables command if the ipset part hasn't been done already. Updated the firewall script to this:

ipset -! create BLOCKED hash:ip;
iptables -I FORWARD -m set --match-set BLOCKED src -j logdrop

Will check after reboot to see if this solves it. Thanks!
inetquestion
DD-WRT User


Joined: 24 Sep 2015
Posts: 67

PostPosted: Sun Jan 29, 2023 3:30    Post subject: Reply with quote
Adding ipset command in the firewall script first fixed it. Didn't realize iptables did a verification to ensure that existed, but it makes sense now. :)

Thanks for the assistance!
inetquestion
DD-WRT User


Joined: 24 Sep 2015
Posts: 67

PostPosted: Mon Jan 30, 2023 1:42    Post subject: Reply with quote
Out of curiosity, why is using ipset so much faster than adding rules through iptables? It's orders of magnitude faster. For ~10,000 addresses it took around 200-300 seconds to add them. Now it can be done in seconds... pretty amazing.
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12882
Location: Netherlands

PostPosted: Mon Jan 30, 2023 11:42    Post subject: Reply with quote
If you add rules every rule has to be traversed.

I think Ipset functions somewhat of an indexed database just one Ipset rule which looks up in its database

_________________
Routers:Netgear R7000, R6400v1, R6400v2, EA6900 (XvortexCFE), E2000, E1200v1, WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> Advanced Networking All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum