Score:1

How can I limit link speed on Ubuntu server 20.04

fi flag

OS:Ubuntu 20.04 server - Virtualbox Interface: enp0s3

I've been looking ofr a solution to limit link speed to 10Mb/s, half duplex and autonegotiation disabled. As I saw on the [link][1] guide but it doesn't work. When I do a networkctl status enp0s3, it just shows autonegotiation on, speed 1Gs and Duplex full. And that never changes, even if it shows it's taking the configuration from my file. Then I discovered the systemctl status systemd-udevd command to get more information about the issue and I found this error:

I need to create a file inside /etc/systemd/network/ that's called 10-mb.link to apply the following configuration:

[MATCH]

MACAddress=ex:am:pl:e0:ma:c1

[LINK]

BitsPerSecond=10M

Duplex=Half

I followed these instructions: [1]: https://manpages.ubuntu.com/manpages/focal/man5/systemd.link.5.html and [2]: https://linuxiac.com/how-to-manipulate-ethernet-card-on-linux-with-ethtool-command/

But none worked, I don't know what else to try, my testing system doesn't have NetworkManager (which I read could be causing issues, but it's not even installed)

Also, on the physical devices I've been able to set configuration I said above on, but as soon as we boot, they lose what's been configured. I did it using this command: "ethtool -s enp2s0 speed 10 duplex half autoneg on" but it doesn't work on the virtual machine, my system just forgets about it after booting up, so my question is, how can I make this changes permanent?

Score:0
jp flag

You can add that command as a cronjob using sudo crontab -e then add a line to run the command after each boot like this:

@reboot sleep 30 && ethtool -s enp2s0 speed 10 duplex half autoneg on

The sleep 30 will delay the execution of the command for 30 seconds after boot to allow the interface to come up first … You can decrease or increase the delay as you need.

Alternatively, you can use different methods to achieve some or all the results you want … For example, you can use traffic shaping rules using only tc to limit the bandwidth rate ... I copied mine and modified it eliminating irrelevant rules and changing the numbers to match your requirement ... It should limit download and upload to 10 Mbit/second ... Copy/paste and execute all commands one at a time:

sudo tc qdisc add dev wlp2s0 root handle 1: cbq avpkt 1000 bandwidth 10mbit
sudo tc class add dev wlp2s0 parent 1: classid 1:1 cbq rate 10000kbit allot 1500 prio 5 bounded isolated
sudo tc class add dev wlp2s0 parent 1:1 classid 1:10 cbq rate 10000kbit allot 1600 prio 1 avpkt 1000
sudo tc class add dev wlp2s0 parent 1:1 classid 1:20 cbq rate 10000kbit allot 1600 prio 2 avpkt 1000
sudo tc qdisc add dev wlp2s0 parent 1:10 handle 10: sfq perturb 10
sudo tc qdisc add dev wlp2s0 parent 1:20 handle 20: sfq perturb 10
sudo tc filter add dev wlp2s0 parent 1:0 protocol ip prio 10 u32 match ip tos 0x10 0xff  flowid 1:10
sudo tc filter add dev wlp2s0 parent 1:0 protocol ip prio 11 u32 match ip protocol 1 0xff flowid 1:10
sudo tc filter add dev wlp2s0 parent 1: protocol ip prio 13 u32 match ip dst 0.0.0.0/0 flowid 1:20
sudo tc qdisc add dev wlp2s0 handle ffff: ingress
sudo tc filter add dev wlp2s0 parent ffff: protocol ip prio 50 u32 match ip src 0.0.0.0/0 police rate 10000kbit burst 1000kbit drop flowid :1

You need to change wlp2s0 to the name of your interface.

You should read the documentation first, but if you get stuck with 10 Mbit/s and don't know how to go back, this should bring you back:

sudo tc qdisc del dev wlp2s0 handle ffff: ingress
sudo tc qdisc del dev wlp2s0 root

Change wlp2s0 to the name of your interface here as well.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.