Mud: Add NICs for KVM virtual machines

Source: Internet
Author: User

This article was sponsored by Xiuyi linfeng and first launched in the dark world.

The previous articles introduced how to install a VM on KVM and how to add a hard disk to the VM. Today we will introduce how to add a NIC to the kvm vm.

You can add NICs to a kvm vm in two ways: graphic interface and virsh attach-interface.

The graphic interface is very simple. Now the Virtual Machine centos2 is used as an example: for example:

Note the MAC address in the figure.

More/etc/udev/rules. d/70-persistent-net.rules

Now, we can see the newly added Nic. eth1 is displayed in the system, and the MAC address is 52: 54: 00: C7: 3B: 42.

The above shows how to add a nic for the kvm virtual machine through the graphic interface. If it is a Windows virtual machine, we can now directly use the NIC and then give the NIC an IP address. For a Linux system, You Need To perform other operations to use the NIC. For more information, see Add a NIC under the command line below.

Now we start to use the virsh attach-interface command to add the NIC. First, we use the virtual machine as the windows system as an example. Note that the virtual machine is running normally. Run the following command to add a NIC for the Virtual Machine server008:

Virsh attach-interface server2008 -- Type Bridge -- source br0

Server2008 is the virtual machine for which the NIC is to be added, -- type is the type of the NIC to be added, and -- source is the NIC that uses the KVM server.

Run the virsh dumpxml command to view the MAC address of the newly added Nic machine in the Virtual Machine server2008, as shown below:

Virsh dumpxml server2008

Note that the yellow part indicates the existing Nic of the VM, and the red part compares the newly added Nic.

Now let's start the Virtual Machine server2008 to see the actual situation.

We can see that the newly added Nic is displayed as "local connection 2" in the system ".

Note that the added Nic takes effect immediately when you run the virsh attach-interface command, but the new Nic disappears after the VM restarts.

This is because the newly added Nic of the command is not updated to the configuration file of the virtual machine. To make the NIC take effect permanently, run the virsh dumpxml command to save the configuration to the virtual machine configuration file. As follows:

Virsh dumpxml server2008> server2008.xml

Run the virsh domiflist command to view the current Nic of the VM, as shown below:

Virsh domiflist server2008

You can also view the configuration file as follows:

More/etc/libvirt/qemu/server2008.xml | grep Mac

The above shows how to add a NIC for a Windows virtual machine. Adding a NIC for a Linux system is similar to this operation. After the NIC is added, You Need To perform other operations before it can be used properly.

Continue to use the virsh attach-interface command. As follows:

Virsh attach-interface centos -- Type Bridge -- source br0

First, check the number of NICs of the centos Virtual Machine before adding a NIC. Run the following command: More/etc/udev/rules. d/70-persistent-net.rules

Run the following command to add the number of NICs of the centos virtual machine after the NIC is added:

More/etc/udev/rules. d/70-persistent-net.rules

We can clearly see that the system has added a NIC eth3 in the Bank of China.

Now we start to set the network adapter eth3 to make it available in the system. We first copy the configuration file of the network adapter eth0 and run the command eth3 as follows:

CP/etc/sysconfig/network-scripts/ifcfg-eth0/etc/sysconfig/network-scripts/ifcfg-eth3

Next we start to configure the network adapter eth3, where the MAC address of the network adapter eth3 can be viewed in the 70-persistent-net.rules file, for example:

After the eth3 configuration is complete, restart the network service for the NIC to take effect. For example:

The above section describes how to add Nic configurations for KVM virtual machines. Of course, do not forget to write the above operations to the VM configuration file. Run the following command:

Virsh dumpxml centos> centos. xml

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.