• OS + Centos TC


    s

    linux 下使用 tc 模拟网络延迟和丢包-使用 linux 模拟广域网延迟 - Emulating wide area network delays with Linux

    https://www.cnblogs.com/xuyaowen/p/netem.html

    tc 是linux 内置的命令;使用man pages 查看 我们看到,其功能为 show / manipulate traffic control settings,可对操作系统进行流量控制;

    netem 与 tc:

    netem 是 Linux 2.6 及以上内核版本提供的一个网络模拟功能模块。该功能模块可以用来在性能良好的局域网中,模拟出复杂的互联网传输性能,诸如低带宽、传输延迟、丢包等等情况。使用 Linux 2.6 (或以上) 版本内核的很多发行版 Linux 都开启了该内核功能,比如 Fedora、Ubuntu、Redhat、OpenSuse、CentOS、Debian 等等。 tc 是Linux 系统中的一个工具,全名为 traffic control(流量控制)。tc 可以用来控制 netem 的工作模式,也就是说,如果想使用 netem ,需要至少两个条件,一个是内核中的 netem 功能被包含,另一个是要有 tc 。

    需要注意的是:本文介绍的流控只能控制发包动作,不能控制收包动作,同时,它直接对物理接口生效,如果控制了物理的 eth0,那么逻辑网卡(比如 eth0:1)也会受到影响,反之,如果您在逻辑网卡上做控制,该控制可能是无效的。(注:虚拟机中的多个网卡可以在虚拟机中视为多个物理网卡)。

    DESCRIPTION
           NetEm  is  an  enhancement  of the Linux traffic control facilities that allow to add delay, packet loss,
           duplication and more other characteristics to packets outgoing from a selected network  interface.  NetEm
           is built using the existing Quality Of Service (QOS) and Differentiated Services (diffserv) facilities in
           the Linux kernel.

    Linux下用tc控制网络延时和丢包率:

    复制代码
    tc修改网络延时:
    
    sudo tc qdisc add dev eth0 root netem delay 1000ms
    
    删除策略:
    
    sudo tc qdisc del dev eth0 root netem delay 1000ms
    
    修改丢包率:
    sudo tc qdisc add dev eth0 root netem loss 10%
    
    删除策略:
    sudo tc qdisc del dev eth0 root netem loss 10%

    配置确认:
    sudo tc qdisc show dev enp2s0

    配置删除:
    sudo tc qdisc del dev enp2s0 root
    复制代码
    复制代码
    NetEm (already enabled in the Linux kernel) provides Network Emulation functionality for testing protocols by emulating the properties of wide area networks. 
    
    To simulate an additional latency of 80 ms, just type sudo tc qdisc add dev eth0 root netem delay 80ms 
    It just adds a fixed amount of delay to all packets going out of the local Ethernet. 
    
    To stop the additional latency, just type sudo tc qdisc change dev eth0 root netem delay 0ms 
    
    Lines to add to the file /etc/rc.local before exit 0, to add 40ms of latency :
    
    # Add +40ms latency tc qdisc add dev eth0 root netem delay 40ms
    
    Note: If your network interface is not eth0, replace eth0 with the name of your network interface
    复制代码

    在调研 iperf 的时候,偶然看到。对项目很有帮助。

    原文链接:https://iperf.fr/iperf-servers.php#netem 

    扩展阅读:https://www.cnblogs.com/Dev0ps/p/8985778.html 

    https://blog.csdn.net/huuinn/article/details/80970079 

    https://wiki.linuxfoundation.org/networking/netem 

    https://wiki.linuxfoundation.org/networking/netem#emulating_wide_area_network_delays (更多万维网模拟相关) 

    tc 高级用法:

    延迟有波动并成正态分布趋势:

    tc qdisc add dev eth0 root netem delay 100ms 20ms distribution normal
     
    centos tc 端口限速

    #http://www.fx114.net/qa-178-108967.aspx
    #http://professor.blog.51cto.com/996189/1569481/
    #http://blog.csdn.net/x_i_y_u_e/article/details/43016053
    #http://bbs.itzmx.com/forum.php?mod=viewthread&tid=10669&page=1
    1.rate – 您可以设置允许的带宽。
    2.ceil – 您可以设置的突发带宽时,允许桶。
    3.prio – 您可以设置额外的带宽优先级。 prios较低的类所提供的带宽。例如,您可以给DNS流量和HTTP下载PRIO较低。
    4.iptables和TC:你需要使用iptables和TC如下:控制出站HTTP流量。
    ####################测试可以正常限速########################################
    #限制速度
    #下面教程是限制为5Mbps,也就是640KB/S
    #设置根
    tc qdisc add dev em1 root handle 1: htb
    #设置允许的速度为2M,突发最大流量为2M,优先级为1
    tc class add dev em1 parent 1: classid 1:5 htb rate 1Mbps ceil 1Mbps prio 1
    #设置防火墙id与规则id对应关系,id 1:5对应防火墙标记id为5
    tc filter add dev em1 parent 1:0 protocol ip handle 5 fw flowid 1:5
    #配置防火墙
    #设置端口7500流量标记为5,应用流量限制规则到7500端口
    /sbin/iptables -A OUTPUT -t mangle -p tcp --sport 7500 -j MARK --set-mark 5
    #####################################常用命令
    #清空规则
    tc qdisc del dev em1 root
    tc -s qdisc ls dev em1
    #查看tc规则
    tc qdisc ls dev em1
    tc -s qdisc ls dev em1
    tc class ls dev em1
    tc -s class ls dev em1
    #查看防火墙
    iptables -t mangle -n -v -L

    end

    centos tc 端口限速

  • 相关阅读:
    phpstorm设置断点调试(转载)
    tp5引用样式路径没反应(转载)
    thinkphp5 关于加载静态资源路径问题(下载)
    jQuery多次选中checkbox失效(转载)
    redis的持久化及配置
    mysql+es+fastdfs+MongoDB的备份及灾备
    es的集群加密码
    redis-cluster的部署安装
    tomcat的日志分割脚本
    ansible介绍
  • 原文地址:https://www.cnblogs.com/lindows/p/14522794.html
Copyright © 2020-2023  润新知