通过限制端口转发数据包的数量来达到限速的目的。

使用的是centos7,默认使用firewalld,需要切换到iptables,将firewalld停掉。

1、安装iptables

#yum -y install yum -y install iptables-services-1.4.21-18.2.el7_4.x86_64  iptables

 

2、使用

#iptables -A FORWARD -p tcp -m tcp --sport 10000 -m limit --limit 500/sec --limit-burst 1000 -j ACCEPT
#iptables -A FORWARD -p tcp -m tcp --sport 10000 -j DROP

#iptables-save >/etc/sysconfig/iptables

#systemctl  enable iptables

#systemctl start iptables

#iptables -nvL

 

3、解释

将10000端口转发的数据包进行过滤,--limit  500/sec  每秒500个数据包,1/m 表示1分钟1个数据包;--limit-burst 1000 表示最开始有1000个令牌环用于转发数据包,即表示每5ms发一个数据包。只有获得令牌环的数据包才会被转发。-j后面的参数保证数据的接受和拒绝。首先ACCEPT满足条件(即每秒数据包小于500)先转发,多余的数据包匹配下面的DROP,将数据包丢弃,从而达到限速的目的。

 

相关文章:

  • 2021-06-05
  • 2022-03-07
  • 2022-12-23
  • 2021-11-18
  • 2021-06-16
  • 2021-10-02
  • 2022-01-07
  • 2021-06-16
猜你喜欢
  • 2021-10-01
  • 2021-10-20
  • 2022-01-28
  • 2022-01-07
  • 2021-07-02
  • 2021-05-22
相关资源
相似解决方案