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
How to run command or code in parallel in bash shell under Linux or Unix
Viewed 3397 times since Tue, Aug 6, 2019
Top 20 OpenSSH Server Best Security Practices ssh linux aix
Viewed 6137 times since Fri, May 15, 2020
ZPOOL: Create a new zpool for zfs filesystems
Viewed 2377 times since Sun, Jun 3, 2018
Tips to Solve Linux & Unix Systems Hard Disk Problems
Viewed 4284 times since Fri, May 15, 2020
SSH: Execute Remote Command or Script – Linux
Viewed 2553 times since Mon, Feb 18, 2019
Używanie rsync poprzez Secure Shell
Viewed 41414 times since Thu, May 24, 2018
Create a Linux Swap File
Viewed 3170 times since Fri, Jun 8, 2018
Netcat shell zabezpieczony hasłem
Viewed 2362 times since Thu, May 24, 2018
stunnel bacula
Viewed 2193 times since Fri, Sep 28, 2018
UUIDs and Linux: Everything you ever need to know [Update]
Viewed 5066 times since Tue, Jul 17, 2018