There are plenty of reasons why you'd need to set up virtual network interfaces on a RHEL 8 / CentOS 8 server or workstation. The process has changed a bit since RHEL 7, but it's still fairly straightforward.

In this tutorial you will learn:
  • How to Locate Your Network Interfaces
  • How to Edit Your Main Network Configuration
  • How to Duplicate Your Network Configuration
  • How to Create The Virtual Interface Confg
Create Virtual Interface on RHEL 8 / CentOS 8
Create Virtual Interface on RHEL 8 / CentOS 8.

Software Requirements and Conventions Used

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System RHEL 8 / CentOS 8
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ - requires given linux commands to be executed as a regular non-privileged user

How to Locate Your Network Interfaces

Before you can start modifying your network interfaces to create a virtual one, you're going to need to find out exactly what they're called. Since RHEL switched to systemd, interface names aren't as simple as they once were.

List Interfaces on RHEL 8 / CentOS 8
List interfaces on RHEL 8 / CentOS 8.

Run ip a to get a full read out of the interfaces on your system. The one you're connected to your network with will have a local IP address listed next to inet.

How to Edit Your Main Network Configuration

Now that you know which interface you're looking to work with, you'll need to modify its configuration file to set up a static IP and make everything work. Open your configuration at /etc/sysconfig/network-scripts/ifcfg-eth0. Replace eth0 with the actual name of your interface.


$$$ Looking for LINUX ADMINISTRATOR ! $$$

BLUE SKY STUDIOS are looking for Linux Administrator to maintain and support the Studio's 450+ production Linux workstations, including daily interactions with the Studio’s digital animation artists.
LOCATION: Greenwich, Connecticut, USA

APPLY NOW

Configure Main Interface on RHEL 8 / CentOS 8
Configure Main Interface on RHEL 8 / CentOS 8.

First, make any changes that you want to the file, like disabling IP6 support, if you don't want it. Then, change BOOTPROTO to static.

At the bottom of the file, add entries for IPADDR, NETMASK, GATEWAY, and DNS. Configure them to match your network.

Save your configuration, and exit.

How to Duplicate Your Network Configuration

You're going to use that original configuration that you just modified as the template for your new virtual networks. cd into the network-scripts directory to make this easier.

# cd /etc/sysconfig/network-scripts/

Then, copy the original to create two virtual network configurations.

# cp ifcfg-eth0 ifcfg-eth0:0
# cp ifcfg-eth0:1

How to Create The Virtual Interface Confg

Configure First Virtual Interface on RHEL 8 / CentOS 8
Configure First Virtual Interface on RHEL 8 / CentOS 8.

Open up ifcfg-eth0:0 to modify the NAME and DEVICE attributes to match eth0:0. Of course, use your actual device's interface in place of eth0 here too.



Configure Second Virtual Interface on RHEL 8 / CentOS 8
Configure Second Virtual Interface on RHEL 8 / CentOS 8.

Do the same with ifcfg-eth0:1, this time filling in eth0:1. For this one, you'll need to change the IPADDR value too. Use a different IP that isn't used on your network.

When you're ready, and everything looks correct, restart your computer. You can try restarting the NetworkManager service, but it has a tendency to be uncooperative.

List Virtual Interfaces on RHEL 8 / CentOS 8
List Virtual Interfaces on RHEL 8 / CentOS 8.

After your computer comes back up, run ip a again. You should see your virtual address this time, complete with the IP address that you set for it.



Ping Vitual Interface on RHEL 8 / CentOS 8
Ping Virtual Interface on RHEL 8 / CentOS 8.

If you would like to test that your interface is working, you can send it a ping from another computer on your network.

Conclusion

There you have it! You can create multiple virtual network interfaces as you need. They'll remain active as long as your configurations remain in place.

ARE YOU LOOKING FOR A LINUX JOB?
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed on LinuxCareers.com.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.