CentOS7和CentOS6修改网卡名称

0. 目标

将网卡的名称从ens33改成eth0。

1. 修改网卡配置文件

# 将网卡配置文件的文件名改成修改后的网卡名相关格式
[root@byte-edu-lab2 ~]# mv /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-eth0

# 修改网卡配置文件内容
# 其中与修改网卡名相关的项是NAME=eth0和DEVICE=eth0
[root@byte-edu-lab2 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

TYPE=Ethernet
#PROXY_METHOD=none
#BROWSER_ONLY=no
#BOOTPROTO=dhcp
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
#IPV6INIT=yes
#IPV6_AUTOCONF=yes
#IPV6_DEFROUTE=yes
#IPV6_FAILURE_FATAL=no
#IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth0
UUID=5f946246-3bd9-4242-bd74-fc33455cd7f1
DEVICE=eth0
ONBOOT=yes

#set static IP
IPADDR=192.168.245.130
PREFIX=24
GATEWAY=192.168.245.2

2. 修改内核配置文件

# 首先查看网卡的MAC地址
# 可知笔者MAC地址为00:0c:29:ab:d9:72
[root@byte-edu-lab2 ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.245.130  netmask 255.255.255.0  broadcast 192.168.245.255
        inet6 fe80::20c:29ff:feab:d972  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:ab:d9:72  txqueuelen 1000  (Ethernet)
        RX packets 11631  bytes 15042914 (14.3 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2571  bytes 201538 (196.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

# 修改内核配置文件,将ATTR{address}的值改为自己的MAC地址
[root@byte-edu-lab2 ~]# vim /usr/lib/udev/rules.d/60-net.rules

ACTION=="add", SUBSYSTEM=="net", DRIVERS=="?*", ATTR{type}=="1", ATTR{address}=="00:0c:29:ab:d9:72", NAME="eth0"

注意CentOS7中网卡驱动读取的配置文件是/usr/lib/udev/rules.d/60-net.rules;CentOS6中则为/etc/udev/rules.d/70-persistent-net.rules

3. 重新加载并重启

[root@byte-edu-lab2 ~]# modprobe -r e1000 ;modprobe e1000;systemctl restart network

4. 查看结果

[root@byte-edu-lab2 ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.245.130  netmask 255.255.255.0  broadcast 192.168.245.255
        inet6 fe80::20c:29ff:feab:d972  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:ab:d9:72  txqueuelen 1000  (Ethernet)
        RX packets 105  bytes 12583 (12.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 93  bytes 16942 (16.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

可看到网卡名称已从ens33改成了eth0。

一次修改两个网卡名称的步骤:
https://blog.51cto.com/u_13055758/2063012

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值