I'm trying to use the iptables connrate match extension, but I can't get it working:
root@XXXXXXXXX:/# iptables -t mangle -A TEST_CHAIN -m connrate --connrate 0:1000 -j ACCEPT
iptables v1.8.3 (legacy): Couldn't load match `connrate':No such file or directory
Try `iptables -h' or 'iptables --help' for more information.
I have the iptables-mod-conntrack-extra package installed, but it turns out the description of this package doesn't actually mention connrate. Is there some other package I need to install?
Sure. My use case is for DSCP classification. I have a chain called SET_INTERACTIVE which sets the DSCP tag on the packet (to CS2/16 in this case) and stores the DSCP value in the connection mark, so it can be restored later on for other packets on the same connection. This same chain is used to restore the DSCP tag after matching against the connmark.
I put remote admin connections into this class (VNC, SSH, NAS interface etc.). However, my NAS uses the same port for its GUI as it does for file uploads/downloads, and I don't want the latter classified as CS2. So I need to limit the match to connections where the transfer rate is less than a threshold, say 1000KB/s.
The connrate extension is the obvious choice, but it can be done with hashlimit as well, as follows:
I add this rule to the SET_INTERACTIVE chain before the rule that tags packets as CS2. If the rate on a packet's flow exceeds 1000KB/s we RETURN out of the chain, which prevents the packet from being tagged as CS2. In my setup the packet will just fall through the rest of my chains and remain as the default, CS0. However, the connection retains the CS2 connmark so the "demotion" of its packets to CS0 will be lifted if the flow rate drops below 1000KB/s.