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.
Asked
Active
Viewed 637 times
2

narotello
- 419
- 2
- 14
-
it looks like there is no good answer to this question - https://unix.stackexchange.com/questions/552107/how-to-get-maximum-supported-mtu-size-for-interface – Maxim Sagaydachny Dec 03 '19 at 10:55
-
Sometimes it is easier to write a small C program to do the work, and then call it from Bash. – jww Dec 03 '19 at 14:29
-
@jww, and what would your program do? I made quick check and did not find any ioctl which would report such capability. I just patched ping tool to use IP_PMTUDISC_PROBE and for some reason it keeps telling me _"Message too long, mtu=1500"_ despite my nick supporting jumbo frames. Probably it is impossible to get out of the nic driver otherwise ethtool would report such capability for sure. This is interesting question and it is wonder why it is not possible to do... http://man7.org/linux/man-pages/man7/ip.7.html – Maxim Sagaydachny Dec 03 '19 at 14:46
-
@Maxim - The C program would call the netlink API directly and write the result to stdout. – jww Dec 03 '19 at 14:47
-
@jww So can we get such range from Netlink API? Could you show some little C code snippet or at least netlink options/keywords for googling? – narotello Dec 03 '19 at 15:26
-
@narotello, I looked into netlink API and did not find anything related to hardware so I think netlink can't be used for getting hardware capabilities of NICs. – Maxim Sagaydachny Dec 05 '19 at 05:50
-
@MaximSagaydachny Thank you for that info. – narotello Dec 05 '19 at 13:35
-
@narotello, Actually kernel 5.4 contains line **"nla_put_u32(skb, IFLA_MAX_MTU, dev->max_mtu)"** - it means that in new kernel you could use RTM_GETLINK to det this information from kernel. I found no other code which would expose it to userland. So if you by chance are using new kernel then there is a chance to get min/max mtu from kernel. I did not check what version of kernel this code was added in. Here is were it did came from https://github.molgen.mpg.de/donald/linux/commit/3e7a50ceb11ea75c27e944f1a01e478fd62a2d8d – Maxim Sagaydachny Dec 05 '19 at 13:57
-
@MaximSagaydachny Could the ***put***-function allow to ***get*** something? If you did some successful research, can you post the code example as answer? – narotello Dec 10 '19 at 09:55
-
@narotello, I can clone https://github.com/thom311/libnl and add support for it. Most likely they will merge my changes back and it will eventually become mainstream. This way you could use libnl-utils to get this value in a bash script (on new versions of kernel). It should not take long but right now I'm a bit busy. I will do it during this week. – Maxim Sagaydachny Dec 10 '19 at 10:12
-
@MaximSagaydachny Thank you, I'll be waiting! – narotello Dec 10 '19 at 10:23
1 Answers
1
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

Maxim Sagaydachny
- 2,098
- 3
- 11
- 22