Network interfaces are an absolutely vital part of any business today. From mom-and-pop shops to Fortune 100 companies, everyone is leveraging the network for logistics and communications. Most, if not all, of these businesses can directly tie their bottom line to their network in some way—if the network goes down or someone accidentally cycles the wrong interface, money is on the table. It is for this reason that the system/network administrator needs to pay careful attention anytime they are working on or around the network interfaces.
One of the most basic and sometimes overlooked tasks can be the naming convention for the various interfaces that you depend on every day. I have worked with small companies that only had one or two interfaces for their entire environment. In this case, a naming convention is less of a problem. However, for larger enterprise environments, naming your network interfaces is vital to long term success. Imagine how easy it would be to make a mistake because all of your interfaces are similarly named.
No need to panic though! The brilliant Linux/Unix community saw this issue coming and developed multiple ways to avoid it. I want to take a look at three different commands: nameif, ip link, and ifrename. You can utilize each of these tools to name and interact with your interfaces in various ways.
nameif
The nameif command is an older command that is officially deprecated. However, there are still those out there using it for specific tasks. The one and only goal of this command is to name an interface according to the MAC address of the device(s). For example:
[root@rhel ~]# nameif -c /etc/mactab -s 08:00:27:30:52:a7
The -c option allows you to specify from which configuration file you wish to read. By default, it uses /etc/mactab. The -s flag simply lets the system know to send any error messages to the syslog. You then give it the MAC address of the interface you are renaming. Easy day.
Note that you must run nameif before bringing the interface up, or it will fail.
ifrename
Network interface names are dynamic by default and are assigned on a first-come, first-served numerical basis: eth0, eth1, eth2, and so on. The ifrename tool allows you to assign a consistent name to your interfaces. You can set this up in several ways. However, the most common usage here is to set the name based on—you guessed it—the MAC address. It makes sense to do it this way since MAC addresses are unique to the device. Much like nameif, you must run ifrename before the interfaces are brought up to avoid failures. This tool also pulls data from configuration files; however, this time, we are using /etc/iftab (unless otherwise specified). Let's look at how to use it.
Syntax: [root@rhel ~]# ifrename [-c configfile] [-i interface] [-n newname]
-c - allows you to specify a config file other than /etc/iftab
-i - allows you to rename only a specific interface rather than all system interfaces
-n - allows you to specify the new name of the interface (use with -i)
-D - allows the user to enter "dry-run" mode. Here, ifrename won't change the name of the interface. It only prints the new name and return. This is a great way to make sure that you have the command correct before running for real.
-V - gives verbose output with additional information used for debugging issues.
ip link
The ip command is the Swiss army knife of Linux networking commands. We are looking specifically at ip link, the command used to name and modify network interfaces.
To list all interfaces, use the following:
[tcarrigan@rhel ~]$ ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
link/ether 08:00:27:30:52:a7 brd ff:ff:ff:ff:ff:ff
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default qlen 1000
link/ether 52:54:00:b7:7b:c7 brd ff:ff:ff:ff:ff:ff
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel master virbr0 state DOWN mode DEFAULT group default qlen 1000
link/ether 52:54:00:b7:7b:c7 brd ff:ff:ff:ff:ff:ff
Notice that there is no IP address information given with this command. You need to use the ip addr command to meet that need. For specific interface information, use the following:
[tcarrigan@rhel ~]$ ip link show dev enp0s3
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
link/ether 08:00:27:30:52:a7 brd ff:ff:ff:ff:ff:ff
To change the name of an interface, we use the following:
[tcarrigan@rhel ~]$ ip link set eth0 name eth123
Note that you must disable the interface, change the name, and then bring it back up for the changes to take place. You also need to modify the /etc/sysconfig/network-scripts/ifcfg_old_device_name to the new device name in both the title and content of the file.
Wrap up
I had a supervisor who used to say, "There is more than one way to skin a cat." Although there are more polished ways to say it, the point is that there is always an alternative way to complete a task. This is proven with almost every operation that an administrator needs to accomplish. Even something as simple as naming interfaces presents choices for the admin to make. What are your thoughts? If presented with the situation, which of these commands would you use to get the job done?
[ Want more for your network? Download a free ebook on network automation with Ansible. ]
Sobre el autor
Tyler is the Sr. Community Manager at Enable Sysadmin, a submarine veteran, and an all-round tech enthusiast! He was first introduced to Red Hat in 2012 by way of a Red Hat Enterprise Linux-based combat system inside the USS Georgia Missile Control Center. Now that he has surfaced, he lives with his wife and son near Raleigh, where he worked as a data storage engineer before finding his way to the Red Hat team. He has written numerous technical documents, from military procedures to knowledgebase articles and even some training curricula. In his free time, he blends a passion for hiking, climbing, and bushcraft with video games and computer building. He is loves to read and enjoy a scotch or bourbon. Find him on Twitter or on LinkedIn.
Más como éste
Behind the scenes of RHEL 10, part 3
Alliander modernises its electricity grid with Red Hat for long-term reliability in balance with rapid innovation
Linux, Shadowman, And Open Source Spirit | Compiler
OS Wars_part 1 | Command Line Heroes
Navegar por canal
Automatización
Las últimas novedades en la automatización de la TI para los equipos, la tecnología y los entornos
Inteligencia artificial
Descubra las actualizaciones en las plataformas que permiten a los clientes ejecutar cargas de trabajo de inteligecia artificial en cualquier lugar
Nube híbrida abierta
Vea como construimos un futuro flexible con la nube híbrida
Seguridad
Vea las últimas novedades sobre cómo reducimos los riesgos en entornos y tecnologías
Edge computing
Conozca las actualizaciones en las plataformas que simplifican las operaciones en el edge
Infraestructura
Vea las últimas novedades sobre la plataforma Linux empresarial líder en el mundo
Aplicaciones
Conozca nuestras soluciones para abordar los desafíos más complejos de las aplicaciones
Virtualización
El futuro de la virtualización empresarial para tus cargas de trabajo locales o en la nube