RHEL: Rename a network interface on RHEL 7

RHEL: Rename a network interface on RHEL 7

# Tested on CentOS 7 (Virtual server)

# RHEL 6 introduced the Consistent Network Device Naming, feature that sets the name of
# network interfaces in order to make locating and differentiating the interfaces easier.

# This feature assigns automatically, during boot-up process, names to network interfaces
# whether they are embedded or in PCI slots, so they are persistent across reboots and
# hardware changes. Given names are based on:
#
# – firmware/bios-provided index numbers for on-board devices
# – firmware-provided pci-express hotplug slot index number
# – physical/geographical location of the hardware
# – the interface’s MAC address
#
# Consistent Network Device Naming convention:
#
# Two character prefixes based on the type of interface:
#   en -- ethernet
#   sl -- serial line IP
#   wl -- wlan
#   ww -- wwan
#
# Type of names:
#   b<number>                             -- BCMA bus core number
#   ccw<name>                             -- CCW bus group name
#   o<index>                              -- on-board device index number
#   s<slot>[f<function>][d<dev_port>]     -- hotplug slot index number
#   x<MAC>                                -- MAC address
#   [P<domain>]p<bus>s<slot>[f<function>][d<dev_port>]
#                                         -- PCI geographical location
#   [P<domain>]p<bus>s<slot>[f<function>][u<port>][..]1[i<interface>]
#                                         -- USB port number chain

ip addr
   1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
       link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
       inet 127.0.0.1/8 scope host lo
          valid_lft forever preferred_lft forever
       inet6 ::1/128 scope host
          valid_lft forever preferred_lft forever
   2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
       link/ether 08:00:27:48:a7:ef brd ff:ff:ff:ff:ff:ff
       inet 192.168.54.113/24 brd 192.168.54.255 scope global enp0s3
          valid_lft forever preferred_lft forever
       inet6 fe80::a00:27ff:fe48:a7ef/64 scope link
          valid_lft forever preferred_lft forever

# We can see that name has been assigned during boot-up:

dmesg | egrep "enp0s3|eth"
   [   12.329024] e1000 0000:00:03.0 eth0: (PCI:33MHz:32-bit) 08:00:27:48:a7:ef
   [   12.329854] e1000 0000:00:03.0 eth0: Intel(R) PRO/1000 Network Connection
   [   97.455465] e1000: enp0s3 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX



# Starting with RHEL 7, this feature is enabled by default. If, for some reason, you want to
# choose your own names for network interfaces, follow this procedure:


# First of all, disable the naming rule. To do that, edit /etc/default/grub file and add
# "net.ifnames=0" parameter to GRUB_CMDLINE_LINUX variable:

vi /etc/default/grub
   [...]
   GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=rootvg/lv_root rd.lvm.lv=rootvg/lv_swap rd.lvm.lv=rootvg/lv_usr net.ifnames=0 rhgb quiet"
   [...]

# Then, regenerate grub configuration by running this command:

grub2-mkconfig -o /boot/grub2/grub.cfg
   Generating grub configuration file ...
   Found linux image: /boot/vmlinuz-3.10.0-327.el7.i686
   Found initrd image: /boot/initramfs-3.10.0-327.el7.i686.img
   Found linux image: /boot/vmlinuz-0-rescue-ccddb0f617bc493baa4e9f7d7b8e4612
   Found initrd image: /boot/initramfs-0-rescue-ccddb0f617bc493baa4e9f7d7b8e4612.img
   done


# Once finished you have to create a udev rule, /etc/udev/rules.d/70-persistent-net.rules,
# to effectively rename the network interface at boot time:

vi /etc/udev/rules.d/70-persistent-net.rules
   SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:48:a7:ef", ATTR{type}=="1", KERNEL=="eth*", NAME="my_eth0"

# *** Do not forget to update /etc/sysconfig/network-scripts/ifcfg-* file conveniently !


# To make this change effective, reboot the server:

systemctl reboot

# And verify:

dmesg | egrep "enp0s3|eth"
   [   19.046271] e1000 0000:00:03.0 eth0: (PCI:33MHz:32-bit) 08:00:27:48:a7:ef
   [   19.048890] e1000 0000:00:03.0 eth0: Intel(R) PRO/1000 Network Connection
   [   99.567957] e1000: my_eth0 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX

ip addr
   1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
       link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
       inet 127.0.0.1/8 scope host lo
          valid_lft forever preferred_lft forever
       inet6 ::1/128 scope host
          valid_lft forever preferred_lft forever
   2: my_eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
       link/ether 08:00:27:48:a7:ef brd ff:ff:ff:ff:ff:ff
       inet 192.168.54.113/24 brd 192.168.54.255 scope global my_eth0
          valid_lft forever preferred_lft forever
       inet6 fe80::a00:27ff:fe48:a7ef/64 scope link
          valid_lft forever preferred_lft forever

0 (0)
Article Rating (No Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
12 Tcpdump Commands – A Network Sniffer Tool
Viewed 8707 times since Fri, Jul 27, 2018
HowTo: Retrieve Email from a POP3 Server using the Command Line
Viewed 10549 times since Mon, Feb 18, 2019
CONFIGURE FOR ASM Linux
Viewed 5441 times since Sat, Jun 2, 2018
Top 20 OpenSSH Server Best Security Practices - good article
Viewed 10459 times since Mon, Oct 1, 2018
RHCS6: Reduce a Global Filesystem 2 (GFS2)
Viewed 3300 times since Sun, Jun 3, 2018
Fix rpmdb: Thread died in Berkeley DB library
Viewed 20962 times since Fri, Feb 14, 2020
LVM: Managing snapshots
Viewed 7655 times since Sat, Jun 2, 2018
Oracle Linux 7 – How to audit changes to a trusted file such as /etc/passwd or /etc/shadow
Viewed 2854 times since Wed, Jul 25, 2018
LVM: Create a new Logical Volume / Filesystem
Viewed 2010 times since Sat, Jun 2, 2018
“Too many authentication failures” with SSH
Viewed 5698 times since Mon, May 21, 2018