Centos7 修改网卡为eth0

摘要

默认centos7安装不设置内核版本,会影响网卡的名称。所以为了我们统一管理我们需要将网卡名称修改为eth开头

Centos7 修改网卡为eth0

Linux

默认centos7安装不设置内核版本,会影响网卡的名称。所以为了我们统一管理我们需要将网卡名称修改为eth开头


第一步查看服务器版本

  1. [root@localhost ~]# cat /etc/redhat-release
  2. CentOS Linux release 7.6.1810 (Core)

第二步查看当前网卡名称

我们可以看到当前网卡名称都是en0开头的,不方便我们集中管理

  1. [root@localhost ~]# ip a
  2. 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
  3. link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  4. inet 127.0.0.1/8 scope host lo
  5. valid_lft forever preferred_lft forever
  6. inet6 ::1/128 scope host
  7. valid_lft forever preferred_lft forever
  8. 2: eno1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000
  9. link/ether f4:1d:6b:86:8a:09 brd ff:ff:ff:ff:ff:ff
  10. 3: eno2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000
  11. link/ether f4:1d:6b:86:8a:0a brd ff:ff:ff:ff:ff:ff
  12. 4: eno3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
  13. link/ether f4:1d:6b:86:8a:0b brd ff:ff:ff:ff:ff:ff
  14. inet 10.4.81.93/24 brd 10.4.81.255 scope global noprefixroute eno3
  15. valid_lft forever preferred_lft forever
  16. inet6 fe80::687f:25f8:b435:887b/64 scope link noprefixroute
  17. valid_lft forever preferred_lft forever
  18. 5: eno4: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000
  19. link/ether f4:1d:6b:86:8a:0c brd ff:ff:ff:ff:ff:ff

第三步进入网卡配置文件

将所有的文件mv 更换名称

  1. [root@localhost ~]# cd /etc/sysconfig/network-scripts/
  2. [root@localhost network-scripts]# ls
  3. ifcfg-eno1 ifcfg-lo ifdown-ippp ifdown-ppp ifdown-TeamPort ifup-bnep ifup-isdn ifup-ppp ifup-TeamPort network-functions
  4. ifcfg-eno2 ifdown ifdown-ipv6 ifdown-routes ifdown-tunnel ifup-eth ifup-plip ifup-routes ifup-tunnel network-functions-ipv6
  5. ifcfg-eno3 ifdown-bnep ifdown-isdn ifdown-sit ifup ifup-ippp ifup-plusb ifup-sit ifup-wireless
  6. ifcfg-eno4 ifdown-eth ifdown-post ifdown-Team ifup-aliases ifup-ipv6 ifup-post ifup-Team init.ipv6-global
  7. [root@localhost network-scripts]#
  8. [root@localhost network-scripts]# mv ifcfg-eno1 ifcfg-eth0
  9. [root@localhost network-scripts]# mv ifcfg-eno2 ifcfg-eth1
  10. [root@localhost network-scripts]# mv ifcfg-eno3 ifcfg-eth2
  11. [root@localhost network-scripts]# mv ifcfg-eno4 ifcfg-eth3

第四步修改网卡信息

需要修改的主要几点
1.NAME
2.DEVICE
3.BOOTPROTO [dhcp or static or none]none和static需要在输入ip地址
4.添加HWADDR 默认网卡没有mac地址,需要添加mac地址

image_1d973tk0r17k91o41brp1ee11qjap.png-132.5kB

第五步修改内核参数

  1. [root@localhost network-scripts]# vi /etc/sysconfig/grub

在倒数第二行quiet前面添加net.ifnames=0 biosdevname=0
image_1d973vcu41cpv15241h7l3ju1p2k16.png-85.7kB

我们还可以在装系统的时候配置
光标移动到Install CentOS上,按tab键 输入net.ifnames=0 biosdevname=0 回车
image_1d97aftiu14lmkqh6pb11b6fad1j.png-21.2kB

第六步生成启动菜单

  1. [root@localhost network-scripts]# grub2-mkconfig -o /boot/grub2/grub.cfg
  2. Generating grub configuration file ...
  3. Found linux image: /boot/vmlinuz-3.10.0-957.el7.x86_64
  4. Found initrd image: /boot/initramfs-3.10.0-957.el7.x86_64.img
  5. Found linux image: /boot/vmlinuz-0-rescue-f9f84382fb844c0a84e9ee9b2a2906b5
  6. Found initrd image: /boot/initramfs-0-rescue-f9f84382fb844c0a84e9ee9b2a2906b5.img
  7. done

第七步验证是否修改成功

  1. [root@localhost ~]# reboot #重启生效
  2. centos7默认不支持ifconfig,如果需要ifconfigyum install net-t

修改完毕!
8DBD4A93-15BF-4F34-B5D8-E9908CE368E0.png-568.3kB
83092637-F388-4307-9682-2F0DFF534624.png-406.4kB


新闻联播老司机

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: