centos 7.9修改网卡名

文档课题:centos 7.9修改网卡名.
1、系统检查
[root@liujun ~]# cat /etc/*release
CentOS Linux release 7.9.2009 (Core)
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

CentOS Linux release 7.9.2009 (Core)
CentOS Linux release 7.9.2009 (Core)
[root@liujun ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.133.120 netmask 255.255.255.0 broadcast 192.168.133.255
inet6 fe80::8859:131d:a761:bc7a prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:98:c5:5f txqueuelen 1000 (Ethernet)
RX packets 134 bytes 29118 (28.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 136 bytes 21093 (20.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 48 bytes 4080 (3.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 48 bytes 4080 (3.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:a8:7c:6f txqueuelen 1000 (Ethernet)
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
2、修改网卡名
2.1、grub文件
--编辑/etc/default/grub,加入“net.ifnames=0 biosdevname=0”到GRUB_CMDLINE_LINUX变量.
[root@liujun ~]# cat /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="crashkernel=auto spectre_v2=retpoline rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
[root@liujun ~]# sed -i 's/rhgb/net.ifnames=0 biosdevname=0 rhgb/' /etc/default/grub
2.2、70-persistent-net.rules文件
修改/etc/udev/rules.d/70-persistent-net.rules文件
--查接口mac地址。
[root@liujun ~]# ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
link/ether 00:0c:29:98:c5:5f brd ff:ff:ff:ff:ff:ff
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default qlen 1000
link/ether 52:54:00:a8:7c:6f brd ff:ff:ff:ff:ff:ff
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN mode DEFAULT group default qlen 1000
link/ether 52:54:00:a8:7c:6f brd ff:ff:ff:ff:ff:ff
--MAC地址为00:0c:29:98:c5:5f,将MAC地址填入文件70-persistent-net.rules的ATTR中。
[root@liujun rules.d]# vi /etc/udev/rules.d/70-persistent-net.rules
添加如下:
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:98:c5:5f", ATTR{type}=="1", KERNEL=="ens*", NAME="ens37"
说明:需注意ATTR和NAME值。
2.3、ifcfg-ens33文件
--修改网卡配置文件
[root@liujun network-scripts]# pwd
/etc/sysconfig/network-scripts
[root@liujun network-scripts]# mv ifcfg-ens33 ifcfg-ens37
[root@liujun network-scripts]# vi ifcfg-ens37
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
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=ens37
UUID=e7191296-fd65-478d-936e-f43dc98f1745
DEVICE=ens37
ONBOOT=yes
IPADDR=192.168.133.120
DNS1=192.168.133.2
GATEWAY=192.168.133.2
PREFIX=24
说明:需修改DEVICE和NAME的名称为ens37.
3、重启系统
[root@liujun network-scripts]# reboot
[root@liujun ~]# ifconfig
ens37: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.133.120 netmask 255.255.255.0 broadcast 192.168.133.255
inet6 fe80::e007:4abd:58d:5da3 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:98:c5:5f txqueuelen 1000 (Ethernet)
RX packets 35 bytes 5261 (5.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 58 bytes 10265 (10.0 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 48 bytes 4080 (3.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 48 bytes 4080 (3.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:a8:7c:6f txqueuelen 1000 (Ethernet)
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

参考网址:http://blog.itpub.net/26736162/viewspace-2771463/