xiaorenwuzyh 2014-03-02
本文讲述如何在Fedora 19下配置桥接网络,使得局域网中的其它机器能够访问KVM中的虚拟机。注:Fedora 19是宿主机器的操作系统。
下面开始!
简而言之是以下几个步骤。
禁用SELinux(参考来源里面建议的,这里我不太推荐禁用SELinux)
虚拟服务端KVM的安装和配置我之前讲过了的,这里就不讲了(标签Fedora下去找吧)。
禁用NetworkManager对网络的管理,改用较为「原始」的network脚本来管理网络。
在KVM中应用桥接网络。
下面详细讲一下第三步这个桥接网络的配置怎么操作的。
先终端下运行ifconfig看看你要桥接起来的网络端口名称(一般是eth0、em0什么的),我这里是p33p1!
终端下依次运行,
su -c 'systemctl disable NetworkManager.service'
su -c 'systemctl enable network.service'
su -c 'systemctl stop NetworkManager.service'
看看/etc/resolv.conf中DNS服务器是否正确,如果缺失nameserver那么运行system-config-network配置好。然后编辑/etc/sysconfig/network-scripts/ifcfg-p33p1(ifcfg-后面跟的是你的网络端口名)这个文件,贴上我的范例供各位参考吧。
view sourceprint?#cat /etc/sysconfig/network-scripts/ifcfg-p33p1
NM_CONTROLLED="no"
BOOTPROTO=none
DEVICE="p33p1"
ONBOOT="yes"
TYPE=Ethernet
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME=Ethernet
HWADDR=20:cf:30:ac:c8:2b
PREFIX0=24
BRIDGE=br0
USERCTL=no
然后新建并编辑/etc/sysconfig/network-scripts/ifcfg-br0文件,内容如下,
view sourceprint?[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
TYPE=Bridge
BOOTPROTO=dhcp
ONBOOT=yes
上面有些具体的值请按照你的实际情况修改。根据我个人的体会的话,把/etc/sysconfig/network-scripts/下ifcfg-开头的文件中不必要的(主要就是无线网络连接过的那几个)删掉,可以避免通过systemctl重启network服务出错。
配置完毕后重启Fedora,再在终端运行ifconfig看看输出是否正确,我的输出如下。
[root@localhost ~]# ifconfig
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.102 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::22cf:30ff:feac:c82b prefixlen 64 scopeid 0x20<link>
ether 20:cf:30:ac:c8:2b txqueuelen 0 (Ethernet)
RX packets 75070 bytes 108005211 (103.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 50912 bytes 4021320 (3.8 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 38492 bytes 8994529 (8.5 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 38492 bytes 8994529 (8.5 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
p33p1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 20:cf:30:ac:c8:2b txqueuelen 1000 (Ethernet)
RX packets 185871 bytes 264517286 (252.2 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 132653 bytes 10686277 (10.1 MiB)
TX errors 0 dropped 0 overruns 0 carrier 1 collisions 0
virbr0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:af:e1:da txqueuelen 0 (Ethernet)
RX packets 45 bytes 5220 (5.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 13 bytes 2649 (2.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
如果这样就表示桥接网络配置完成了。然后修改KVM虚拟机的网络界面配置,把Source deviec改成主机桥接的网络,如下图所示。