The default network mode of KVM is NAT. That is to say, we want to use the host mode to access the Internet. Now we want to change to the bridge mode so that the outside world can directly communicate with the virtual machine in the host.
The default network mode of KVM is NAT. That is to say, we want to use the host mode to access the Internet. Now we want to change to the bridge mode so that the outside world can directly communicate with the virtual machine in the host.
1. First, let's take a look at the default network settings.
The Code is as follows:
# cat /etc/libvirt/qemu/networks/default.xml
default
1f118032-0345-4725-adcf-6b94f6aca19c
2. Check the network settings in the virtual machine configuration file.
# Cat/etc/libvirt/qemu/ubuntu10.04.xml
Ubuntu10.04 2eeb1395-39a2-a169-4da3-f22b20a1d34f 1048576 1048576 1 Hvm Destroy Restart Restart /Usr/libexec/qemu-kvm Interface type = 'default' It turns out to be source network = 'default'. Here br1 is based on your physical Nic.
3. Update the configuration file after modification.
# Virsh define ubuntu10.04.xml
Definition domain ubuntu10.04 (from ubuntu10.04.xml)
# Then you can run virsh start ubuntu10.04, but the physical Nic has not been changed yet.
4. You can change the physical Nic manually. However, you can use the ready-made tool kit to change the NIC.
# Wget http://www.convirture.com/downloads/convirture-tools/2.0.1/convirture-tools-2.0.1.tar.gz
# Tar zxvf convirture-tools-2.0.1.tar.gz
#/Root/convirture-tools/install/managed_server/scripts/convirt-tool -- bridge setup
I encountered a small problem here, and found that the Network was not up, so do not perform this operation remotely, the main reason is that the configuration file inside is a bit of a need
I commented on the UUID.
# Ls ifcfg -*
Ifcfg-br1 ifcfg-br2 ifcfg-br3 ifcfg-br4 ifcfg-em1 ifcfg-em2 ifcfg-em3 ifcfg-lo
I have four physical NICs, so four bridges are generated, but only br1 is actually used.
One advantage of this tool is to save the original configuration file and restore it if you do not want it
# ls saved.ifcfg-em*saved.ifcfg-em1.20121128.101114 saved.ifcfg-em3.20121128.101114saved.ifcfg-em2.20121128.101114 saved.ifcfg-em4.20121128.101114
Look at the ifceg-em1
# cat ifcfg-em1DEVICE="em1"#BOOTPROTO=noneNM_CONTROLLED="yes"ONBOOT=yesTYPE="Ethernet"#UUID="3bc7fdcc-42b1-4223-b202-e697305897c8"#IPADDR172.16.10.81PREFIX=24GATEWAY=172.16.10.254DNS1=172.16.10.5DEFROUTE=yesIPV4_FAILURE_FATAL=yesIPV6INIT=noNAME="System em1"HWADDR=90:B1:1C:20:4D:A5BRIDGE=br1
Look at the ifcfg-br1
# cat ifcfg-br1DEVICE="br1"BOOTPROTO=noneNM_CONTROLLED="yes"ONBOOT=yes#UUID="3bc7fdcc-42b1-4223-b202-e697305897c8"IPADDR=172.16.10.81PREFIX=24GATEWAY=172.16.10.254DNS1=172.16.10.5DEFROUTE=yesIPV4_FAILURE_FATAL=yesIPV6INIT=noNAME="System br1"TYPE=Bridge
Finally, check the NIC.
# ifconfigbr1 Link encap:Ethernet HWaddr 90:B1:1C:20:4D:A5inet addr:172.16.10.81 Bcast:172.16.10.255 Mask:255.255.255.0inet6 addr: fe80::92b1:1cff:fe20:4da5/64 Scope:LinkUP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1RX packets:10219 errors:0 dropped:0 overruns:0 frame:0TX packets:3776 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:0RX bytes:576031 (562.5 KiB) TX bytes:15928008 (15.1 MiB)em1 Link encap:Ethernet HWaddr 90:B1:1C:20:4D:A5inet6 addr: fe80::92b1:1cff:fe20:4da5/64 Scope:LinkUP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1RX packets:10362 errors:0 dropped:0 overruns:0 frame:0TX packets:13131 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000RX bytes:766684 (748.7 KiB) TX bytes:16489098 (15.7 MiB)Interrupt:35lo Link encap:Local Loopbackinet addr:127.0.0.1 Mask:255.0.0.0inet6 addr: ::1/128 Scope:HostUP LOOPBACK RUNNING MTU:16436 Metric:1RX packets:144411 errors:0 dropped:0 overruns:0 frame:0TX packets:144411 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:0RX bytes:147381248 (140.5 MiB) TX bytes:147381248 (140.5 MiB)virbr0 Link encap:Ethernet HWaddr 52:54:00:F1:6B:6Einet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1RX packets:2028 errors:0 dropped:0 overruns:0 frame:0TX packets:1135 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:0RX bytes:233311 (227.8 KiB) TX bytes:89372 (87.2 KiB)vnet0 Link encap:Ethernet HWaddr FE:54:00:50:58:7Einet6 addr: fe80::fc54:ff:fe50:587e/64 Scope:LinkUP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1RX packets:161 errors:0 dropped:0 overruns:0 frame:0TX packets:3117 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:500RX bytes:15533 (15.1 KiB) TX bytes:263947 (257.7 KiB)vnet1 Link encap:Ethernet HWaddr FE:54:00:B5:1A:19inet6 addr: fe80::fc54:ff:feb5:1a19/64 Scope:LinkUP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1RX packets:56 errors:0 dropped:0 overruns:0 frame:0TX packets:794 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:500RX bytes:8754 (8.5 KiB) TX bytes:42245 (41.2 KiB)
5. Configure the NIC after starting the VM ubuntu10.04
#cat /etc/network/interfaceauto loiface lo inet loopbackauto eth0iface eth0 inet staticaddress 172.16.10.100netmask 255.255.255.0gateway 172.16.10.254#/etc/init.d/networking restart
Start