Creating a sub-interface in CentOS (adding a second IP to interface)

Viewing interfaces

This manual explains how to configure a network sub-interface. First of all, let's look at available network interfaces:

ifconfig -a

Creating a sub-interface in CentOS.png

We see ens32 network interface with the IP address assigned to it.

Creating a sub-interface

Let's make a copy of the configuration file ifcfg-ens32 and name it as ifcfg-ens32: 0 - this will be a configuration file for our sub-interface:

cp /etc/sysconfig/network-scripts/ifcfg-ens32 /etc/sysconfig/network-scripts/ifcfg-ens32:0

Edit the newly created file

nano /etc/sysconfig/network-scripts/ifcfg-ens32:0

Replace: DEVICE=ens32 with: DEVICE=ens32:0.

Find IPADDR string and replace it with the desired IP address of the network sub-interface.

Creating a sub-interface in CentOS-edit ens32_0.png

Save the changes „Ctrl + O“ and press "Enter"; exit the editor „Ctrl + X“

Starting the sub-interface

Start the sub-interface using the command:

ifup ens32:0

Let's check the network interface:


Creating a sub-interface in CentOS-resault.png

This completes the configuration of the additional IP address