KVM bridging Network

Source: Internet
Author: User
Tags rdesktop

The following describes how to configure the KVM bridging Network: \ pay special attention to the fact that most wireless network adapters cannot be bridges... Only PCI NICs can be Bridge ....
Install the bridge tool:

Code:

sudo apt-get install bridge-utils

Install the tool for creating the tap interface:

Code:

sudo apt-get install uml-utilities

Edit the network interface configuration file
Code:

Sudo VI/etc/Network/interfaces:

Code:

Auto eth0iface eth0 Inet static \ This can be dhcpaddress 192.168.1.2netmask 255.255.255.0gateway 192.168.1.1

Or use the most conservative eth0 Configuration:
Auto eth0
Iface eth0 Inet Manual

Auto tap0
Iface tap0 Inet Manual
Up ifconfig $ iface 0.0.0.0 up
Down ifconfig $ iface down
Tunctl_user lm \ lm is my user name. Here, replace it with your user name.

Auto br0
Iface br0 Inet static \ can also be allocated using DHCP.
Bridge_ports eth0 tap0
Address 192.168.1.3
Netmask 255.255.255.0
Network 192.168.1.0
Broadcast 192.168.1.255
Gateway 192.168.1.1

Activate tap0 and br0: // sometimes it will not work, but it will work after restart.

Code:

sudo /sbin/ifup tap0sudo /sbin/ifup br0

Now, you can check ifconfig. If you have an additional tap0 and br0, the IP address on br0 is the IP address of your local machine.

KVM usage:
For details about how to use KVM, refer

Code:
/Usr/local/KVM/bin/qemu-system-x86_64 -- Help

The following are examples:
Create a virtual disk (use the qemu-IMG command ):

Code:

mkdir kvmcd kvm/usr/local/kvm/bin/qemu-img create -f qcow2 winxp.img 10G

Create a virtual machine:

Code:

sudo /usr/local/kvm/bin/qemu-system-x86_64 -m 512 -hda /home/lm/kvm/winxp.img -localtime -net nic,vlan=0,macaddr=52-54-00-12-34-01 -net tap,vlan=0,ifname=tap0,script=no -boot d -cdrom /home/lm/iso/winxp.iso -smp 2 -clock rtc -soundhw es1370

The parameters are described as follows:

Code:

-m 512

Allocate MB of memory to guest OS

Code:

-hda /home/lm/kvm/winxp.img

Use Virtual Disk Files and paths

Code:

-localtime

Use local time (this parameter must be added, or the VM time may be faulty)

Code:

-net nic,vlan=0,macaddr=52-54-00-12-34-01 -net tap,vlan=0,ifname=tap0,script=no

Use the network and connect to an existing network device, such as tap0. Note that you must write one for the MAC address. If you have virtualized multiple systems and want to run them at the same time, the Mac will conflict.

Code:

-boot d

Boot from the CD (boot c from the hard disk)

Code:

-cdrom /home/lm/iso/winxp.iso

The disk image used. If you want to use a physical optical drive, it is-CDROM/dev/CDROM.

Code:

-smp 2 

The number of SMP processors is 2. If you are a 4-core processor, the following number is 4 (if you do not enable this option, you can only run in Single-core Mode)

Code:

-clock rtc

Use the RTC clock (If this option is not enabled, WINXP may be slow)

Have you started the installation system? Is it very fast? If your machine can, install XP in about 15 minutes.
Start the installed Virtual Machine (very simple, just change the above command to two parameters ):

Code:

sudo /usr/local/kvm/bin/qemu-system-x86_64 -m 512 -hda /home/lm/kvm/winxp.img -localtime -net nic,vlan=0,macaddr=52-54-00-12-34-01 -net tap,vlan=0,ifname=tap0,script=no -boot c -smp 2 -clock rtc -soundhw es1370

Then you can use the IP address in the client. However, the KVM video card cannot be used. You can use rdesktop to connect remotely (the IP address of the plane is set to the gw ip address specified by br0)

Code 1:

Rdesktop 192.168.1.1: 3389-u administrator-P ******-G 1280x750-d-r sound: Local \ resolution can be set by yourself, is it better than virtualbox's seamless connection mode ??

