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.