linux 修改网卡名称

RHEL6系统

例如将eth0修改为Mg0

1.查看要修改的网卡的MAC地址

1
[root@localhost ~]#ifconfig

2.重命名网卡配置文件

1
2
[root@localhost ~]# cd /etc/sysconfig/network-scripts/     
[root@localhost network-scripts]# mv ifcfg-eth0 ifcfg-Mg0

3.修改网卡配置文件

1
2
3
4
5
6
7
[root@localhost network-scripts]# vim ifcfg-Mg0
BOOTPROTO=static
DEVICE=Mg0    //修改为Mg0
ONBOOT=yes
IPADDR=192.168.10.10
NETMASK=255.255.255.0
GATEWAY=192.168.10.254

4.修改70-persistent-net.rules配置文件

1
 
1
2
[root@localhost network-scripts]#vim /etc/udev/rules.d/70-persistent-net.rules
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:d3:a7:23", ATTR{type}=="1", KERNEL=="eth*", NAME="Mg0"

//修改与ifconfig对应MAC地址的网卡名称

5.重启系统进行验证

RHEL7/8系统

例如将网卡名称修改为ethX形式

方法1:直接修改

1.备份、重命名网卡配置文件

1
2
3
4
5
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-ens160 ifcfg-ens160.bak      
[root@localhost network-scripts]# mv ifcfg-ens160 ifcfg-eth0            
[root@localhost network-scripts]# ls
ifcfg-ens160.back  ifcfg-eth0

2.修改网卡配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@localhost network-scripts]# vim ifcfg-eth0
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
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    //修改为eth0
UUID=26300929-38a2-4ea5-b68d-3148a997e8fe
DEVICE=eth0    //修改为eth0
ONBOOT=yes
IPADDR=192.168.10.10
PREFIX=24
HWADDR=1B:6C:7N:BC:8D:1M  //添加网卡的MAC地址

3.重启机器

1
[root@localhost network-scripts]#reboot

 

方法2:当方法1不行时,可以尝试使用该方法

1.备份、重命名网卡配置文件

1
2
3
4
5
6
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-ens160 ifcfg-ens160.bak      
[root@localhost network-scripts]# <strong>mv ifcfg-ens160 ifcfg-eth0</strong>            
[root@localhost network-scripts]# ls
ifcfg-ens160.back  <strong>ifcfg-eth0
</strong>

2.修改网卡配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[root@localhost network-scripts]# vim ifcfg-eth0
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
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    //修改为eth0
UUID=26300929-38a2-4ea5-b68d-3148a997e8fe
DEVICE=eth0    //修改为eth0
ONBOOT=yes
IPADDR=192.168.10.10
PREFIX=24

3.禁用网卡命名规则(添加"net.ifnames=0 biosdevname=0"参数)

1
2
3
4
5
6
7
[root@localhost network-scripts]# vim /etc/default/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="resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet <strong>net.ifnames=0 biosdevname=0</strong>" //加入两个参数 <br>GRUB_DISABLE_RECOVERY="true" GRUB_ENABLE_BLSCFG=true

4.添加udev网卡规则

1
2
3
[root@localhost network-scripts]#cd /etc/udev/rules.d/
[root@localhost rules.d]#vim 70-persistent-net.rules
SUBSYSTEM==”net”,ACTION==”add”,DRIVERS==”?*”,ATTR{address}==”<strong>需要修改名称的网卡MAC地址</strong>”,ATTR{type}==”1″ ,KERNEL==”eth*”,NAME=”<strong>eth0</strong>″

5.更新grub配置(grub2-mkconfig -o /boot/grub2/grub.cfg)

1
[root@localhost network-scripts]#grub2-mkconfig -o /boot/grub2/grub.cfg

6.重启服务、重启主机 

1
[root@localhost network-scripts]#reboot

  

posted @   小蟋帅  阅读(2918)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下
点击右上角即可分享
微信分享提示