How does Linux add a virtual network card?

  
                

NICs and IP addresses are not one-to-one. Many users create virtual NICs that can be assigned separate IP addresses when needed. A single physical NIC can cluster unlimited subnet cards or virtual NICs, each of which can assign its own IP address to the corresponding port. Today Xiaobian will tell you how to add virtual network cards to Linux.

The first method: express create \\ delete virtual network card

sudo ifconfig eth0:0 192.168.10.10 up

The above command can create a call on the eth0 network card The virtual network card of eth0:0, his address is: 192.168.1.63

If you do not want this virtual network card, you can use the following command to delete:

sudo ifconfig eth0:0 down

After restarting the server or network, the virtual network card is gone.

hzhsan: But found that the added virtual network card and the original network card physical address is the same.

The second way: to modify the network card configuration file

In ubuntu, LAN configuration file is /etc /network /interfaces, so we modify it:

sudo vim /etc/network/interfaces

Add the following to this file and save it:

auto eth0:0

iface eth0:0 inet static

address 192.168.10.10

netmask 255.255.255.0

#network 192.168.10.1

#broadcast 192.168.1.255

After saving, we need Restart the NIC (reload the configuration file) to take effect, use the following command to restart:

sudo /etc/init.d/networking restart

His advantage is that restarting the server or NIC configuration will not Lost.

The third method: create tap

The first two methods have a feature, the created network card can have different ip address, but the Mac address is the same. Cannot be used to create a virtual machine.

Adding a virtual network card tap

tunctl -b

Attaching a related command Introduction:

Displaying bridge information

brctl show< Br>

Adding a bridge

brctl addbr virbr0

Activating a bridge

ip link set virbr0 up

Adding a virtual NIC tap

tunctl -b

tap0 -------》 Performing the above mission will generate a tap with the suffix increasing from 0, 1, and 2

activating the created tap< Br>

ip link set tap0 up

Add the tap0 virtual NIC to the specified bridge.

brctl addif br0 tap0

Configuring an ip address for a bridge

ifconfig virbr1 169.254.251.4 up

NIC5 eth5 bound to the virbr1 bridge Remove

brctl delif virb1 eth5

Add NIC to virbr1 bridge eth6

brctl addif virbr1 eth6

The above is how Linux adds virtual NIC, three Different methods are available, and users in need can choose any method to add a virtual network card.

Copyright © Windows knowledge All Rights Reserved