Skip to content

CentOS 7 更改网卡名 #47

Open
Open
@johnnian

Description

@johnnian

安装CentOS 7后,默认的网卡名字不是 「eth0」,由于在安装阿里云的Logtail客户端,其默认读取 「eth0」网卡的IP地址,因此需要更改下网卡名。

设置步骤

下面的具体步骤:(假设网卡名字是:eth123456)

步骤1: 配置创建并配置 ifcfg-eth0 文件

[root@localhost ~]# ifconfig
eth123456: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1280
        inet 192.168.0.102  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::77a1:9964:3a77:8ab9  prefixlen 64  scopeid 0x20<link>
        ether d8:9e:f3:10:7a:11  txqueuelen 1000  (Ethernet)
        RX packets 34180  bytes 4149267 (3.9 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 32703  bytes 20801400 (19.8 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 16  memory 0xf7e80000-f7ea0000

[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# mv ifcfg-eth123456 ifcfg-eth0
[root@localhost network-scripts]# vi ifcfg-eth0
#修改下面两个Key
NAME="eth0"
DEVICE="eth0"

步骤2: 修改grub配置并更新内核参数

#修改配置
[root@localhost ~]# vi /etc/sysconfig/grub
#修改这个Key:增加 net.ifnames=0 biosdevname=0
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root net.ifnames=0 biosdevname=0 rd.lvm.lv=centos/swap rhgb quiet"

#更新内核参数
[root@localhost ~]# grub2-mkconfig -o /boot/grub2/grub.cfg

步骤3: 添加udev的规则

[root@localhost ~]# vi /usr/lib/udev/rules.d/60-net.rules
#将第一行注释掉
#ACTION=="add", SUBSYSTEM=="net", DRIVERS=="?*", ATTR{type}=="1", PROGRAM="/lib/udev/rename_device", RESULT=="?*", NAME="$result"
ACTION=="add", SUBSYSTEM=="net", DRIVERS=="?*", ATTR{type}=="1", ATTR{address}=="d8:9e:*:10:*11", NAME="eth0"

配置完成之后,重启服务器即可。

备注:

  • ATTR{address}=="网卡Mac地址"(可以通过 ifconfig命令查看 )
  • NAME="新网卡名字"

参考链接

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions