Linux-C7系统网卡名字

Linux修改网卡名字

第一步:先ifconfig查看网卡

[root@192.168.20.10 ~]# ifconfig
docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:43:05:65:d4  txqueuelen 0  (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

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.20.10  netmask 255.255.255.0  broadcast 192.168.20.255
        inet6 fe80::20c:29ff:fed7:7508  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:d7:75:08  txqueuelen 1000  (Ethernet)
        RX packets 60  bytes 6922 (6.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 66  bytes 8883 (8.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

第二步:编辑网卡配置更改名字

[root@192.168.20.10 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
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=eth0					#更改这里
UUID=aacfab22-2ec5-4dc6-b378-8011c3a46922
DEVICE=eth0					#更改这里
ONBOOT=yes
IPADDR=192.168.20.10
PREFIX=24
GATEWAY=192.168.20.2
DNS1=223.5.5.5

第三步:修改网卡的名字

[root@192.168.20.10 /etc/sysconfig/network-scripts]# mv ifcfg-ens34 ifcfg-eth0

第四步:修改系统启动项文件

#net.ifnames=0 biosdevname=0
[root@192.168.20.10 ~]# cat > /etc/default/grub<<'EOF'
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="spectre_v2=retpoline rd.lvm.lv=centos/root rd.lvm.lv=centos/swap net.ifnames=0 biosdevname=0 net.ifnames=0 biosdevname=0 rhgb quiet net.ifnames=0  biosdevname=0"
GRUB_DISABLE_RECOVERY="true"
EOF

增加这个

第五步:生成改动的参数

[root@192.168.20.10 ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-1160.76.1.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1160.76.1.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-1160.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1160.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-3ed4b92f396c464cb7a0e89dff242268
Found initrd image: /boot/initramfs-0-rescue-3ed4b92f396c464cb7a0e89dff242268.img
done

运行过程

第六步:重启

[root@192.168.20.10 ~]# reboot

第七步:查看是否生成

[root@192.168.20.10 ~]# ifconfig
docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:43:05:65:d4  txqueuelen 0  (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

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.20.10  netmask 255.255.255.0  broadcast 192.168.20.255
        inet6 fe80::20c:29ff:fed7:7508  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:d7:75:08  txqueuelen 1000  (Ethernet)
        RX packets 414  bytes 34001 (33.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 285  bytes 46731 (45.6 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
posted @ 2022-10-08 18:37  YIDADA-SRE  阅读(88)  评论(0编辑  收藏  举报