问题描述
TODO 如何在 Linux 中修改网卡的名称
该笔记将记录:在 Linux 中,如何修改网卡名称,以及相关问题处理方法;
解决方案
方法一、直接重命名(临时方法)
可以使用命令ip link直接修改网络接口名:
# 关闭网卡 ip link set dev peth0 down ifconfig peth0 down # 修改网卡名 ip link set peth0 name eth0 # 启动网卡 ip link set dev eth0 up ifconfig eth0 up
方法二、使用 Udev 配置
ArchWiki/Network configuration/Tips and tricks
[Solved] Predictable Network Interface changes interface names / Newbie Corner / Arch Linux Forums
系统环境:Debian
修改/etc/udev/rules.d/73-special-net-names.rules 文件,加入如下配置:
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="<MAC Address>", NAME="<New Interface Name>"
参数说明:
ATTR{address}==”<MAC Address>”中的<MAC Address>为 MAC 地址,根据自己的网卡进行修改;
NAME=”<New Interface Name>”中的<New Interface Name>为要使用的新命名;
如果 73-special-net-names.rules 文件不存在,创建即可,或者写入其他配置文件也可以;
通过 udev 服务,来配置固定接口名称:
# /etc/udev/rules.d/10-network.rules SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="aa:bb:cc:dd:ee:ff", NAME="net1" SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="ff:ee:dd:cc:bb:aa", NAME="net0"
方法三、使用「可预测网卡接口名」
在 Debian 中,可以修改/etc/default/grub文件中的GRUB_CMDLINE_LINUX_DEFAULT参数,加入net.ifnames=1配置,然后执行update-grub2命令,重启系统;
附加说明
注意:如果修改修改了网卡接口名,不要忘记更新相关的配置文件;
参考文献
Change Network Interface Name: eth0,eth1,eth2+
Arch/Network Configuration
Rename a Linux network interface without Udev/Reboot
Network naming on Arch Linux
How to enable “Predictable Network Interface Names”?