A Network Interface Card (NIC) is used to connect a computer to an Ethernet network. This tutorial will teach you two ways you can add a network interface to an already existing network interface.
– First, we take a look at the interfaces I have available by issuing the ip a command.
For this tutorial, I am going to create and attach a sub network interface to the lo interface. All the configuration files for the various network interfaces are stored in the etc/sysconfig/network-scripts directory.
First, we will copy the content of the configuration scripts of the interface we want to attach the new subnetwork interface to; copy it to a file that will serve as the configuration script for the new subnetwork interface. The new script must end with a :interger extention. For example, the new interface I am creating will be named lo:1
- Copy the configuration file with the command:
cp /etc/sysconfig/network-scripts/ifcfg-lo /etc/sysconfig/network-scripts/ifcfg-lo:1
Remember to change the name of the network interfaces correspondingly when you are trying yours.
When you are done copying, open the file you just created with the copy command with a text editor:
Where you see DEVICE, change the device name to match the one you used in the copy command. In my case, I will change lo to lo:1.
– Also change the IPADDR value to the new address you want to add to the existing interface. In my case, I will put 127.0.0.10.
Save and quit the editor. Now, restart the interface using the command: ifup interfaceName. In my case, it will be ifup lo:1
Now, if we run the ip a command again, you will see the new network sub interface has been added.
You can ping the ip address to verify if it is truly up.
– Let’s run the ip a command again to view our existing network interfaces.
For this demonstration, I will attach a new sub network interface to the ens33 interface.
Now use the command below to add a new interface to a network interface: nmcli con mod interfaceName +ipv4.addresses “new-ip-address/nwMask”. In my case, the command will be nmcli con mod ens33 +ipv4.addresses “192.168.37.175/24”.
Now reboot your system and run the ip a command again.
The major difference between both methods is that you hold control over naming the newly created interface in the first method.
I hope you found this tutorial helpful.