What length can a network interface name have?
Solution 1
As far as the Linux-specific part of this, in recent kernel versions this is defined by IFNAMSIZ to be 16 bytes, so 15 user-visible bytes (assuming it includes a trailing null). IFNAMSIZ
is used in defining struct net_device's name field here.
In order to test empirically, you can use the following to see that 16 bytes fails and 15 bytes works:
# CLEAN SLATE
root# ip link ls dev 123456789012345
Device "123456789012345" does not exist.
root# ip link ls dev 1234567890123456
Device "1234567890123456" does not exist.
# FAIL
root# ip link add dev 1234567890123456 type dummy
Error: argument "1234567890123456" is wrong: "name" too long
root# ip link ls dev 1234567890123456
Device "1234567890123456" does not exist.
# PASS
root# ip link add dev 123456789012345 type dummy
root# ip link ls dev 123456789012345
40: 123456789012345: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT group default
link/ether ... brd ff:ff:ff:ff:ff:ff
# CLEAN UP
root# ip link del dev 123456789012345
(Assuming you have ip
from the iproute2 package installed, as is likely on any Linux distribution from within the last decade or so.)
Solution 2
Also, if you want to use the interface with DHCP, the name must have length < 14, due to this issue:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=858580
Andrei Matei
Engineering Manager at Micro Focus by day. iOS developer and tech enthusiast by night.
Updated on June 02, 2022Comments
-
Andrei Matei almost 2 years
I need to adjust some database tables in order to accommodate 50+ character long network interface names. I wonder if there is a standard on how long an interface name can be, so I can map it correctly.
-
Mikko Rantalainen about 3 yearsSee also: bugs.debian.org/cgi-bin/bugreport.cgi?bug=704072 (Linux DHCP client has problems if device name has 14 or more characters and the
ip
command fails if device name has 16 or more characters.) -
András Korn almost 3 yearsThat has allegedly been fixed in 2015, in version
4.3.2-1
, at least according to bugs.debian.org/cgi-bin/bugreport.cgi?bug=704072.