热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

KVM虚拟机如何配置桥接网络

1.ConfigureyourbridgeYourlibvirtinstallationwillprovidedefaultbridgesforusewithxen,qemuandothertypesofdomains.Forqemu/kvm,thedefaultbridgeshouldbecalledvnet0and
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 no
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 no 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.
 
ifconfig一下,你会发现eth0没有了IP,但是vnet0有,并且你依然可以访问外网。
 
4. Configure Bridged Networking in Virt-Manager
Now comes the easy part.
# service libvirtd restart
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.
 FC12 <wbr>KVM虚拟机网络配置-桥接
 
 
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

看到了没vnet1也加入了进来其实它是专门为guest OS服务的网卡。
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.

推荐阅读
  • Docker的安全基准
    nsitionalENhttp:www.w3.orgTRxhtml1DTDxhtml1-transitional.dtd ... [详细]
  • 本文详细介绍了如何在Linux系统上安装和配置Smokeping,以实现对网络链路质量的实时监控。通过详细的步骤和必要的依赖包安装,确保用户能够顺利完成部署并优化其网络性能监控。 ... [详细]
  • 1.如何在运行状态查看源代码?查看函数的源代码,我们通常会使用IDE来完成。比如在PyCharm中,你可以Ctrl+鼠标点击进入函数的源代码。那如果没有IDE呢?当我们想使用一个函 ... [详细]
  • 本文详细介绍了 Dockerfile 的编写方法及其在网络配置中的应用,涵盖基础指令、镜像构建与发布流程,并深入探讨了 Docker 的默认网络、容器互联及自定义网络的实现。 ... [详细]
  • Valve 发布 Steam Deck 的新版 Windows 驱动程序
    Valve 最新发布了针对 Steam Deck 掌机的 Windows 驱动程序,旨在提升其在 Windows 环境下的兼容性、安全性和性能表现。 ... [详细]
  • 本文详细介绍了 GWT 中 PopupPanel 类的 onKeyDownPreview 方法,提供了多个代码示例及应用场景,帮助开发者更好地理解和使用该方法。 ... [详细]
  • 本文将介绍如何编写一些有趣的VBScript脚本,这些脚本可以在朋友之间进行无害的恶作剧。通过简单的代码示例,帮助您了解VBScript的基本语法和功能。 ... [详细]
  • Explore how Matterverse is redefining the metaverse experience, creating immersive and meaningful virtual environments that foster genuine connections and economic opportunities. ... [详细]
  • 本题探讨了一种字符串变换方法,旨在判断两个给定的字符串是否可以通过特定的字母替换和位置交换操作相互转换。核心在于找到这些变换中的不变量,从而确定转换的可能性。 ... [详细]
  • 在 Windows 10 中,F1 至 F12 键默认设置为快捷功能键。本文将介绍几种有效方法来禁用这些快捷键,并恢复其标准功能键的作用。请注意,部分笔记本电脑的快捷键可能无法完全关闭。 ... [详细]
  • 资源推荐 | TensorFlow官方中文教程助力英语非母语者学习
    来源:机器之心。本文详细介绍了TensorFlow官方提供的中文版教程和指南,帮助开发者更好地理解和应用这一强大的开源机器学习平台。 ... [详细]
  • Explore a common issue encountered when implementing an OAuth 1.0a API, specifically the inability to encode null objects and how to resolve it. ... [详细]
  • 技术分享:从动态网站提取站点密钥的解决方案
    本文探讨了如何从动态网站中提取站点密钥,特别是针对验证码(reCAPTCHA)的处理方法。通过结合Selenium和requests库,提供了详细的代码示例和优化建议。 ... [详细]
  • 计算机网络复习:第五章 网络层控制平面
    本文探讨了网络层的控制平面,包括转发和路由选择的基本原理。转发在数据平面上实现,通过配置路由器中的转发表完成;而路由选择则在控制平面上进行,涉及路由器中路由表的配置与更新。此外,文章还介绍了ICMP协议、两种控制平面的实现方法、路由选择算法及其分类等内容。 ... [详细]
  • 本文基于刘洪波老师的《英文词根词缀精讲》,深入探讨了多个重要词根词缀的起源及其相关词汇,帮助读者更好地理解和记忆英语单词。 ... [详细]
author-avatar
端庄的一白_167
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有