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
WatchDog watchdog.sh script for checking server running
Viewed 5641 times since Tue, Jul 31, 2018
How do I add ethtool settings to a network device permanently?
Viewed 6934 times since Mon, May 21, 2018
Top 10 darmowych i publicznych serwerów DNS
Viewed 2558 times since Tue, May 22, 2018
6 easy steps to setup offline two factor authentication in Linux
Viewed 13652 times since Mon, Apr 6, 2020
Deskshare TLS over Stunnel
Viewed 2981 times since Fri, Sep 28, 2018
RHCS6: Reduce a Global Filesystem 2 (GFS2)
Viewed 3612 times since Sun, Jun 3, 2018
How to encrypt a partition using LUKS?
Viewed 2040 times since Fri, Jul 13, 2018
Method 2 – Use shell scripts How to install yum cron on a CentOS/RHEL 6.x/7.x
Viewed 4354 times since Tue, Dec 4, 2018
How setting the TZ environment variable avoids thousands of system calls
Viewed 10420 times since Mon, May 21, 2018
OEL 7 – How to disable IPv6 on Oracle Linux 7
Viewed 20812 times since Fri, Aug 3, 2018