This approach provides a systematic method for assigning user friendly, descriptive names to network interfaces within a system. By utilizing meaningful nomenclature, the purpose and functionality of each network interface become immediately apparent. Rather than relying on generic identifiers such as "eth" or "en" followed by arbitrary numerical suffixes, this method employs intuitive labels such as "PUBLIC," "PRIVATE," or "SAN," thereby enhancing clarity and facilitating efficient network management.
This is of particular benefit for VMware based VMs but can also be helpful on other systems, though it should generally only be done when kicking a new system. While it should be technically feasible to adjust a live system to use this method it would likely break things very fast.
When deploying virtual machine (VM) guests on VMware, it is a standard practice to configure the network interface cards (NICs) with descriptive, user friendly names. This is achieved by renaming the NICs for the current boot session and modifying the corresponding network configuration scripts, such as those managed by ifconfig or similar utilities. As previously noted, this process results in the assignment of intuitive NIC labels, such as "PUBLIC" or "PRIVATE," rather than generic identifiers like "eth0" or "en0." This approach enhances clarity and simplifies network management within the virtualized environment.
The first step is to deploy the system per the build specs. Then upon the first boot of the VM this task should be done before anything else.
These directions will assume that you have already configured and attached networks to the VMs NIC in vCenter.
Variable | How to find |
---|---|
$INITIAL_NAME | The default assigned name for the NIC device. E.g. eth0, en0, etc |
$NAME |
The human friendly NIC name - should be contextually obvious for the use. E.g. PUBLIC, PRIVATE, INTERNAL, DLM, etc |
$MAC_ADDR | The MAC address assigned to the NIC by vCenter. Get it from the drop down on the NIC in vCenter or via ip link in Guest's shell. |
$IP |
The IP address you are assigning to the Guest VM for this NIC. |
$SUBNET_GATE |
The Gateway IP for the subnet that the IP address belongs to. |
$SUBNET_PREFIX |
The subnet prefix that matches the IP address being assigned. |
Screenshots:
Now you'll rename the NIC, however this change isn't persistent. So it will only last for the current boot of the system unless you complete all the steps. This is important as it just helps ensure you can properly test things.
First gather the interface name that you will be setting up. Depending on management level this may be something like eht0 or ens192. Best to do an "ip a" to verify what the active nic is named.
ip a
Next assure the interface you are wanting to update is down:
ip link set $INITIAL_NAME down or ifdown $INITIAL_NAME
Example:
ip link set eth0 down or ifdown eth0
Run:
ip l set $INITIAL_NAME name $NAME
Example:
ip l set eth0 name PUBLIC
Screenshots:
To ensure the name change is permanent we will make the appropriate network script. The base path of this file will be:
/etc/sysconfig/network-scripts/ifcfg-${NAME}
However it's wise to check for existing scripts using the $INITIAL_NAME. If that exists, you can simply rename the file and edit it accordingly. Ensure that if you see any other matching "*-$INITIAL_NAME" network scripts you rename those accordingly too.
Example:
touch /etc/sysconfig/network-scripts/ifcfg-PUBLIC vim /etc/sysconfig/network-scripts/ifcfg-PUBLIC
Essentially it doesn't matter if you are editing an existing file you renamed, or creating a new NIC config file. The basic process will be the same idea overall - since we just need a specific set of parameters configured.
The default template based on the variables above is:
DEVICE=$NAME HWADDR=$MAC_ADDR BOOTPROTO=none ONBOOT=yes IPADDR=$IP PREFIX=$SUBNET_PREFIX GATEWAY=$SUBNET_GATE
Example:
DEVICE=PUBLIC HWADDR=00:50:FF:a1:FF:7c BOOTPROTO=none ONBOOT=yes IPADDR=172.16.240.190 PREFIX=24 GATEWAY=172.16.240.1
Note: Do not copy and paste the example - you will need to edit it if you do.
Finally, we'll use systemd to restart networking to do a quick test. If systemd restarts networking successfully and you can still reach the public internet things are good! This test should ensure it should work on reboot - but you can test that too.
First run:
systemctl restart network
Then, depending on which NICs you are testing you will want to ping something you should be able to reach. So for the PUBLIC interface you can test pinging out to google. But for internal networks you'll want to use a device on the same network to ping at.