Ubuntu20 修改网卡名称

Ubuntu 修改网卡名称

Ubuntu修改网卡名称

  1. Ubuntu 版本: Ubuntu 20.04

  2. 查看当前网卡名称

root@it:~# ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:2d:79:40 brd ff:ff:ff:ff:ff:ff
    inet 192.168.121.21/24 brd 192.168.121.255 scope global ens32
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe2d:7940/64 scope link 
       valid_lft forever preferred_lft forever
  1. /etc/default/grub 文件中编辑
  • GRUB_CMDLINE_LINUX 引号中添加参数 net.ifnames=0 biosdevname=0

Ubuntu20 修改网卡名称

4、修改完后执行命令 update-grub

root@it:~# update-grub
Sourcing file `/etc/default/grub‘
Sourcing file `/etc/default/grub.d/init-select.cfg‘
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.4.0-62-generic
Found initrd image: /boot/initrd.img-5.4.0-62-generic
done

5、在 /etc/netplan/00-installer-config.yaml 文件中修改网卡名为传统名称 eth0

  • 注意:如果是Ubuntu 16或一下版本,则是在 /etc/network/interfaces 文件中修改
root@it:~# sed -i "s/ens32/eth0/" /etc/netplan/00-installer-config.yaml
root@it:~# cat /etc/netplan/00-installer-config.yaml 
# This is the network config written by ‘subiquity‘
network:
  ethernets:
    eth0:
      addresses:
      - 192.168.121.21/24
      gateway4: 192.168.121.2
      nameservers:
        addresses:
        - 8.8.8.8
  version: 2
  1. 重启
root@it:~# reboot

重启后,查看网卡名称

it@it:~$ ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:2d:79:40 brd ff:ff:ff:ff:ff:ff
    inet 192.168.121.21/24 brd 192.168.121.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe2d:7940/64 scope link 
       valid_lft forever preferred_lft forever
  • OK,修改成功

Ubuntu20 修改网卡名称

上一篇:Linux——端口命令


下一篇:Linux设置静态IP地址