Iptables not appearing to work...

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


Joined: 22 Aug 2013
Posts: 154

PostPosted: Sun Jan 02, 2022 18:31    Post subject: Iptables not appearing to work... Reply with quote
I host twelve game servers behind a router using DD-WRT for the OS. When a player becomes disruptive (normally somebody new who popped on, not a regular player) I kick and/or ban in-game, but to prevent wasted traffic, I also do something like the following via SSH in the router.
Code:

iptables -I FORWARD -p udp --dport 7777:7798 -s 1.2.3.4/24 -j DROP

In older versions of DD-WRT this worked. However, now it does not. I can see the rule at the top of the list but the player can rejoin, still on the exact same address. I ahve tried /32 as well, but no change. It's like iptables is ignoring the rule. What gives?

Router: Netgear XR500
DD Version: v3.0 r47528

Router is solid beyond this bug. I upgraded from a much older version, doing a factory reset both before the upgrade and after, then configured it. OpenVPN works, DNS works, everything, except iptables rules entered from SSH.

_________________
Cicero: Stab you, stab you, stab you!
Psycho: I think he wants to play xylophone with my spinal cord!
Sponsor
Wildlion
DD-WRT Guru


Joined: 24 May 2016
Posts: 1415

PostPosted: Sun Jan 02, 2022 19:55    Post subject: Reply with quote
You will probably have to post the iptables rules, including things like pre-routing otherwise it is hard to debug...

Do you have QOS or SFE enabled?
eibgrad
DD-WRT Guru


Joined: 18 Sep 2010
Posts: 9157

PostPosted: Sun Jan 02, 2022 19:57    Post subject: Reply with quote
I don't see anything obviously wrong w/ the rule (although technically it should be 1.2.3.0/24, but iptables will accept 1.2.3.4/24 too and convert it). If the rule is listed in iptables, then it will work, and should show a hit count if triggered. But I have no way of knowing if the public IP and/or ports you've specified are correct.

I assume the router actually is configured as a router, and NOT in some form of bridged mode (AP only, client/repeater bridge, etc.). Because if it was bridged, then the firewall would have no effect. I also assume the Operating Mode is still the default, Gateway.

_________________
ddwrt-ovpn-split-basic.sh (UPDATED!) * ddwrt-ovpn-split-advanced.sh (UPDATED!) * ddwrt-ovpn-client-killswitch.sh * ddwrt-ovpn-client-watchdog.sh * ddwrt-ovpn-remote-access.sh * ddwrt-ovpn-client-backup.sh * ddwrt-mount-usb-drives.sh * ddwrt-blacklist-domains.sh * ddwrt-wol-port-forward.sh * ddwrt-dns-monitor.sh (NEW!)
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12889
Location: Netherlands

PostPosted: Sun Jan 02, 2022 20:44    Post subject: Reply with quote
Could be SFE being enabled (shortcut forwarding engine on setup page)
_________________
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
Sephiroth
DD-WRT User


Joined: 22 Aug 2013
Posts: 154

PostPosted: Mon Jan 03, 2022 22:52    Post subject: Reply with quote
Sorry for the delayed replies. I just got home from work. Here are my responses in reverse order.

Egc, the SFE is enabled and it was enabled from the moment I installed DD-WRT. I do not know what this is and have not bothered it. I do not see this on any other routing hardware such as Ubiquiti or Watchguard.

Eibgrad, I do use the correct network denotation when I do the rule, I was just typing something here as an example. The address is correct as I literally copy/paste it. Oh, and this worked in the old V2 firmware I ran prior. And yes, the router is a router, not a bridge/AP/etc. My cable modem goes to WAN, I have not configured VLANs so all four ports are one big switch, and two of those go to a Synology DS1019+ NAS. The others go to switches at opposite ends of my home.

Wildlion, I am hesitant to post the rules as they expose my internal LAN info and addresses of those banned. While a player may be a pile of crap in-game I do respect their privacy. If it becomes necessary to publish the rules, I will do so after editing the private stuff out.

When I type the rule into the SSH connection and do "iptables -L" I do indeed see the rule. That is why it bothers me that it does not work.

_________________
Cicero: Stab you, stab you, stab you!
Psycho: I think he wants to play xylophone with my spinal cord!
Wildlion
DD-WRT Guru


Joined: 24 May 2016
Posts: 1415

PostPosted: Wed Jan 05, 2022 0:01    Post subject: Reply with quote
I understand...

The few things I can think of to check to see if a iptables rule of RELATED or ESTABLISHED is kicking in first... or if something higher up is triggering/changing... like in the pre-NAT area

FYI SFE stands for short cut forwarding engine and it is a way to accelerate the packets going through the system... so the reason we were asking is to see if SFE is picking up the packets and therefore accelerating the system/bypassing firewall rules (SFE affects QOS)

I do not know if you are able to test but that would be my suggestions
Sephiroth
DD-WRT User


Joined: 22 Aug 2013
Posts: 154

