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
stunnel Howto A Guide to create SSL access to a HTTP-only webserver with stunnel
Viewed 2879 times since Fri, Sep 28, 2018
logrotate Understanding logrotate utility
Viewed 1978 times since Sun, Jan 12, 2020
ZPOOL: Detach a submirror from a mirrored zpool
Viewed 2897 times since Sun, Jun 3, 2018
ZFS: Remove an existing zfs filesystem
Viewed 2289 times since Sun, Jun 3, 2018
Linux File Systems (mkfs, mount, fstab) ext4
Viewed 3343 times since Sat, Jun 2, 2018
Linux - How to get IP and MAC address of ethernet adapter in Linux
Viewed 2889 times since Fri, Jun 8, 2018
How log rotation works with logrotate
Viewed 5075 times since Fri, Nov 30, 2018
Linux PAM configuration that allows or deny login via the sshd server
Viewed 2146 times since Wed, Oct 3, 2018
How to use yum-cron to automatically update RHEL/CentOS Linux 6.x / 7.x
Viewed 5286 times since Tue, Dec 4, 2018
Linux Add a Swap File – HowTo
Viewed 10329 times since Fri, Jun 8, 2018