6

I have a packet rate limit (max. 10 per seconds) which is set by my internet provider. This is a problem if I want to use the AceStream player, because if I exceed the limit I get disconnected.

How can I restrict the internet access of this program?

I tried the suggested command:

iptables -A OUTPUT -m limit --limit 10/s -j ACCEPT

but I get a fatal error message:

FATAL: Error inserting ip_tables (/lib/modules/3.2.0-67-generic/kernel/net/ipv4/netfilter/ip_tables.ko): Operation not permitted
iptables v1.4.12: can't initialize iptables table `filter': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.

With administor rights:

sudo iptables -A OUTPUT -m limit --limit 10/s -j ACCEPT

there is no errror message anymore. But it is still not working, I get disconnected.

Is there an error in the command line? Or do I have to use other arguments of iptables?

Below is the actual message that I get, when I exceed the limits of the provider.enter image description here

Up to now, I tried different approaches, but none of them didn't work.

sudo iptables -A INPUT -p tcp --syn --dport 8621 -m connlimit --connlimit-above 10 --connlimit-mask 32 -j REJECT --reject-with tcp-reset

sudo iptables -A INPUT -m state --state RELATED,ESTABLISHED -m limit --limit 9/second --limit-burst 10 -j ACCEPT

sudo iptables -A INPUT -p tcp --destination-port 8621 --syn -m state --state NEW -m limit --limit 9/s --limit-burst 10 -j ACCEPT

This approach seems not to help in order to still use the application. So, I posted another question: set connection limit via iptables .

12
  • 1
    I don't have enough experience with tc to know how to do it with that (although I know it is possible) but there is a means of doing that with cgroups
    – Bratchley
    Oct 22, 2014 at 18:30
  • Do you mean packet limit?
    – Barmar
    Oct 22, 2014 at 18:47
  • sry, I don't know the difference
    – Andy
    Oct 22, 2014 at 20:24
  • @JoelDavis the suggested solution with cgroup does not work, I get error: "only root can do that" for the first line
    – Andy
    Oct 22, 2014 at 20:47
  • 2
    Something like iptables -A OUTPUT -m limit --limit 100/s -j ACCEPT, given a default DROP policy? Not sure about tc, most qdiscs do bandwidth rather than absolute packet counts. Then again, this would drop rather than delay... Oct 23, 2014 at 2:29

2 Answers 2

5

The solution you found was correct:

iptables -A OUTPUT -m limit --limit 10/s -j ACCEPT

But it is assuming a default policy of DROP or REJECT which is not usual for OUTPUT. You need to add:

iptables -A OUTPUT -j REJECT

Be sure to add this rule after the ACCEPT one. Either execute them in this order, or use -I instead of -A for the ACCEPT.

Also, depending on the application this might kill the connection. In that case try with DROP instead of REJECT or try with a different --reject-with (default is icmp-port-unreachable).

I just tested with telnet against a DVR server and it didn't kill the connection. Of course, since a new connection is an output packet, trying to reconnect right after hitting the limit will fail right away if you use REJECT.

I gather from the comments that your ISP also expects you to limit your INPUT packets... you cannot do this. By the time you are able to stop them they've already reached your NIC, which means the were already accounted for by your ISP. The INPUT packet count will also increase considerably when you limit your OUTPUT because most of the ACK won't make it out, causing lots of retransmissions.

10 packets per second is insane.

6
  • thanks! I have to test this, will have the possibility in a few days. Do you know a command line (like ss -t -a) to have surveillance over an application? .. in order to see how many OUTPUT and INPUT packets there are
    – Andy
    Oct 24, 2014 at 17:43
  • Sure. I actually use shorewall for any firewall more complex than "reject everything accept this two services". Check man 5 shorewall-accounting.
    – GnP
    Oct 24, 2014 at 17:50
  • well, it works.. every connection is limited by 10 packets/s
    – Andy
    Oct 26, 2014 at 22:02
  • unfortunately, the application is worthless then... looking at the IP traffic, I have to make another approach: I need to limit the connections per second... is this also possible with iptables?
    – Andy
    Oct 26, 2014 at 22:05
  • Certainly, add an ACCEPT rule to match ESTABLISHED and RELATED connections right before the REJECT or DROP policy. You need conntrack for this, so I would suggest you open a new question (and link it at the end of this one)
    – GnP
    Oct 27, 2014 at 14:03
0

Syn-flood protection:

# iptables -A FORWARD -p tcp --syn -m limit --limit 1/s -j ACCEPT

Furtive port scanner:

# iptables -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s -j ACCEPT

Ping of death:

# iptables -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
3
  • I must be missing something, because I don't see how this answers the question...
    – GnP
    Oct 24, 2014 at 14:16
  • btw I tried this yesterday and it didn't work
    – Andy
    Oct 24, 2014 at 17:41
  • @gnp because poster mentioned me for example , above answer is example... Oct 24, 2014 at 18:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .