当前位置: 首页 > news >正文

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

http://www.lryc.cn/news/443886.html

相关文章:

  • ALSA ubuntu 编译
  • 【学习笔记】SSL/TLS证书安全机制之证书透明
  • 网络编程问题解答
  • 【开源免费】基于SpringBoot+Vue.JS服装商城系统(JAVA毕业设计)
  • C语言字符串学习
  • 当你在Linux系统中使用MySQL命令行工具查询数据库时,如果中文显示为问号(?)或其他乱码,简单解决办法。(2)
  • API网关之Fizz Gateway
  • pgvector docker版安装;稀疏向量使用;psycopg2 python连接使用
  • C#命令行参数解析库System.CommandLine介绍
  • CCF CSP题解:密码(key)(202409-1)
  • RuntimeError: Maximum Recursion Depth Exceeded - 递归深度超限的完美解决方案
  • Linux1-ls,cd,pwd
  • 【高级编程】XML DOM4J解析XML文件(含案例)
  • 查看VSFTPD配置的服务器路径和linux系统有哪些用户
  • JavaEE: 创造无限连接——网络编程中的套接字
  • 记K8s组件harbor和kuboard故障恢复
  • c++ return {};
  • 【设计模式-适配】
  • 深度学习02-pytorch-08-自动微分模块
  • 使用Python实现深度学习模型:智能宠物监控与管理
  • 【HTTPS】对称加密和非对称加密
  • MySQL中的LIMIT与ORDER BY关键字详解
  • Java 编码系列:集合框架(List、Set、Map 及其常用实现类)
  • Go进阶概览 -【7.2 泛型的使用与实现分析】
  • 罗德岛战记游戏源码(客户端+服务端+数据库+全套源码)游戏大小9.41G
  • AI+教育|拥抱AI智能科技,让课堂更生动高效
  • WebServer
  • java项目之基于spring boot的多维分类的知识管理系统的设计与实现源码
  • go的结构体、方法、接口
  • 力扣第一题——删除有序数组中的重复项