Linux script for ethtool
-
I am trying to get this script to run in Ubuntu 20.04.
I placed it in /usr/local/bin$, /etc/init.d$,
#!/bin/sh ### BEGIN INIT INFO # Provides: 1000Mbs # Required-Start: $all # Required-Stop: # Default-Start: 2 3 4 5 # Default-Stop: # Short-Description: Halts USB power... ### END INIT INFO ETHTOOL="/usr/sbin/ethtool" DEV="ens32" SPEED="1000 duplex full" RXBUFFERS="4096" TXBUFFERS="4096" NEG="off" case "$1" in start) echo -n "Setting ens32 speed 1000 duplex full autoneg off..."; $ETHTOOL -s $DEV speed $SPEED autoneg $NEG; echo -n "Setting ens32 rx 4096 tx 4096..."; $ETHTOOL -G $DEV rx $RXBUFFERS tx $TXBUFFERS; echo " done.";; stop) ;; esac exit 0
here is /etc/systemd/system/1000Mbs.service
[Unit] After=network.service [Service] ExecStart=/usr/local/bin/1000Mbs.sh [Install] WantedBy=default.target
I
rx and tx don't set. sudo /etc/init.d/1000Mbs does work but not on restart in Ubuntu 20.04.
-
The script might not actually be running when systemd starts the service. Add a line to the end of your script that writes to syslog so you can make sure it is actually running. You can use something like:
logger NIC configuration script has executed
Also, I believe Ubuntu uses the dash shell during boot up so systemd may not be happy with calling that script directly. You might want to consider changing the
ExecStart
line to read:[Service] ExecStart=/usr/bin/bash /usr/local/bin/1000Mbs.sh
You could also consider doing away with the script altogether. You have hardcoded all the values so there is no real advantage over just calling the ethtool command directly and passing command line arguments. That is assuming you didn't have plans to expand the script further later on.
-
I added start to it
[Unit] After=network.service [Service] ExecStart=/usr/local/bin/1000Mbs.sh start [Install] WantedBy=default.target
sudo systemctl enable 1000Mbs.service
to get it to work on restart.
Auto negotiate = off is not working.
ethtool ens32 Settings for ens32: Supported ports: [ TP ] Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Supported pause frame use: No Supports auto-negotiation: Yes Supported FEC modes: Not reported Advertised link modes: 1000baseT/Full Advertised pause frame use: No Advertised auto-negotiation: Yes Advertised FEC modes: Not reported Speed: 1000Mb/s Duplex: Full Port: Twisted Pair PHYAD: 0 Transceiver: internal Auto-negotiation: on MDI-X: off (auto) Cannot get wake-on-lan settings: Operation not permitted Current message level: 0x00000007 (7) drv probe link Link detected: yes
-
The Ubuntu 20.04 servers for CLI only. The only method was using ethtool commands. I searched for a way to add it to the netplan files or another way.