跳到主要内容

配置有线网卡改名 eth0

在安装 debian-12.9.0 后,第一次开机时,网卡名称可能类似于 enP3p49s0,这种命名方式不易于操作。可以通过以下步骤将网卡名称改为 eth0

注意: GRUB 配置仅用于 X86 设备


查看当前网卡名称

使用以下命令查看当前网卡名称:

root@Debian:~$ ip addr 
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000

2: enP3p49s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000

修改 GRUB 配置

  1. 编辑 GRUB 配置文件:

    vim /etc/default/grub
  2. GRUB_CMDLINE_LINUX 中添加 net.ifnames=0 biosdevname=0:

    GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"

修改网卡配置文件

编辑网卡配置文件 vim /etc/network/interfaces,配置动态或静态 IP。

动态 IP 配置

auto eth0
allow-hotplug eth0
iface eth0 inet dhcp
iface eth0 inet6 auto

静态 IP 配置(多网卡可添加 eth1、eth2 等)

allow-hotplug eth1
iface eth1 inet static
address 192.168.1.2
gateway 192.168.1.1
netmask 255.255.255.0
dns-nameservers 192.168.1.1

应用配置并重启

执行以下命令使配置生效:

grub-mkconfig -o /boot/grub/grub.cfg
update-grub
reboot

验证配置

重启后,使用以下命令验证网卡名称是否已改为 eth0:

root@Debian:~$ ip addr 
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000

现在可以愉快地使用了!