摘要
RHEL6桥接网络,使KVM虚拟主机上网
[root@devilkin Desktop]# brctl show
bridge name bridge id STP enabled interfaces
virbr0 8000.c6e518fd7788 yes vnet0
vnet1
[root@devilkin Desktop]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 * 255.255.255.0 U 1 0 0 eth0
192.168.122.0 * 255.255.255.0 U 0 0 0 virbr0
default 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
[root@devilkin Desktop]# nm-tool
NetworkManager Tool
State: connected
- Device: eth0 [System eth0] --------------------------------------------------
Type: Wired
Driver: sky2
State: connected
Default: yes
HW Address: 00:30:18:A7:5C:8E
Capabilities:
Carrier Detect: yes
Speed: 100 Mb/s
Wired Properties
Carrier: on
IPv4 Settings:
Address: 192.168.1.102
Prefix: 24 (255.255.255.0)
Gateway: 192.168.1.1
DNS: 61.139.2.69
DNS: 58.62.207.18
我们可以看到当前的网络,只有eth0和virbr0两个网卡在工作,其它virbr0是KVM的虚拟桥接网卡
接下来,我们需要对eth0网卡配置成一个桥接网络,首先我们需要安装一个软件包
bridge-utils
可以通过 rpm -qa bridge-utils 查看是否已经安装。
接下来,我们要添加一个桥接的配置文件和修改一下ifcfg-eth0的配置文件
[root@devilkin network-scripts]# vim ifcfg-eth0
[root@devilkin network-scripts]# pwd
/etc/sysconfig/network-scripts
=======================
DEVICE=eth0
NM_CONTROLLED=yes
ONBOOT=yes
#BRIDGE="public"
TYPE=Ethernet
BOOTPROTO=dhcp
HWADDR=00:30:18:A7:5C:8E
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"
UUID=5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03
USERCTL=no
修改成:
DEVICE="eth0"
HWADDR="00:30:18:A7:5C:8E"
NM_CONTROLLED="no"
ONBOOT="yes"
BRIDGE="public"
TYPE="Ethernet"
BOOTPROTO="none"
添加一个 ifcfg-public 配置文件(作为桥接的网络)
[root@devilkin network-scripts]# cat ifcfg-public
DEVICE="public"
HWADDR="00:30:18:A7:5C:8E"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Bridge"
BOOTPROTO="dhcp" #动态IP
#BOOTPROTO=static 静态IP
#IPADDR= IP地址
#NETMASK= 子网掩码
#GATEWAY= 网关
#DNS1= DNS
DELAY="0"
重启网络:/etc/init.d/network restart
查看桥接的网络
[root@devilkin Desktop]# brctl show
bridge name bridge id STP enabled interfaces
public 8000.003018a75c8e no eth0
virbr0 8000.c6e518fd7788 yes vnet0
vnet1
============手动的绑定网卡===========
[root@devilkin Desktop ~]# brctl delif virbr0 vnet0
[root@devilkin Desktop ~]# brctl delif virbr0 vnet1
[root@devilkin Desktop ~]# brctl addif public vnet0
[root@devilkin Desktop ~]# brctl addif public vnet1
[root@devilkin Desktop ~]# brctl show
==============================
[root@devilkin Desktop]# brctl show
bridge name bridge id STP enabled interfaces
public 8000.003018a75c8e no eth0
vnet0
vnet1
virbr0 8000.c6e518fd7788 yes
查看网关
[root@devilkin Desktop]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 * 255.255.255.0 U 0 0 0 public
192.168.122.0 * 255.255.255.0 U 0 0 0 virbr0
link-local * 255.255.0.0 U 1008 0 0 public
default 192.168.1.1 0.0.0.0 UG 0 0 0 public
然后要在/etc/rc.local的文件里面写入/etc/init.d/network restart
然后重启计算机,KVM和真机都可以同时上网了。
如果不写会出现以下情况。
============出现的问题=========
[root@devilkin Desktop]# ping www.baidu.com
ping: unknown host www.baidu.com
============解决方法=========
[root@devilkin Desktop]# /etc/init.d/network restart
正在关闭接口 public: [确定]
正在关闭接口 eth0: [确定]
关闭环回接口: [确定]
弹出环回接口: [确定]
弹出界面 eth0: [确定]
弹出界面 public:
正在决定 public 的 IP 信息...完成。 [确定]
[root@devilkin Desktop]# ping www.baidu.com
PING www.a.shifen.com (119.75.218.45) 56(84) bytes of data.
64 bytes from 119.75.218.45: icmp_seq=1 ttl=52 time=424 ms
RHEL6桥接网络,使KVM虚拟主机上网
[root@devilkin Desktop]# brctl show
bridge name bridge id STP enabled interfaces
virbr0 8000.c6e518fd7788 yes vnet0
vnet1
[root@devilkin Desktop]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 * 255.255.255.0 U 1 0 0 eth0
192.168.122.0 * 255.255.255.0 U 0 0 0 virbr0
default 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
[root@devilkin Desktop]# nm-tool
NetworkManager Tool
State: connected
- Device: eth0 [System eth0] --------------------------------------------------
Type: Wired
Driver: sky2
State: connected
Default: yes
HW Address: 00:30:18:A7:5C:8E
Capabilities:
Carrier Detect: yes
Speed: 100 Mb/s
Wired Properties
Carrier: on
IPv4 Settings:
Address: 192.168.1.102
Prefix: 24 (255.255.255.0)
Gateway: 192.168.1.1
DNS: 61.139.2.69
DNS: 58.62.207.18
我们可以看到当前的网络,只有eth0和virbr0两个网卡在工作,其它virbr0是KVM的虚拟桥接网卡
接下来,我们需要对eth0网卡配置成一个桥接网络,首先我们需要安装一个软件包
bridge-utils
可以通过 rpm -qa bridge-utils 查看是否已经安装。
接下来,我们要添加一个桥接的配置文件和修改一下ifcfg-eth0的配置文件
[root@devilkin network-scripts]# vim ifcfg-eth0
[root@devilkin network-scripts]# pwd
/etc/sysconfig/network-scripts
=======================
DEVICE=eth0
NM_CONTROLLED=yes
ONBOOT=yes
#BRIDGE="public"
TYPE=Ethernet
BOOTPROTO=dhcp
HWADDR=00:30:18:A7:5C:8E
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"
UUID=5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03
USERCTL=no
修改成:
DEVICE="eth0"
HWADDR="00:30:18:A7:5C:8E"
NM_CONTROLLED="no"
ONBOOT="yes"
BRIDGE="public"
TYPE="Ethernet"
BOOTPROTO="none"
添加一个 ifcfg-public 配置文件(作为桥接的网络)
[root@devilkin network-scripts]# cat ifcfg-public
DEVICE="public"
HWADDR="00:30:18:A7:5C:8E"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Bridge"
BOOTPROTO="dhcp" #动态IP
#BOOTPROTO=static 静态IP
#IPADDR= IP地址
#NETMASK= 子网掩码
#GATEWAY= 网关
#DNS1= DNS
DELAY="0"
重启网络:/etc/init.d/network restart
查看桥接的网络
[root@devilkin Desktop]# brctl show
bridge name bridge id STP enabled interfaces
public 8000.003018a75c8e no eth0
virbr0 8000.c6e518fd7788 yes vnet0
vnet1
============手动的绑定网卡===========
[root@devilkin Desktop ~]# brctl delif virbr0 vnet0
[root@devilkin Desktop ~]# brctl delif virbr0 vnet1
[root@devilkin Desktop ~]# brctl addif public vnet0
[root@devilkin Desktop ~]# brctl addif public vnet1
[root@devilkin Desktop ~]# brctl show
==============================
[root@devilkin Desktop]# brctl show
bridge name bridge id STP enabled interfaces
public 8000.003018a75c8e no eth0
vnet0
vnet1
virbr0 8000.c6e518fd7788 yes
查看网关
[root@devilkin Desktop]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 * 255.255.255.0 U 0 0 0 public
192.168.122.0 * 255.255.255.0 U 0 0 0 virbr0
link-local * 255.255.0.0 U 1008 0 0 public
default 192.168.1.1 0.0.0.0 UG 0 0 0 public
然后要在/etc/rc.local的文件里面写入/etc/init.d/network restart
然后重启计算机,KVM和真机都可以同时上网了。
如果不写会出现以下情况。
============出现的问题=========
[root@devilkin Desktop]# ping www.baidu.com
ping: unknown host www.baidu.com
============解决方法=========
[root@devilkin Desktop]# /etc/init.d/network restart
正在关闭接口 public: [确定]
正在关闭接口 eth0: [确定]
关闭环回接口: [确定]
弹出环回接口: [确定]
弹出界面 eth0: [确定]
弹出界面 public:
正在决定 public 的 IP 信息...完成。 [确定]
[root@devilkin Desktop]# ping www.baidu.com
PING www.a.shifen.com (119.75.218.45) 56(84) bytes of data.
64 bytes from 119.75.218.45: icmp_seq=1 ttl=52 time=424 ms