How can one obtain MTU range supported by some network device in Linux from bash-script (not directly through netlink API)?
I tried to play with ifconfig
and ip link
but can't find the solution.
Package iproute2 (since v4.19) parses min/max mtu details and prints it to console when "--details" option is provided by user
ip --details link
ip --details link --name=eth0
ip --details addr
ip --details addr show dev eth0
example of script
#!/bin/bash
for nic in eth0 eth1 eth2; do
min_mtu=`ip --details link show $nic | grep 'minmtu'| sed -r 's/^(.*minmtu) ([0-9]+) (.*)$/\2/'`
max_mtu=`ip --details link show $nic | grep 'maxmtu'| sed -r 's/^(.*maxmtu) ([0-9]+) (.*)$/\2/'`
echo "$nic - min: $min_mtu, max: $max_mtu"
done
output:
eth0 - min: 60, max: 9000
eth1 - min: 68, max: 1770
eth2 - min: 68, max: 1770
Debian 10 already has recent enough version of iproute2 package (v4.20) to display min/max mtu. Ubuntu 18.04.3 has a kernel which already provides this information to userspace but iproute2 package is not fresh enough(v4.15) to parse kernel's data (and display them to the user).
You can build fresh iproute2 tools yourself in case you have outdated package.
git clone git://git.kernel.org/pub/scm/network/iproute2/iproute2.git
cd iproute2 && ./configure && make && ./ip/ip --details link