Regarding the configuration of the graphical interface, I will not introduce more here, this is very simple. Here is how to implement a virtual network card by modifying the configuration file.
First introduce the configuration of the virtual network card under ubuntu (I am using ubuntu-16.04 here)
1. First use ifconfig to view the current network card configuration
ens33 Link encap: ethernet hardware address 02:0c:29:c6:be:c7 inet6 address: fe80::20c:29ef:fec6:bec7/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU: 1500 跃 Score: 1 Received packets: 215 Errors: 0 Dropped: 0 Overload: 0 Frames: 0 Packets sent: 256 Errors: 0 Dropped: 0 Overload: 0 Carrier: 0 Collision: 0 Send Queue Length: 1000 Received bytes: 25858 (25.8 KB) Transmitted bytes: 27711 (27.7 KB) lo Link encap: local loopback inet address: 127.0.0.1 mask: 255.0.0.0 inet6 address: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU: 65536 Hops: 1 Received packets: 165 Errors: 0 Dropped: 0 Overload: 0 Frames: 0 Packets sent: 165 Errors: 0 Dropped: 0 Overload: 0 Carrier: 0 Collision: 0 Send Queue Length: 1 Receive bytes: 12225 (12.2 KB) Send bytes: 12225 (12.2 KB)
Generally, before setting, the printed information is as above.
2. View the current network card configuration and open the configuration file /etc/network/interfaces
sudo vim /etc/network/interfaces
You can see the network card configuration with only one loopback test
auto lo iface lo inet loopback
3. Choose to add our own network card configuration. The first network card (ens33) configuration must be on the external network. If you configure it as an internal network, your system will not be able to access the external network.
The address, mask and gateway are configured according to their actual network. My external network ip is on the 172.16.2.xxx network segment.
car ens33 iface ens33 inet static #Set static IP, dynamic is to change static to dhcp, if set to dynamic IP, virtual network card cannot be set address 172.16.2.95 # If it is below dynamic IP, no configuration is required. netmask 255.255.0.0 gateway 172.16.254.254
4. Next, configure the virtual network card (ens33:1)
Similarly, the IP of the intranet is configured according to the actual situation. The intranet IP here is the 192.168.8.xxx network segment.
auto ens33: 1 iface ens33:1 inet static address 192.168.8.95 netmask 255.255.255.0 gateway 192.168.8.1
In this way, you can access the internal and external networks at the same time.
Assume that one more intranet virtual NIC of another network segment is added.
auto ens33: 2 iface ens33:2 inet static address 192.168.88.95 netmask 255.255.255.0 gateway 192.168.88.1
By analogy, multiple intranet network cards of different network segments can be added, and all of them can access each other.
5. Configure the default gateway
Open /etc/resolv.conf
sudo vim /etc/resolv.conf
Add the gateway of the network segment configured above to the configuration file. We have configured three network segments above, then add the following information to our configuration file
nameserver 172.16.254.254 nameserver 192.168.8.1 nameserver 192.168.88.1
In the previous version, this is enough, but in the new version, you need to add the above content in another configuration file.
Open /etc/resolvconf/resolv.conf.d/base
sudo vim /etc/resolvconf/resolv.conf.d/base
In general, add the above three default gateways
nameserver 172.16.254.254 nameserver 192.168.8.1 nameserver 192.168.88.1
6. Restart the computer
After modifying these, it can only take effect by restarting the computer. Restarting the network card with the command (sudo /etc/init.d/networking restart) has no effect. The reason is unclear.
After restarting the computer, use ifconfig to check, there are multiple network card configurations, and they can all be used without conflicting with each other.