Detailed description of iptableslimit parameter speed limit

Source: Internet
Author: User
Limit matching: limits the frequency or rate of matched packets. It is clear that it is used to limit the frequency and rate of matched packets. here, the term limit is often used to limit others' misunderstandings. In fact, to be accurate, it should be matched at a certain rate. As for the restriction or allow, it is implemented by the following-j action, limit is only a match module, and its function is to match

Limit matching: limits the frequency or rate of matched packets. It is clear that it is used to limit the frequency and rate of matched packets. here, the term "limit" often gives people a misunderstanding of "limitation". In fact, it should be "matching at a certain rate ", as for "limit" or "allow", the following-j action is implemented. limit is only a match module, and its function is matching. The matching method is based on a certain rate.

Use the limit module of iptables. The target is ACCEPT. when you set 300/s, it sends a token every 3 ms, the packet that obtains the token can be sent out, the packet that does not get the token can only wait for the next token to arrive, this will not cause some packet loss, nor cause the so-called "disconnection.

The following two items areCmpBurst restrictions
Iptables-a input-p icmp-m limit -- limit 1/sec -- limit-burst 10-j ACCEPT
Iptables-a input-p icmp-j DROP

The first ipables indicates a limit.PingPackage one per second, 10 and then start again.

At the same time, IP fragmentation can be restricted, and only 100 fragments are allowed per second to prevent DoS attacks.
Iptables-a input-f-m limit -- limit 100/sec -- limit-burst 100-j ACCEPT


The following describes in detail the functions of the limit module of iptables:




  • Limit the input speed of ping (echo-request)

Before the limit, ping every 0.2 seconds
Ping your. linux. ip-I 0.2

Only one icmp echo-request packet is allowed per second
Iptables-a input-p icmp -- icmp-type echo-request-m limit -- limit 1/s -- limit-burst 1-j ACCEPT
Iptables-a input-p icmp -- icmp-type echo-request-j DROP

-- Limit 1/s indicates once per second; 1/m indicates once per minute.
-- Limit-burst indicates the maximum number of limit triggers allowed (default: 5)

Ping once every 0.2 seconds, and the response is once per second.
Ping your. linux. ip-I 0.2

The following rule can also accept only one echo-request Packet per second
Iptables-N pinglimit
Iptables-A pinglimit-m limit -- limit 1/s -- limit-burst 1-j ACCEPT
Iptables-A pinglimit-j DROP
Iptables-a input-p icmp -- icmp-type echo-request-j pinglimit






  • Create custom Chain, limit tCpOnline once per minute, the Log record is triggered by a superuser (recorded in/var/log/messages)

Iptables-N ratelimit
Iptables-A ratelimit-p tcp-mStatE -- state ESTABLISHED, RELATED-j ACCEPT
Iptables-A ratelimit-p tcp -- syn-m limit -- limit 1/m -- limit-burst 1-j ACCEPT
Iptables-A ratelimit-p tcp-j LOG -- log-level "NOTICE" -- log-prefix "[RATELIMIT]"
Iptables-A ratelimit-p tcp-j DROP

Reference a custom Chain to limit the connection frequency of ssh (tcp port 22) connections (specific IP sources are not limited)
Iptables-a input-p tcp -- dport 22-s 192.168.0.0/16-j ACCEPT
Iptables-a input-p tcp -- dport 22-j ratelimit

Supplement: Clear Custom Chain
Iptables-L-n -- line-number
Iptables-d input n
Iptables-F ratelimit
Iptables-X ratelimit






  • Prevent SYN-Flood fragment attacks

Iptables-N syn-flood
Iptables-A syn-flood-m limit -- limit 50/s -- limit-burst 10-j RETURN
Iptables-A syn-flood-j DROP
Iptables-I INPUT-j syn-flood

You can use httperf/webbe on your own.NcUse stress testing tools such as h to simulate syn-flood attacks.





  • Iprange a. B. c. Does the d-a. B .c.d represent this segment of address or each included address?

Iptables-a input-m iprange -- src-range 172.16.1.10-172.16.16.1-m limit -- limit 300/second-j ACCEPT

Indicates that the address 172.16.1.10-172.16.16.1 matches a total of 300 data packets per second, or does the address 172.16.1.10-172.16.16.1 match 300 data packets for each ip address?
According to the author's experience, iprange a. B. c. d-a. B .c.d should indicate that a segment of address matches a total of 00 packets per second. The reader can verify it.

Ping prohibited
Echo 1>/proc/sys/net/ipv4/icmp_echo_ignore_all

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.