PostPosted: Thu Jan 06, 2022 16:59    Post subject: Reply with quote
I already figured it out. You had some great ideas, Wildlion, but it was the SFE. I researched it. Upon disabling it my up speed stayed the same and I lost about 50Mbps down, but now the iptables rules work. This scares me because it may mean a way in for hackers. Granted, I am a home user and my systems and NAS devices hold only games and pictures dating back to the 90's. No bank info, nothing special. I do, however, have a few of these in the wild where security may be more important and now I may need to disable this feature at the cost of speed to ensure security.
_________________
Cicero: Stab you, stab you, stab you!
Psycho: I think he wants to play xylophone with my spinal cord!
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12889
Location: Netherlands

PostPosted: Thu Jan 06, 2022 18:38    Post subject: Reply with quote
Great you figured it out Wink

You only need to temporarily disable (or flush the connection table) SFE after you activated the IPtables rule with:
Code:
stopservice sfe
startservice sfe

_________________
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
Sephiroth
DD-WRT User


Joined: 22 Aug 2013
Posts: 154

PostPosted: Fri Jan 07, 2022 15:03    Post subject: Reply with quote
Oh, so I can leave SFE enabled so long as I restart that service after manual changes? I'll give it a try. Thanks, egc.
_________________
Cicero: Stab you, stab you, stab you!
Psycho: I think he wants to play xylophone with my spinal cord!
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12889
Location: Netherlands

PostPosted: Fri Jan 07, 2022 15:17    Post subject: Reply with quote
Exactly that should work Smile
_________________
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
Sephiroth
DD-WRT User


Joined: 22 Aug 2013
Posts: 154

PostPosted: Tue Jan 11, 2022 21:57    Post subject: Reply with quote
OK, this did not work. I enabled the SFE, rebooted the router, and then logged into an SSH terminal. I entered the rule and verified it was first on the list. Then I entered "stopservice sfe" followed by "startservice sfe". No go. Tested with a helper at a remote location and I could not block their connection while SFE was on.
Code:

iptables -I FORWARD -p udp --dport 1234 -s 3.2.1.0/24 -j DROP
stopservice sfe
startservice sfe

Am I missing something?

_________________
Cicero: Stab you, stab you, stab you!
Psycho: I think he wants to play xylophone with my spinal cord!
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12889
Location: Netherlands

PostPosted: Wed Jan 12, 2022 13:26    Post subject: Reply with quote
I just tested on my R7800.

That R7800 is a secondary downstream router.

The video server is on the main subnet on 192.168.0.59.

While SFE is on I add a blocking rule:
Code:
root@R7800-2:/tmp# iptables -vnL FORWARD
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 REJECT     all  --  *      *       192.168.0.59         0.0.0.0/0            reject-with icmp-port-unreachable
    2   104 ACCEPT     all  --  tun1   *       0.0.0.0/0            0.0.0.0/0            state NEW


Nothing happens and the movie plays on.

After:
stopservice sfe
startservice sfe

The movie stops (it takes some time as VLC buffers) but you can also see it in action:
Code:
root@R7800-2:/tmp# iptables -vnL FORWARD
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
   40  660K REJECT     all  --  *      *       192.168.0.59         0.0.0.0/0            reject-with icmp-port-unreachable
    2   104 ACCEPT     all  --  tun1   *       0.0.0.0/0            0.0.0.0/0            state NEW

_________________
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
Sephiroth
DD-WRT User


Joined: 22 Aug 2013
Posts: 154

PostPosted: Wed Jan 12, 2022 16:35    Post subject: Reply with quote
Odd, but remember, I am blocking UDP. I have an XR500, very similar to yours unless I am mistaken. Does yours properly block UDP? That might be key.

For reference, we tested by having one of my players connect to one of our servers. I then implemented the rule, specifying UDP and the server port, and he dropped after a minute. I enabled SFE, he connected again, and I added the rule. No drop. I did the service stop and start. He stayed connected for an additional 15-20min, so it was not working. As soon as I disabled SFE, iptables worked again.

_________________
Cicero: Stab you, stab you, stab you!
Psycho: I think he wants to play xylophone with my spinal cord!
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12889
Location: Netherlands

PostPosted: Thu Jan 13, 2022 15:58    Post subject: Reply with quote
Use only the source address of the client and not the UDP and the ports and see if that makes a difference.

Always check the rules with:
iptables -vnL FORWARD

check if SFE is removed after "stopservice sfe"
when sfe is running you will see fastclassifer module loaded with lsmod:
Code:
root@R7800-2:~# lsmod
Module                  Size  Used by
fast_classifier       138432  0
nf_nat_pptp             1600  0


fastclassifier should be gone after "stopservice sfe"

although normally not necessary you can flush the connection tracking after stop and start e.g.:
Code:
stopservice sfe
startservice sfe
cat /proc/sys/net/netfilter/nf_conntrack_flush 2>&1
cat /proc/net/ip_conntrack_flush 2>&1


That is all I can think off

_________________
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
Sephiroth
DD-WRT User


Joined: 22 Aug 2013
Posts: 154

PostPosted: Mon Jan 17, 2022 15:49    Post subject: Reply with quote
I will check this and report back the next time I can take down the router. Thanks again for your help, egc.
_________________
Cicero: Stab you, stab you, stab you!
Psycho: I think he wants to play xylophone with my spinal cord!
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