CentOS 7.2更改网卡名称

背景

没啥背景,就是VMWare装的CentOS虚拟机的自带网卡名有点乱,想重新定义一下。

环境

1、VMWare虚拟机

6张网卡

2、系统

[[email protected] ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)

并且是最小化安装。

网卡信息

网卡配置文件

配置内容

[[email protected] network-scripts]# cat ifcfg-eno16777736
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777736
UUID=1160a71e-e5b5-4378-b742-c1bf0cba6f00
DEVICE=eno16777736
ONBOOT=no

这里启动下网卡,获得IP,好连接shell

[[email protected] network-scripts]# sed -i ‘/ONBOOT/s/no/yes/‘ ifcfg-eno*
[[email protected] network-scripts]# systemctl restart network
[[email protected] network-scripts]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    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: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:5c brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.128/24 brd 192.168.140.255 scope global dynamic eno16777736
       valid_lft 1799sec preferred_lft 1799sec
    inet6 fe80::20c:29ff:fea3:b15c/64 scope link
       valid_lft forever preferred_lft forever
3: eno33554960: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:66 brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.129/24 brd 192.168.140.255 scope global dynamic eno33554960
       valid_lft 1800sec preferred_lft 1800sec
    inet6 fe80::20c:29ff:fea3:b166/64 scope link
       valid_lft forever preferred_lft forever
4: eno50332184: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:70 brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.130/24 brd 192.168.140.255 scope global dynamic eno50332184
       valid_lft 1800sec preferred_lft 1800sec
    inet6 fe80::20c:29ff:fea3:b170/64 scope link
       valid_lft forever preferred_lft forever
5: eno67109408: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:7a brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.131/24 brd 192.168.140.255 scope global dynamic eno67109408
       valid_lft 1800sec preferred_lft 1800sec
    inet6 fe80::20c:29ff:fea3:b17a/64 scope link
       valid_lft forever preferred_lft forever
6: eno83886632: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:84 brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.132/24 brd 192.168.140.255 scope global dynamic eno83886632
       valid_lft 1800sec preferred_lft 1800sec
    inet6 fe80::20c:29ff:fea3:b184/64 scope link
       valid_lft forever preferred_lft forever
7: eno100663856: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:8e brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.133/24 brd 192.168.140.255 scope global dynamic eno100663856
       valid_lft 1801sec preferred_lft 1801sec
    inet6 fe80::20c:29ff:fea3:b18e/64 scope link
       valid_lft forever preferred_lft forever
[[email protected] network-scripts]# 

默认使用DHCP,都是自动获取的IP

配置

CentOS7使用了“一致性网络命名方法”,这里举例,将网卡名截断为前5个字符,如eno16777736改为eno16。

1、更改网卡配置文件名

[[email protected] network-scripts]# ll
total 252
-rw-r--r--. 1 root root   290 Jan 11 22:41 ifcfg-eno10
-rw-r--r--. 1 root root   288 Jan 11 22:41 ifcfg-eno16
-rw-r--r--. 1 root root   288 Jan 11 22:41 ifcfg-eno33
-rw-r--r--. 1 root root   288 Jan 11 22:41 ifcfg-eno50
-rw-r--r--. 1 root root   288 Jan 11 22:41 ifcfg-eno67
-rw-r--r--. 1 root root   288 Jan 11 22:41 ifcfg-eno83
-rw-r--r--. 1 root root   254 Sep 16  2015 ifcfg-lo
lrwxrwxrwx. 1 root root    24 Jan 11 22:31 ifdown -> ../../../usr/sbin/ifdown
-rwxr-xr-x. 1 root root   627 Sep 16  2015 ifdown-bnep
[[email protected] network-scripts]# 

并更改配置文件内容,举例

[[email protected] network-scripts]# cat ifcfg-eno16
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eno16
UUID=803d2d05-493b-489b-8201-1d3fc67878aa
DEVICE=eno16
ONBOOT=yes
[[email protected] network-scripts]# 

2、关闭“一致性网络设备命名法”

更改前

[[email protected] ~]# 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 rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
[[email protected] ~]# 

添加net.ifnames=0 biosdevname=0

更改后

[[email protected] ~]# 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 rd.lvm.lv=centos/root rd.lvm.lv=centos/swap net.ifnames=0 biosdevname=0 rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
[[email protected] ~]# 

更新GRUB、内核配置

