Getting started with Linux: Change the network interface name on CentOS7

Source: Internet
Author: User

Getting started with Linux: Change the network interface name on CentOS7

Question: On CentOS7, I want to change the assigned network interface name to another name. Is there any proper way to rename the network interface of CentOS or RHEL7?

Traditionally, the network interface of Linux is enumerated as eth [0123...], however, these names do not necessarily match the actual hardware slots, PCI locations, and number of USB interfaces. This introduces an unpredictable naming problem (for example, due to uncertain device detection behavior ), this may lead to different network configuration errors (for example, an interface or firewall bypass is prohibited due to an unintentional interface name ). MAC address-based udev rules are not useful in a virtualized environment. The MAC address here is impermanence like the number of ports.

CentOS/RHEL6 introduces a consistent and predictable method for naming network interfaces for network devices. These features allow you to uniquely identify the name of a network interface to make it easier to locate and differentiate devices. In this way, no matter whether or not the machine is restarted, how long it has elapsed, or the hardware is changed, its name remains unchanged. However, this naming rule is not enabled on CentOS/RHEL6 by default.

From CentOS/RHEL7, this foreseeable naming rule has changed to default. According to this rule, the interface name is automatically determined based on the firmware, topology, and location information. Now, even if you add or remove a network device, the interface name remains fixed without reenumeration, and can be replaced seamlessly with the broken hardware.

* Two letter prefixes Based on the Interface Type: * en -- Ethernet * sl -- Serial Line IP (slip) * wl -- wlan * ww -- wwan ** name type: * B <number> -- BCMA bus and new book * ccw <name> -- CCW bus group name * o <index> -- index number of the vehicle-mounted device * s <slot> [f <function >] [d <dev_port>] -- the index number of the hot swappable slot * x <MAC> -- MAC address * [P <domain>] p <bus> s <slot> [f <function >] [d <dev_port>] * -- PCI location * [P <domain>] p <bus> s <slot> [f <function>] [u <port>] [...] 1 [I <interface>] * -- USB port number chain

A small disadvantage of the new naming scheme is that the interface name is a bit difficult to read than the traditional name. For example, you may find a name like enp0s3. Furthermore, you can no longer control the interface name.

For some reason, if you prefer the old method and want to assign any name to a CentOS/RHEL7 device, you need to override the default predictable naming rules, define udev rules based on MAC addresses.

The following describes how to name the network interface in CentOS or RHEL7.

First, let's disable this predictable naming rule. You can pass the Kernel Parameter "net. ifnames = 0" at startup. This is done by editing/etc/default/grub and adding "net. ifnames = 0" to GRUBCMDLINELINUX variables.

Run this command to regenerate GRUB configuration and update kernel parameters.

$ sudo grub2-mkconfig -o /boot/grub2/grub.cfg 

Next, edit (or create) A udev network naming rule file (/etc/udev/rules. d/70-persistent-net.rules) and add the following line. Replace it with your own MAC address (08: 00: 27: a9: 7a: e1) and interface (sushi ).

 $ sudo vi /etc/udev/rules.d/70-persistent-net.rules 
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:a9:7a:e1", ATTR{type}=="1", KERNEL=="eth*", NAME="sushi"

Finally, restart the computer and verify the new interface name.

Note that the renamed interface is still your responsibility. If the network configuration (for example, IPv4 setting and firewall rule) is based on the old name (before the change), you need to update the network configuration to reflect the changed name.

Analysis of changes in CentOS 7 System Configuration

Build a high-availability cluster in CentOS 7

Getting started with Linux: Installing VMware 10 on CentOS 7

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.