KVM 桥接问题

KVM 桥接问题

http://www.linux-kvm.com/content/using-bridged-networking-virt-manager

[@more@]

Using bridged networking with Virt-manager

In previous posts you can find instructions on how to configure bridged networking when managing your kvm guests by command line. However for many users experimenting with kvm, the virt-manager GUI tool is the preferred method of managing kvm guests in which case bridged networking configuration might pose a challenge. If you fall into the camp of users who prefer virt-manager and have ever wondered how to configure bridged networking , you’ll be able to use bridged networking with virt-manager after reading this post.

niccard.jpg

1. Configure your bridge

Your libvirt installation will provide default bridges for use with xen, qemu and other types of domains. For qemu/kvm, the default bridge should be called vnet0 and you can verify this by issuing the following command on your system.

# brctl show

bridge name bridge id STP enabled interfaces
pan0 8000.000000000000 no
virbr0 8000.000000000000 yes
vnet0 8000.000000000000 yes

Th first thing you need to do is add a network script for your vnet0 bridge. On Fedora this script will be located under /etc/sysconfig/network-scripts/ but may differ for other linux distributions. So go ahead and create a new script at /etc/sysconfig/network-scripts/ifcfg-vnet0 as root user and edit the contents so that it looks like the following.

DEVICE=vnet0
TYPE=Bridge
BOOTPROTO=dhcp
ONBOOT=yes

This completes set up of your vnet0 bridge.

2. Add your physical interface to the bridge

The next step is to add the physical interface that your kvm guest will be sharing to the vnet0 bridge configured above. For this post, we’ll assume that you’ll be using eth0 so to add eth0 to vnet0 bridge, issue the following command.

# brctl addif vnet0 eth0  

You can verify that your eth0 was added to the vnet0 bridge issuing the brctl show command. Your output should look similar to the following.

# brctl show

bridge name bridge id STP enabled interfaces
pan0 8000.000000000000 no
virbr0 8000.000000000000 yes
vnet0 8000.0019b97ec863 yes eth0

Now you need to configure your network script for eth0. You will already have a script for eth0, but you’ll need to modify it by adding one line as BRIDGE=vnet0 so that it looks similar to the following script.

# Broadcom Corporation BCM4401-B0 100Base-TX
DEVICE=eth0
BRIDGE=vnet0
BOOTPROTO=dhcp
HWADDR=00:19:b9:7e:c8:63
ONBOOT=yes
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes
NM_CONTROLLED=no

3. Restart your network services

In order for all the network script modifications to take effect, you need to restart your network services. Your command may differ slightly but for most linux distributions the following command will restart your network services.

# /etc/rc.d/init.d/network restart

Shutting down interface vnet0: [ OK ]
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
Bringing up interface vnet0:
Determining IP information for vnet0... done.
[ OK ]

My experience is that the dhcp on the bridge device usually takes a little longer than the other scripts so don’t worry if the line that says “determining ip information for vnet0” sits there for a min or two. Once this script completes, you’re finished with your system network configurations. Now, onto actually using bridged networking with virt-manager.

4. Configure Bridged Networking in Virt-Manager

Now comes the easy part. Configure your kvm guest in virt-manager as you normally would. When you get to the part that asks about your network type, choose to share with a physical device and you will be able to select the eth0 on bridge vnet0. Below is a screenshot of what you should see. You don’t need to specify a specific mac address unless you need to for some kind of static mapping.

virt-manager-bridged.png

Boot up your kvm guest which will be now connected to your local network. Your brctl show command will now show your kvm guest network added to your vnet0 bridge. Below is a sample output.

# brctl show

bridge name bridge id STP enabled interfaces
pan0 8000.000000000000 no
virbr0 8000.000000000000 yes
vnet0 8000.0019b97ec863 yes eth0
vnet1

Summary

Bridged networking with virt-manager is simpler than configuring bridged networking when managing kvm guests with command line since you don’t have to worry about things like qemu network scripts and generating random mac addresses. Virt-manager takes care of these things behind the scenes. What will be nice to see someday would be GUI tools for managing the bridges which would make the procedure even simpler.

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9697/viewspace-1031675/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/9697/viewspace-1031675/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值