网络接口名称可以有多少长度? [英] What length can a network interface name have?

查看:592
本文介绍了网络接口名称可以有多少长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要调整一些数据库表,以容纳50个以上字符的网络接口名称. 我想知道是否有接口名称可以使用多长时间的标准,所以我可以正确地映射它.

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.

推荐答案

至于Linux的特定部分,在最近的内核版本中,它是由这里.

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.

为了进行经验测试,您可以使用以下命令查看16字节失败而15字节有效:

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

(假设您已经安装了iproute2软件包中的ip,这在过去十年左右的任何Linux发行版中都可能出现.)

(Assuming you have ip from the iproute2 package installed, as is likely on any Linux distribution from within the last decade or so.)

这篇关于网络接口名称可以有多少长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