Limit bandwidth of a physical interface, turn a 10G link into a 1G link


I want a given network card to behave as if it were a slower network card. Like if the 1G interface in my laptop would actually be a 100M or 10M interface. One way of doing that is of course dig out my old 10mbit hub back from the days, and use that for this purpose.

I'm sure there is a "software solution" for that. And indeed, it appears as if the tc command and the tbf feature is able to do that.

Unfortunately, I do not fully grasp the concept to achieve what I wrote above. It seems there is some math involved to take the assumed link speed into account /sys/class/net/*/speed, likely the MTU from /sys/class/net/*/mtu, and the tick rate of the system. I'm not sure if the latter is still required these days with "current" distro kernels (I have CONFIG_NO_HZ=y and CONFIG_HZ_300=y for example).

How would a shell script look like to make such feature more generic? Like bash <interface> 10m|100m|1G|2.5G|10G


As suggested by @vidarlo, changing the link speed does actually work. I was able to change the list of advertised speeds for individual ports on the switch. I had mixed results with using ethtool, even on mlx5 cards which offered a number of different speeds.

I also have a mlx4 card which supports just a single speed. Here I tried the suggested, but incomplete, nc command. Hence the question how to programmatically generate the optimal values. This part remains unanswered, until now. For me a command like this worked on a fixed speed 10G link:

tc qdisc add dev $interface root tbf rate 2000mbit latency 1ms burst 2000mbit

This behaves like a hypothetical 2G card, but most likely the latency and burst values have room for improvement. I also tried 1000mbit and 100mbit with the expected results.

Best Answer

Use ethtool:

ethtool -s $IFACE speed 1000

Note that generally many SFPs only support a single speed. Running ethtool $IFACE will show supported rates and modes.

In addition, you can use tc to reduce available bandwidth; this does nothing to the link speed of the card, but it can shape the data stream:

tc qdisc add dev $IFACE root tbf rate 100mbit

Related Topic