大网数据广告活动
服务器运维问答

Limit number of incoming packets per second for a INPUT UDP port [per IP only, not globally] [Ubuntu IPTables]

· 52CE 我爱测

I searched and I can't find a rule to limit the count of the incoming packets for a INPUT UDP port per second and per IP. I need that per all IPs that connect to my socket , not for a specific one. I'm using iptables on Ubuntu 14…

问题原文

原帖链接 · AA. · CC BY-SA 3.0

I searched and I can't find a rule to limit the count of the incoming packets for a INPUT UDP port per second and per IP.

I need that per all IPs that connect to my socket, not for a specific one.

I'm using iptables on Ubuntu 14.0.4 LTS amd64.

I am familiar how UDP works. In my scenario someone can create great number of UDP sockets using different ports.

I need only one socket from a single IP can connect to my UDP port.

Is this possible with iptables? I know Netfilter and C++, can i do this with that?

已采纳解答

原帖链接 · prosti · CC BY-SA 3.0

Here is what you can do:

iptables -A INPUT -p udp -s 111.111.111.111 --dport 123 -m limit --limit 25/minute --limit-burst 100 -j ACCEPT

You need to have limit iptables extension. The example provided limits maximum 25 connection per minute. The limit-burst 100 indicates that the limit/minute will be enforced only after the total number of connection have reached the limit-burst level.

From the manual:

-s, --source address[/mask][,...]
              Source specification. Address can be either a network name, a hostname, a network IP address (with  /mask),  or  a  plain  IP
              address.  Hostnames  will be resolved once only, before the rule is submitted to the kernel.  Please note that specifying any
              name to be resolved with a remote query such as DNS is a really bad idea.  The mask can be either an ipv4 network  mask  (for
              iptables) or a plain number, specifying the number of 1's at the left side of the network mask.  Thus, an iptables mask of 24
              is equivalent to 255.255.255.0.  A "!" argument before the address specification inverts the sense of the address.  The  flag
              --src  is an alias for this option.  Multiple addresses can be specified, but this will expand to multiple rules (when adding
              with -A), or will cause multiple rules to be deleted (with -D).

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-03-03)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。