[[email protected] ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-327.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-327.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-f034e6e19df748b7a27fad77b06e3179
Found initrd image: /boot/initramfs-0-rescue-f034e6e19df748b7a27fad77b06e3179.img
done
[[email protected] ~]# 

3、添加设备规则配置文件

修改/etc/udev/rules.d/70-persistent-net.rules,没有该文件则新建文件

内容如下

[[email protected] ~]# cat /etc/udev/rules.d/70-persistent-net.rules
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:a3:b1:5c", ATTR{type}=="1", KERNEL=="eth*", NAME="eno16"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:a3:b1:8e", ATTR{type}=="1", KERNEL=="eth*", NAME="eno10"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:a3:b1:66", ATTR{type}=="1", KERNEL=="eth*", NAME="eno33"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:a3:b1:70", ATTR{type}=="1", KERNEL=="eth*", NAME="eno50"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:a3:b1:7a", ATTR{type}=="1", KERNEL=="eth*", NAME="eno67"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:a3:b1:84", ATTR{type}=="1", KERNEL=="eth*", NAME="eno83"
[[email protected] ~]# 

注意MAC地址与NAME相匹配(可以用ip addr查看)

4、重启

[[email protected] ~]# reboot

使用

[[email protected] ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    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: eno16: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:5c brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.128/24 brd 192.168.140.255 scope global dynamic eno16
       valid_lft 1768sec preferred_lft 1768sec
    inet6 fe80::20c:29ff:fea3:b15c/64 scope link
       valid_lft forever preferred_lft forever
3: eno33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:66 brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.129/24 brd 192.168.140.255 scope global dynamic eno33
       valid_lft 1768sec preferred_lft 1768sec
    inet6 fe80::20c:29ff:fea3:b166/64 scope link
       valid_lft forever preferred_lft forever
4: eno50: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:70 brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.130/24 brd 192.168.140.255 scope global dynamic eno50
       valid_lft 1768sec preferred_lft 1768sec
    inet6 fe80::20c:29ff:fea3:b170/64 scope link
       valid_lft forever preferred_lft forever
5: eno67: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:7a brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.131/24 brd 192.168.140.255 scope global dynamic eno67
       valid_lft 1768sec preferred_lft 1768sec
    inet6 fe80::20c:29ff:fea3:b17a/64 scope link
       valid_lft forever preferred_lft forever
6: eno83: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:84 brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.132/24 brd 192.168.140.255 scope global dynamic eno83
       valid_lft 1768sec preferred_lft 1768sec
    inet6 fe80::20c:29ff:fea3:b184/64 scope link
       valid_lft forever preferred_lft forever
7: eno10: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:8e brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.133/24 brd 192.168.140.255 scope global dynamic eno10
       valid_lft 1768sec preferred_lft 1768sec
    inet6 fe80::20c:29ff:fea3:b18e/64 scope link
       valid_lft forever preferred_lft forever
[[email protected] ~]# 

看见网卡名称都已经更改了

再来设置个静态ip,以eno83为例

[[email protected] network-scripts]# cat ifcfg-eno83
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eno83
UUID=919f599a-c262-4868-be7e-0646b1e98dee
DEVICE=eno83
IPADDR=192.168.140.140
PREFIX=24
ONBOOT=yes
[[email protected] network-scripts]# 

重启网络

[[email protected] network-scripts]# systemctl restart network
[[email protected] network-scripts]#
[[email protected] network-scripts]#
[[email protected] network-scripts]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    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: eno16: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:5c brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.128/24 brd 192.168.140.255 scope global dynamic eno16
       valid_lft 1802sec preferred_lft 1802sec
    inet6 fe80::20c:29ff:fea3:b15c/64 scope link
       valid_lft forever preferred_lft forever
3: eno33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:66 brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.129/24 brd 192.168.140.255 scope global dynamic eno33
       valid_lft 1802sec preferred_lft 1802sec
    inet6 fe80::20c:29ff:fea3:b166/64 scope link
       valid_lft forever preferred_lft forever
4: eno50: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:70 brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.130/24 brd 192.168.140.255 scope global dynamic eno50
       valid_lft 1803sec preferred_lft 1803sec
    inet6 fe80::20c:29ff:fea3:b170/64 scope link
       valid_lft forever preferred_lft forever
5: eno67: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:7a brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.131/24 brd 192.168.140.255 scope global dynamic eno67
       valid_lft 1803sec preferred_lft 1803sec
    inet6 fe80::20c:29ff:fea3:b17a/64 scope link
       valid_lft forever preferred_lft forever
6: eno83: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:84 brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.140/24 brd 192.168.140.255 scope global eno83
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fea3:b184/64 scope link
       valid_lft forever preferred_lft forever
7: eno10: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:8e brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.133/24 brd 192.168.140.255 scope global dynamic eno10
       valid_lft 1802sec preferred_lft 1802sec
    inet6 fe80::20c:29ff:fea3:b18e/64 scope link
       valid_lft forever preferred_lft forever
[[email protected] network-scripts]# 

改好了~

ps:

1、如果没有“配置-3添加设备规则配置文件“这步,其他不变,系统重启后将使用eth0、eth1、eth2、...这样的网卡名,此时系统会尝试启动配置文件(eno16等)描述的网卡,但网卡不存在,这些网卡将启动失败,并且开机后无法重启网络,提示failed to start lsb:bring up/down巴拉巴拉~

2、/etc/sysconfig/network-scripts这里目录里的网卡配置文件不要有多余的,每个ifcfg-xxxx对应且仅对应一个网卡,否则容易造成重启网络失败,提示failed to start lsb:bring up/down巴拉巴拉~

3、按这个顺序更改,可以避免更改网卡名称并重启之后,无法重启network的情况。

时间: 2024-10-20 18:41:29

CentOS 7.2更改网卡名称的相关文章

CentOS 6.X如何更改网卡名称

CentOS 6.X下修改网卡名称有三种方法: 法1: 修改UDEV文件,删除里面的内容:用命令,重新定义名字,两个名字都要改: 法2: 在centos6中,可以直接使用setup,设置一块新网卡,填上eth1.ip等内容. 在 CentOS 6 中,默认的 kudzu 这个识别硬件的服务不存在了,基本上所有的硬件管理都通过 Udev 来管理了. 如果在 Centos 6 中加了一个新的硬件,如网卡只需要重新启动 udev 就行了. start_udev 它会重新扫描新加的硬件并做相关的处理.

CentOS 7更改网卡名称

1.更改网卡配置文件ifcfg-enoxxxxxx里的NAME选项 vim /etc/sysconfig/network-scripts/ifcfg-enoxxxxxx NAME=eth0 2.更改网卡配置文件名称     cd /etc/sysconfig/network-scripts/ mv ifcfg-enoxxxxxx ifcfg-eth0 3.禁用该可预测命名规则,通过编辑/etc/default/grub并加入"net.ifnames=0 biosdevname=0 "

CentOS7更改网卡名称

废话不多说,直接上干货 1.更改NAME DEVICE项为etho,如果有多块网卡需要改为eth1.... vim /etc/sysconfig/network-scripts/ifcfg-eno16777736 NAME=eth0 DEVICE=eth0 2.重新命名网卡名称 cd /etc/sysconfig/network-scripts/ mv ifcfg-eno16777736 ifcfg-eth0 如果有第二块网卡需要改为eth1 3.编辑配置文件/etc/default/grub

如何修改CentOS 7.6的网卡名称

1. 背景介绍 在centos5的时候,我们习惯了eth0这样的网络设备命名,在centos6发现网络设备变成了em1这样的命名,到了CentOS 7版本对网卡的命名规则又进行了重新定义,因此,对于这个命名规则的修改,还是让很多人比较头疼,无法适应这种随机生成的网卡名称,下面就教大家如何将网卡固定修改为eth0,操作步骤也很简单: 2. 修改方法 进入到/etc/sysconfig/network-scripts/目录下,备份网卡文件 [[email protected] ~]# cd /etc

CentOS 7.2修改网卡名称

#!/bin/bash #Centos7.2修改网卡名称ens33为eth0 #2017/05/19 if [ -f /etc/sysconfig/grub ];then cp /etc/sysconfig/grub ./grub.conf sed -i '/GRUB_CMDLINE_LINUX/s/"$/ net.ifnames=0 biosdevname=0&/' ./grub.conf cat grub.conf > /etc/sysconfig/grub rm -f gru

Centos7更改网卡名称Eth0

安装完Centos7系统,网卡命名跟之前发生了变化,例如! 就是看着不爽也不会影响使用,只是个网卡名称而已. eno16777736 1. 先编辑网卡的配置文件将里面的NAME DEVICE项修改为eth0 vim /etc/sysconfig/network-scripts/ifcfg-eno16777736 2. 重命名该配置文件. [[email protected] yum.repos.d]#  cd /etc/sysconfig/network-scripts/[[email prot

Linux 7更改网卡名称

1,vim /etc/sysconfig/grub 在quiet后面添加 net.ifname=0 biosdevname=0 保存退出2 ,执行命令 grub2-mkconfig -o /boot/grub2/grub.cfg,生成新的grub.cfg文件3,重命名网卡 vim /etc/sysconfig/network-script/ifcfg-ens33 更改dev等参数名字更改配置文件名字4,重启服务器,验证更改是否成功 ifconfig 原文地址:http://blog.51cto.

CentOS7 更改网卡名称

1.ifconfig查看网卡名称为ens33 [[email protected] ~]# ifconfig ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.137.2 netmask 255.255.255.0 broadcast 192.168.137.255 inet6 fe80::20c:29ff:fe8b:bbbe prefixlen 64 scopeid 0x20<link>

RedHat/CentOS 7如何更改网卡名为eth0 eth1......

[root@localhost ~]# vi /etc/sysconfig/grubGRUB_TIMEOUT=5GRUB_DEFAULT=savedGRUB_DISABLE_SUBMENU=trueGRUB_TERMINAL_OUTPUT="console"GRUB_CMDLINE_LINUX="rd.lvm.lv=rhel/swap crashkernel=auto rd.lvm.lv=rhel/root rhgb quiet net.ifnames=0 biosdevna