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

相关推荐
Alphapeople7 分钟前
moveit真机部署
linux·运维·服务器
pt104322 分钟前
网络自动化Python课程:Netconf与Restconf及Cisco自动化配置实验
网络·python·自动化
Eminem8930 分钟前
2、k8s环境规划
linux·运维·kubernetes
神仙别闹32 分钟前
基于C++ WinPcap 的网络抓包软件
网络·c++·php
LabVIEW开发1 小时前
使用 LabVIEW 获取文件的创建日期:从内置函数到 Windows API 封装
网络·windows·labview·labview知识·labview功能·labview程序
DevOpenClub1 小时前
全球区域与 IP 定位工作台案例方案
大数据·网络·网络协议·tcp/ip
打团从来人不齐1 小时前
Linux服务器搭建笔记-008:台式机共享WIFI
linux·服务器·笔记
wuyk5551 小时前
从零吃透 Modbus 通信|第 6 章:线圈功能码 05/0F 实现 & Modbus‑TCP 基础入门
c语言·网络·网络协议·tcp/ip
NJCloud1 小时前
Docker 私有仓库部署:Registry、加密传输与认证鉴权
运维·网络·docker·云原生·容器
w200512241 小时前
K8S控制器管理
linux·云原生·容器·kubernetes