Change the NIC name of a Linux system

Time:2022-8-5

1. Rename the name of the network card configuration file to eth0 (it can also be changed to other names)

[[email protected] ~]# ifconfig
ens33: flags=4163 mtu 1500

    inet 192.168.10.11  netmask 255.255.255.0  broadcast 192.168.10.255
    inet6 fe80::250:56ff:fe29:eae  prefixlen 64  scopeid 0x20
    ether 00:50:56:29:0e:ae  txqueuelen 1000  (Ethernet)
    RX packets 132  bytes 14492 (14.1 KiB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 115  bytes 13105 (12.7 KiB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73 mtu 65536

    inet 127.0.0.1  netmask 255.0.0.0
    inet6 ::1  prefixlen 128  scopeid 0x10 loop  txqueuelen 1000  (Local Loopback)
    RX packets 140  bytes 11204 (10.9 KiB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 140  bytes 11204 (10.9 KiB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[[email protected] ~]#
[[email protected] ~]# cd /etc/sysconfig/network-scripts/
[[email protected] network-scripts]# ls
ifcfg-ens33 ifdown-ppp ifup-eth ifup-sit
ifcfg-lo ifdown-routes ifup-ippp ifup-Team
ifdown ifdown-sit ifup-ipv6 ifup-TeamPort
ifdown-bnep ifdown-Team ifup-isdn ifup-tunnel
ifdown-eth ifdown-TeamPort ifup-plip ifup-wireless
ifdown-ippp ifdown-tunnel ifup-plusb init.ipv6-global
ifdown-ipv6 ifup ifup-post network-functions
ifdown-isdn ifup-aliases ifup-ppp network-functions-ipv6
ifdown-post ifup-bnep ifup-routes
[[email protected] network-scripts]# mv ifcfg-ens33 ifcfg-eth0
[[email protected] network-scripts]# vim ifcfg-eth0
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=192.168.10.11
GATEWAY=192.168.10.2
NETMASK=255.255.255.0

2. Disable NIC naming rules

This function passes

/etc/default/grub

file to control, to disable this feature, add in the file

“net.ifnames=0 biosdevname=0”

Just

[[email protected] 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=”crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap
rhgb quiet net.ifnames=0 biosdevname=0″
GRUB_DISABLE_RECOVERY=”true”

3. Add udev network card rules

Create a NIC rule 70-persistent-net.rules file in the /etc/udev/rules.d directory and write the following parameters in the file:

SUBSYSTEM==”net”,ACTION==”add”,DRIVERS==”?",ATTR{address}=="The MAC address of the network card whose name needs to be changed",ATTR{type}=="1" ,KERNEL=="eth“,NAME=”eth0”

Reference configuration:

[[email protected] rules.d]# vim 70-persistent-net.rules
SUBSYSTEM==”net”,ACTION==”add”,DRIVERS==”?*”,ATTR{address}==”00:50:56:29:0e:ae”,
ATTR{type}==”1″ ,KERNEL==”eth*”,NAME=”eth0″

Execute grub2-mkconfig -o /boot/grub2/grub.cfgOrderGenerate update grub configuration parameters

[[email protected] rules.d]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file …
Found linux image: /boot/vmlinuz-3.10.0-957.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-957.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-fe49b659ccb940fa8d260a5897c0b08a
Found initrd image: /boot/initramfs-0-rescue-fe49b659ccb940fa8d260a5897c0b08a.img
done

rebootLinux systemAfter verifying whether the name of the network card is changed successfully

[[email protected] ~]# ifconfig
eth0: flags=4163 mtu 1500

    inet 192.168.10.11  netmask 255.255.255.0  broadcast 192.168.10.255
    inet6 fe80::250:56ff:fe29:eae  prefixlen 64  scopeid 0x20
    ether 00:50:56:29:0e:ae  txqueuelen 1000  (Ethernet)
    RX packets 86  bytes 10889 (10.6 KiB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 95  bytes 10828 (10.5 KiB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73 mtu 65536

    inet 127.0.0.1  netmask 255.0.0.0
    inet6 ::1  prefixlen 128  scopeid 0x10 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 

Summarize

The above is the method to change the NIC name of RHEL7 or CentOS 7. Finally, seeing eth0 indicates that the NIC name has been changed successfully!

Recommended Today

Collection common API

//Collection common API Collection list = new ArrayList<>(); //1. Adding elements successfully returns true regardless of the return value (here refers to list) list.add(“Java”); list.add(“HTML”); list.add(“HTML”); list.add(“Java”); list.add(“wsl”); System.out.println(list); //2. Clear the elements of the collection //list.clear(); //System.out.println(list); //3. Determine whether the collection is empty or not, return true and vice versa System.out.println(list.isEmpty()); //false //4. […]