1. 背景介绍

在centos5的时候,我们习惯了eth0这样的网络设备命名,在centos6发现网络设备变成了em1这样的命名,到了CentOS 7版本对网卡的命名规则又进行了重新定义,因此,对于这个命名规则的修改,还是让很多人比较头疼,无法适应这种随机生成的网卡名称,下面就教大家如何将网卡固定修改为eth0,操作步骤也很简单;

2. 修改方法

  1. 进入到/etc/sysconfig/network-scripts/目录下,备份网卡文件
    [root@192168088102-NFS-Server ~]# cd /etc/sysconfig/network-scripts/
    [root@192168088102-NFS-Server network-scripts]# ls
    ifcfg-ens33  ifdown-bnep  ifdown-ipv6  ifdown-ppp     ifdown-Team      ifup          ifup-eth   ifup-isdn   ifup-post    ifup-sit       ifup-tunnel       network-functions
    ifcfg-lo     ifdown-eth   ifdown-isdn  ifdown-routes  ifdown-TeamPort  ifup-aliases  ifup-ippp  ifup-plip   ifup-ppp     ifup-Team      ifup-wireless     network-functions-ipv6
    ifdown       ifdown-ippp  ifdown-post  ifdown-sit     ifdown-tunnel    ifup-bnep     ifup-ipv6  ifup-plusb  ifup-routes  ifup-TeamPort  init.ipv6-global
    [root@192168088102-NFS-Server network-scripts]# cp ifcfg-ens33 ifcfg-ens33.bak
    [root@192168088102-NFS-Server network-scripts]# ll ifcfg-ens33*
    -rw-r--r--. 1 root root 347 Jul 27 11:41 ifcfg-ens33
    -rw-r--r--. 1 root root 347 Jul 27 12:48 ifcfg-ens33.bak
  2. 将网卡文件名称改为ifcfg-eth0,并修改网卡配置文件
    [root@192168088102-NFS-Server network-scripts]# mv ifcfg-ens33 ifcfg-eth0
    [root@192168088102-NFS-Server network-scripts]# ll ifcfg-eth0
    -rw-r--r--. 1 root root 347 Jul 27 11:41 ifcfg-eth0
    [root@192168088102-NFS-Server network-scripts]# cat ifcfg-eth0
    TYPE=Ethernet
    PROXY_METHOD=none
    BROWSER_ONLY=no
    BOOTPROTO=static
    DEFROUTE=yes
    IPV4_FAILURE_FATAL=no
    #将ens33改为eth0
    NAME=eth0
    UUID=7615d0b6-d6c2-46bf-9140-45083e4aed4b
    #将ens33改为eth0
    DEVICE=eth0
    ONBOOT=yes
    IPADDR=192.168.88.102
    NETMASK=255.255.255.0
    GATEWAY=192.168.88.2
  3. 修改grub文件,添加内核参数net.ifnames=0 biosdevname=0信息,使网卡名称修改为eth0
    [root@192168088102-NFS-Server network-scripts]# cat /etc/sysconfig/grub
    GRUB_TIMEOUT=5
    GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
    GRUB_DEFAULT=saved
    GRUB_DISABLE_SUBMENU=true
    GRUB_TERMINAL_OUTPUT="console"
    GRUB_CMDLINE_LINUX="crashkernel=auto rhgb net.ifnames=0 biosdevname=0 quiet"
    GRUB_DISABLE_RECOVERY="true"
  4. 生成启动菜单,重新加载到启动中,并重启系统
    [root@192168088102-NFS-Server network-scripts]# grub2-mkconfig -o /boot/grub2/grub.cfg
    Generating grub configuration file ...
    Found linux image: /boot/vmlinuz-3.10.0-957.el7.x86_64
    Found initrd image: /boot/initramfs-3.10.0-957.el7.x86_64.img
    Found linux image: /boot/vmlinuz-0-rescue-dc723d2d2d444cf0ae3794ab211366b8
    Found initrd image: /boot/initramfs-0-rescue-dc723d2d2d444cf0ae3794ab211366b8.img
    done
    [root@192168088102-NFS-Server network-scripts]# reboot
  5. 验证网卡是否成功修改为eth0
    [root@192168088102-NFS-Server ~]# ip addr
    1: lo:  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:  mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:b6:52:ed brd ff:ff:ff:ff:ff:ff
    inet 192.168.88.102/24 brd 192.168.88.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:feb6:52ed/64 scope link
       valid_lft forever preferred_lft forever