iptables限制网速

1、使用 hashlimit来限速

#从eth0网卡进入INPUT链数据,使用模块hashlimit 限制网速为100kb/s或2mb/s,超过限制的数据包会被DROP。OUTPUT链同理,mode为srcip,有4个mode选项:

  1. srcip(默认匹配每个源地址IP,配置指定源地址IP,使用-s参数)
  2. dstip(默认匹配每个目的地址IP,配置指定目的地址IP,使用-d参数)
  3. srcport(默认匹配每个源端口,配置指定源端口,使用-sport参数)
  4. dstport(默认匹配目的端口,配置指定目的端口,使用-dport参数)

2、 限制从eth0网卡 到IP地址网速

2.1 限制 从eth0网卡到所有IP地址 INPUT/OPUTPU数据网速为100kb/s:

root@localhost \~# iptables -A INPUT -i eth0 -m hashlimit --hashlimit-above 100kb/s --hashlimit-mode srcip --hashlimit-name in -j DROP

root@localhost \~# iptables -A OUTPUT -o eth0 -m hashlimit --hashlimit-above 100kb/s --hashlimit-mode dstip --hashlimit-name out -j DROP

****root@localhost \~#****iptables -L -n --line-numbers #查看添加的iptables规则

****root@localhost \~#****iptables -D INPUT 1 #根据查到iptables规则编号进行删除

2.2 限制 从eth0网卡 固定IP 地址 INPUT/OUTPUT数据网速为100kb/s:

root@localhost \~# iptables -A INPUT -i eth0 -m hashlimit --hashlimit-above 100kb/s --hashlimit-mode srcip -s 192.168.3.36 --hashlimit-name in -j DROP

root@localhost \~# iptables -A OUTPUT -o eth0 -m hashlimit --hashlimit-above 100kb/s --hashlimit-mode dstip -d 192.168.3.36 --hashlimit-name out -j DROP

****root@localhost \~#****iptables -L -n --line-numbers #查看添加的iptables规则

****root@localhost \~#****iptables -D INPUT 1 #根据查到iptables规则编号进行删除

root@localhost \~# iptables -D OUTPUT 1

3、 限制从eth0网卡 到端口 网速

3.1 限制 从eth0网卡所有端口 INPUT/OPUTPU数据网速为100kb/s:

root@localhost \~# iptables -A INPUT -i eth0 -m hashlimit --hashlimit-above 100kb/s --hashlimit-mode srcport --hashlimit-name in -j DROP

root@localhost \~# iptables -A OUTPUT -o eth0 -m hashlimit --hashlimit-above 100kb/s --hashlimit-mode dstport --hashlimit-name out -j DROP

****root@localhost \~#****iptables -D INPUT 1 #根据查到iptables规则编号进行删除

root@localhost \~# iptables -D OUTPUT 1

3.2 限制 从eth0网卡 固定 端口 IPINPUT/OUTPUT数据网速为100kb/s:

root@localhost \~# iptables -A INPUT -i eth0 -m hashlimit --hashlimit-above 100kb/s --hashlimit-mode srcport -p tcp --sport 9985 --hashlimit-name in -j DROP

root@localhost \~# iptables -A OUTPUT -o eth0 -m hashlimit --hashlimit-above 100kb/s --hashlimit-mode dstport -p tcp --dport 9985 --hashlimit-name out -j DROP

****root@localhost \~#****iptables -D INPUT 1 #根据查到iptables规则编号进行删除

root@localhost \~# iptables -D OUTPUT 1

3.3 限制 从eth0网卡 固定 端口 IPINPUT/OUTPUT数据网速为100kb/s:

root@localhost \~# iptables -A INPUT -i eth0 -m hashlimit --hashlimit-above 100kb/s --hashlimit-mode srcport -s 192.168.3.36 -p tcp --sport 9985 --hashlimit-name in -j DROP

root@localhost \~# iptables -A OUTPUT -o eth0 -m hashlimit --hashlimit-above 100kb/s --hashlimit-mode dstport -d 192.168.3.36 -p tcp --dport 9985 --hashlimit-name out -j DROP

****root@localhost \~#****iptables -D INPUT 1 #根据查到iptables规则编号进行删除

root@localhost \~# iptables -D OUTPUT 1

注:默认是来所有IP对应的端口,如果指定固定IP,请参考使用-s和-d参数。

原文链接:https://blog.csdn.net/mayifan0/article/details/116149344

相关推荐
码农学院1 小时前
基于运维监控体系的网络品牌推广方案:从架构设计到技术实现
运维·网络
爱写代码的森8 小时前
鸿蒙三方库 | harmony-utils之ImageUtil图片保存到本地详解
服务器·华为·harmonyos·鸿蒙·huawei
REDcker9 小时前
显示分辨率标准对照详解
前端·网络·分辨率·显示·屏幕
ANSIOT10 小时前
安朔科技蓝牙无感开锁方案,靠近自动解锁
网络·科技·物联网
晏宁科技YaningAI11 小时前
VoIP系统的工程实现模型:从信令控制到媒体传输的完整架构解析
网络·人工智能·架构·系统架构·信息与通信
HLC++11 小时前
Linux的进程间通信
android·linux·服务器
华清远见IT开放实验室12 小时前
实验室建设案例 | 石家庄科技信息职业学院嵌入式实验室——从底层硬件到系统应用,一所应用型高校的嵌入式人才培养这样落地
linux·arm开发·stm32·嵌入式硬件·高校·实验室建设
白露与泡影13 小时前
Arthas 实战指南:从方法耗时定位到 JVM 变量热修改
服务器·jvm·c#
神奇霸王龙14 小时前
Claude Code屠榜:MiMo与Grok紧追Codex
服务器·网络·人工智能·gpt·ai·ai编程
Web极客码14 小时前
WordPress SEO优化:提升网站排名的13个关键步骤
服务器·seo·wordpress