Code 2: rdesktop localhost-u username-P username-G 1024x768-z-D-n-k En-us-r clipboard: primaryclipboard-r sound: Local

When using remote connection, add-redir TCP: 3389: 3389 to map port 3389 of the passenger plane to the host machine and use localhost to connect remotely. For example: sudo/usr/local/KVM/bin/qemu-system-x86_64-M 512-hda/home/lm/KVM/WINXP. IMG-localtime-net Nic, VLAN = 0, macaddr = 52-54-00-12-34-01-net tap, VLAN = 0, ifname = tap0, script = No-boot C-SMP 2-clock RTC-soundhw es1370-redir TCP: 3389: 3389

Note 1: add the user to the UML-net group. Otherwise, you may encounter cocould not open/dev/NET/TUN: no virtual network emulation this is caused by no/dev/NET/TUN read/write permission, such as no tun. ko compiles the kernel. Make menuconfig select Network Device Support-> universal tun/TAP Device Driver support; dummy Network Driver support; bonding Driver Support (both set to m); If ls
If/dev/NET/TUN has returned information, sudo chmod o + RW (or 0666)/dev/NET/tun.
Add the UML-net group code:
$ Sudo useradd <userid> UML-Net

In this way, IP address forwarding can be performed on the host machine through the KVM virtual machine.

Supplement:
If multiple Guest OS are running at the same time, you need to modify the network settings and add several tap interfaces to/etc/Network/interfaces. Each guest OS uses a single tap, for example, if you want to run three guest OS at the same time, the configuration file is as follows:

Code:

Auto tap0iface tap0 Inet manualup ifconfig $ iface 0.0.0.0 updown ifconfig $ iface downunctl_user lm \ lm is my user name. Here we change it to your user name

Auto tap1
Iface tap1 Inet Manual
Up ifconfig $ iface 0.0.0.0 up
Down ifconfig $ iface down
Tunctl_user lm \ lm is my user name. Here, replace it with your user name.

Auto tap2
Iface tap2 Inet Manual
Up ifconfig $ iface 0.0.0.0 up
Down ifconfig $ iface down
Tunctl_user lm \ lm is my user name. Here, replace it with your user name.

Auto br0
Iface br0 Inet static \ can also be allocated using DHCP.
Bridge_ports eth0 tap0 tap1 tap2
Address 192.168.1.3
Netmask 255.255.255.0
Network 192.168.1.1
Broadcast 192.168.1.255
Gateway 192.168.1.1

Start Guest OS

Code:

sudo /usr/local/kvm/bin/qemu-system-x86_64 -m 512 -hda /home/lm/kvm/winxp.img -localtime -net nic,vlan=0,macaddr=52-54-00-12-34-01 -net tap,vlan=0,ifname=tap0,script=no -boot c -smp 2 -clock rtc -soundhw es1370

Change ifname = tap0 to tap1 or tap2, and change Mac ..

Note that the KVM kernel module must be reloaded after the system is restarted:

Code:

Sudo modprobe kvmsudo modprobe KVM-AMD // if you are using an AMD processor sudo modprobe KVM-Intel // if you are using an Intel processor

Of course, you can also modify the system settings to automatically load the module at startup.
Similarly, you can use this method to install Linux. After the installation, we can compare it. Is it much better than VB and Vm?

For other problems such as USB connection, refer to the posts in the Forum.

However, KVM still has many disadvantages. I have not successfully installed the Solaris System on KVM (the clock may not be synchronized ), in other cases, the system clock is not synchronized in Windows KVM (which may cause Windows Guest to run slowly ).

I have run four centos 4.6 and one WINXP SP3 and one win2003 SP2 and five FreeBSD 7.0 in my system at the same time.
The speed is too fast, incredible.
The system configuration is: Ubuntu 8.04.1 64bit for athlon X2 5000 + 4g RAM running

In fact, KVM is easy to install and use. You need to understand the meaning of each KVM parameter. The most important thing is the KVM network bridging settings. According to the above, many things on the Internet have no effect, in the end, the network bridging Settings section of virtualbox's official user documentation was successfully referenced. Here, you can read the software's own documents, which will be of great help.

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.