【linux】tc命令使用总结

本文详细介绍了如何在虚拟机中使用tcqdisc工具进行网络延迟、抖动、丢包、重复包和带宽限制的设置,包括延迟规则、振幅变化、均匀变异和正态分布,以及PacketLoss、PacketCorruption和PacketDuplicates等网络属性的控制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

笔者使用的是虚拟机做如下测试。 注意没有eth0网卡

虚拟机IP状态

查看queue状态

查看所有网卡

tc qdisc ls
tc qdisc ls

查看指定网卡

tc qdisc show dev enp0s3
tc qdisc show dev enp0s3


delay延迟

tc qdisc add dev enp0s3 root netem delay 1000ms

命令详解
qdisc: 类型为 queuing discipline,不懂的请先查询一下基本概念
add: add a new rule
dev eth0: rules will be applied on device eth0
root: modify the outbound traffic scheduler (aka known as the egress qdisc)
netem: use the network emulator to emulate a WAN property
delay: the network property that is modified
1000ms: introduce delay of 1000 ms

执行前
执行前

执行后
执行后
delay最后还是有两个参数

命令1.增加振幅

delay不是一个固定的值,而是在后面这个参数的增加减少幅度内变动
tc qdisc add dev enp0s3 root netem delay 1000ms 500ms
增加振幅
可以看到delay的幅度在500(1000-500)和1500(1000+500)之间了。

命令2. uniform variation with correlation value

tc qdisc add dev enp0s3 root netem delay 1000ms 500ms 20%
使振幅根据uniform variation with correlation value发生变化。

命令3. distribution normal正态分布变化

tc qdisc add dev enp0s3 root netem delay 1000ms 500ms distribution normal


Packet Loss丢包

tc qdisc add dev enp0s3 root netem loss 50%
tc qdisc add dev enp0s3 root netem loss 50%

Packet Corruption 包损

tc qdisc add dev enp0s3 root netem corrupt 50%
tc qdisc add dev enp0s3 root netem corrupt 50%
通过PING看不出corruption,包的传送都没有问题的

Packet Duplicates 重复包

tc qdisc add dev enp0s3 root netem duplicate 50%
通过PING看不出Duplicates,包的传送都没有问题的

Bandwidth limit限制带宽

tc qdisc add dev enp0s3 root tbf rate 1mbit burst 32kbit latency 400ms

参数说明:
tbf: use the token buffer filter to manipulate traffic rates
rate: sustained maximum rate
burst: maximum allowed burst
latency: packets with higher latency get dropped

其他操作

删除

tc qdisc del dev enp0s3 root

修改

tc qdisc change dev enp0s3 root netem delay 1000ms

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值