This tutorial is intended for users who want to use Ubuntu for small experiments. This does not apply to all users, especially those who use production machines in the official environment.
If you know something about network operations and IP networks, you should know that in most cases, each NIC will only assign one IP address. We are used to think that this is a one-to-one thing.
A network adapter corresponds to an IP address. A network adapter on a machine and its IP address can only be bound to or run a single network service/port. For example, if you want to run a web server on port 80, and an IP address and port number can only be monitored by one web server. This is designed in this way.
Therefore, the relationship between the network adapter and the IP address is not one-to-one. You can create a virtual network adapter that can assign an IP address separately. Therefore, a single physical Nic can cluster unlimited sub-nics or virtual NICs. Each user can assign its own IP address to the corresponding port.
This short tutorial will show you how to do this on Ubuntu. This is a good way to run and test multiple network services on a computer with a physical Nic and a single port number.
Run the following command to open the network interface file.
Sudo gedit/etc/network/interfaces
Then, add any number of virtual NICs you want as per the steps in. By default, Linux assigns the eth0 name to the first Nic, so if your host has only one Nic, it will be named eth0.
Add a virtual network card, create multiple static network cards and name them eth0: 1, eth0: 2, eth0: 3, and so on (eth0 followed by a colon and number ).
Make sure that the network is a different subnet for each network adapter you create. This is a common knowledge of networks)
After that, save the file and run the following command to restart the network service.
Sudo service networking restart
That's it!
Have fun!
Compile a Linux virtual network card to implement NVI-like
Linux driver development: Virtual Network Card for network devices
Implement Virtual Nic in Linux