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
Jak ustawić LVM, jak robić snapshoty oraz automatycznie powiększać LV, czyli małe howto
Viewed 4441 times since Sun, May 20, 2018
How to create stunnel with systemd? stunnel
Viewed 9385 times since Thu, Jan 16, 2020
python learning
Viewed 1779 times since Wed, Dec 18, 2019
How to create a Systemd service in Linux
Viewed 2784 times since Mon, Dec 7, 2020
Linux Kernel /etc/sysctl.conf Security Hardening
Viewed 23440 times since Fri, Aug 3, 2018
Top 10 darmowych i publicznych serwerów DNS
Viewed 2276 times since Tue, May 22, 2018
Yum Update: DB_RUNRECOVERY Fatal error, run database recovery
Viewed 3937 times since Fri, Jan 17, 2020
20 Linux Command Tips and Tricks That Will Save You A Lot of Time linux
Viewed 4616 times since Thu, Apr 18, 2019
Need to set up yum repository for locally-mounted DVD on Red Hat Enterprise Linux 7
Viewed 2998 times since Mon, Oct 29, 2018
How To: Linux Hard Disk Encryption With LUKS [ cryptsetup Command ]
Viewed 7239 times since Fri, Jul 13, 2018