linux kvm虚拟机 NAT/BRIDGE配置

宿主机网卡配置:

NAT模式安装KVM时候,已经默认配置好了。如果没有:

找回NAT:

#virsh net-define /usr/share/libvirt/networks/default.xml        //目标:/etc/libvirt/storage/default.xml

#virsh net-autostart defalut                                                         //目标:/etc/libvirt/storage/autostart/default.xml

#virsh net-start default

[[email protected] ~]# virsh net-list

??§°               ???     èa?¨???§  Persistent

--------------------------------------------------

default              ?′??¨     yes           yes

[[email protected] ~]#

BRIDGE模式,BRIDGE重点:

禁用NetworkManager工具,启用自带的network服务

chkconfig NetworkManager off

chkconfig network on

service NetworkManager stop

测试时,注意关闭宿主机与虚拟机的防火墙等,待测试完后再配置。

宿主机网卡:

[[email protected] ~]# cat /etc/sysconfig/network-scripts/ifcfg-br0

DEVICE=br0

TYPE=Bridge

#UUID=498400a2-bc2d-4680-963d-d0a585cdde5b

ONBOOT=yes

NM_CONTROLLED=yes

BOOTPROTO=static

DEFROUTE=yes

IPV4_FAILURE_FATAL=yes

IPV6INIT=no

#NAME="System eth4"

#HWADDR=70:E2:84:0F:08:18

IPADDR=192.168.0.239

NETMASK=255.255.254.0

NETWORK=192.168.0.0

PREFIX=23

GATEWAY=192.168.1.1

DNS1=61.139.2.69

LAST_CONNECT=1438859818

[[email protected] ~]#

[[email protected] ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth4

DEVICE=eth4

TYPE=Ethernet

#UUID=498400a2-bc2d-4680-963d-d0a585cdde5b

ONBOOT=yes

#NM_CONTROLLED=yes

#BOOTPROTO=static

#DEFROUTE=yes

#IPV4_FAILURE_FATAL=yes

#IPV6INIT=no

#NAME="System eth4"

HWADDR=70:E2:84:0F:08:18

#IPADDR=192.168.0.239

#NETMASK=255.255.254.0

#PREFIX=23

#GATEWAY=192.168.1.1

#DNS1=61.139.2.69

#LAST_CONNECT=1438859818

BRIDGE="br0"

[[email protected] ~]#

重启network服务之后

service network restart

出现“Master connection not found or invalid”网络错误

关闭NetworkManager,重起网络

service NetworkManager stop

service network restart

[[email protected] ~]# brctl show

bridge name     bridge id        STP enabled     interfaces

br0             8000.70e2840f0818       no              eth4

vnet0

virbr0        8000.52540097dc51       yes             virbr0-nic

bridge br0 已经搭建完成,eth4与虚拟机启动时候产生的vnet0已经在br0中

[[email protected] ~]# route -n

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0

192.168.0.0     0.0.0.0         255.255.254.0   U     0      0        0 br0

169.254.0.0     0.0.0.0         255.255.0.0     U     1009   0        0 br0

0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 br0

[[email protected] ~]#

虚拟机网卡配置:

IPADDR=192.168.0.237

NETMASK=255.255.254.0

NETWORK=192.168.0.0

GATEWAY=192.168.1.1

DNS1=61.139.2.69

-----------------------------------------------------------------------------------

其他参考:

RHEL 6 Virtual Networks and Network Bridges

from:     http://www.techotopia.com/index.php/Creating_an_RHEL_6_KVM_Networked_Bridge_Interface

A KVM virtual machine running on RHEL 6 has two options in terms of networking connectivity.

One option is for it to be connected to a virtual network running within the operating system of the host computer. In this configuration any virtual machines on the virtual network can see each other but access to the external network is provided by Network
Address Translation (NAT). When using the virtual network and NAT, each virtual machine is represented on the external network (the network to which the host is connected) using the IP address of the host system. This is the default behavior for KVM virtualization
and requires no additional configuration, other than selecting the Virtual network option on the Network screen of the virt-manager new virtual machine wizard. Typically, a single virtual network is created by default, represented by the name default and the
device virbr0.

In order for guests to appear as individual and independent systems on the external network (i.e. with their own IP addresses), they must be configured to share a physical network interface on the host. This is achieved by configuring a network bridge interface
on the host system to which the guests can connect. In the remainder of this chapter we will cover the steps necessary to configure an RHEL 6 network bridge for use by KVM based guest operating systems.

Creating an RHEL 6 Network Bridge

The creation of a network bridge involves the use of the bridge-utils package. Begin by checking if this is already installed by executing the following command:

rpm –q bridge-utils

If the package is not yet installed, install it using yum:

su –

yum install bridge-utils

With this package installed it is time to look at the current network configuration. The easiest way to do this is to run the ifconfig command. The following shows output from running ifconfig on a system on which KVM is installed, but on which a network bridge
has yet to be configured:

eth0      Link encap:Ethernet  HWaddr 00:13:72:0B:14:57

inet addr:192.168.2.18  Bcast:255.255.255.255  Mask:255.255.255.0

inet6 addr: fe80::213:72ff:fe0b:1457/64 Scope:Link

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

RX packets:14715 errors:0 dropped:0 overruns:0 frame:0

TX packets:8586 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:100

RX bytes:19628565 (18.7 MiB)  TX bytes:687049 (670.9 KiB)

Memory:fe3e0000-fe400000

lo        Link encap:Local Loopback

inet addr:127.0.0.1  Mask:255.0.0.0

inet6 addr: ::1/128 Scope:Host

UP LOOPBACK RUNNING  MTU:16436  Metric:1

RX packets:8 errors:0 dropped:0 overruns:0 frame:0

TX packets:8 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:480 (480.0 b)  TX bytes:480 (480.0 b)

virbr0    Link encap:Ethernet  HWaddr 62:C1:46:30:92:37

inet addr:192.168.122.1  Bcast:192.168.122.255  Mask:255.255.255.0

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

RX packets:0 errors:0 dropped:0 overruns:0 frame:0

TX packets:24 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:0 (0.0 b)  TX bytes:4187 (4.0 KiB)

In the above output, the entry for eth0 represents a physical network adaptor on the host computer. This is the connection currently used by this host to access the external network. The virbr0 entry represents the virtual network to which guest operating systems
will connect if configured to do so.

In order to provide the option for guest operating systems to share the eth0 connection of the host it is necessary to establish a network bridge between eth0 and the virtual machines.

Begin the bridge creation process by gaining root access and changing directory to the /etc/sysconfig/network-scripts directory:

su –

cd /etc/sysconfig/network-scripts

If the interface to be bridged is currently running it should be taken down before proceeding:

ifdown eth0

The next step is to modify the script file for the physical network device. In this example the device is eth0 so we need to edit the ifcfg-eth0 file to add a BRIDGE= line. For the purposes of this example we will name the interface bridge0:

DEVICE="eth0"

BOOTPROTO="dhcp"

HWADDR="00:13:72:0B:14:57"

IPV6INIT="yes"

IPV6_AUTOCONF="yes"

NM_CONTROLLED="yes"

ONBOOT="yes"

BRIDGE="bridge0"

The next step is to create a script file for the bridge interface. The name of this file must take the form ifcfg-<bridgename> where <bridgename> matches the name of the bridge defined in the BRIDGE= directive outlined above. Given this requirement, we will
name the file ifcfg-bridge0. The contents of this file for this example will read as follows:

DEVICE="bridge0"

TYPE="Bridge"

BOOTPROTO="dhcp"

ONBOOT="yes"

DELAY=0

Note that the DEVICE= line must refer to the bridge name previously specified (i.e. bridge0 in this instance). Save the file and then start up both interfaces:

ifup eth1

ifup bridge0

Using the ifconfig command, the new bridge interface should now be visible:

bridge0   Link encap:Ethernet  HWaddr 00:13:72:0B:14:57

inet addr:192.168.2.18  Bcast:255.255.255.255  Mask:255.255.255.0

inet6 addr: fe80::213:72ff:fe0b:1457/64 Scope:Link

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

RX packets:951 errors:0 dropped:0 overruns:0 frame:0

TX packets:970 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:760584 (742.7 KiB)  TX bytes:139643 (136.3 KiB)

eth0      Link encap:Ethernet  HWaddr 00:13:72:0B:14:57

inet6 addr: fe80::213:72ff:fe0b:1457/64 Scope:Link

UP BROADCAST RUNNING PROMISC MULTICAST  MTU:1500  Metric:1

RX packets:15831 errors:0 dropped:0 overruns:0 frame:0

TX packets:9750 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:100

RX bytes:20420107 (19.4 MiB)  TX bytes:858409 (838.2 KiB)

Memory:fe3e0000-fe400000

lo        Link encap:Local Loopback

inet addr:127.0.0.1  Mask:255.0.0.0

inet6 addr: ::1/128 Scope:Host

UP LOOPBACK RUNNING  MTU:16436  Metric:1

RX packets:11 errors:0 dropped:0 overruns:0 frame:0

TX packets:11 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:816 (816.0 b)  TX bytes:816 (816.0 b)

virbr0    Link encap:Ethernet  HWaddr 62:C1:46:30:92:37

inet addr:192.168.122.1  Bcast:192.168.122.255  Mask:255.255.255.0

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

RX packets:0 errors:0 dropped:0 overruns:0 frame:0

TX packets:24 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:0 (0.0 b)  TX bytes:4187 (4.0 KiB)

Configuring an RHEL 6 Firewall for a Network Bridge

If a firewall is enabled on the RHEL 6 host, it may be necessary to add an iptables rule to allow network traffic via the bridge interface. This is achieved by adding a rule similar to the following to the /etc/sysconfig/iptables configuration file:

-A RH-Firewall-1-INPUT -i bridge0 -j ACCEPT

The change to the firewall will not take effect until the service is restarted, so complete the configuration by running the following command at the prompt in a terminal window:

/sbin/service iptables restart

Configuring a Virtual Machine to use the Network Bridge

During the virtual machine creation process using the virt-manager tool, the network configuration screen will list now Host device eth0 (Bridge ‘bridge0’) under the Advanced options section of the final page of the new virtual machine creation wizard:

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-01 06:32:43

linux kvm虚拟机 NAT/BRIDGE配置的相关文章

linux kvm虚拟机使用

安装配置kvm 1.安装kvm软件包 [[email protected] ~]# yum install kvm python-virtinst libvirt tunctl bridge-utils virt-manager qemu-kvm-tools virt-viewer virt-v2v   2.安装kvm虚拟化管理工具包 [[email protected] ~]# yum install libguestfs-tools 3.查看虚拟化环境 (1)查看虚拟机环境   [[emai

KVM虚拟机之网络配置

kvm虚拟机的网络配置有两种模式:桥接模式和NAT模式. 两种模式区别如下:1)NAT模式:也是用户模式,数据包由NAT方式通过主机的接口进行传送,可以访问公网,但是无法从外部访问虚拟机网络,所以一般不会用到.2)Bridge:也就是桥接模式,这种模式允许虚拟机像一个独立的主机一样拥有网络,外部的机器可以直接访问到虚拟机内部,但需要网卡支持,一般有线网卡都支持. 一.NAT模式配置 nat模式配置比较简单,只需要在启动虚拟机后,更改其虚拟机的网卡配置文件,将"ONBOOT"配置项默认的

虚拟机NAT网络配置

今天虚拟机NAT模式配置网络遇到一个奇葩问题.主机能ping同虚拟机时,虚拟机不能ping同主机.相反虚拟机ping通主机时,主机ping不通虚拟机. 最后花了一个小时,终于可以互通了,做一个记录: 1.主机ip为192.168.1.12 2.虚拟机分配的网段是74,于是我将虚拟机的网卡设置为192.168.74.1 如下图: 3.虚拟机分配的NAT设置网关:192.168.74.1 注意,如果设置为192.168.74.1 会导致主机ping虚拟机通时,虚拟机ping不通主机,反之亦然.所以,

CentOS 6.9下KVM虚拟机网络Bridge(网桥)方式与NAT方式详解(转)

摘要:KVM虚拟机网络配置的两种方式:NAT方式和Bridge方式.Bridge方式的配置原理和步骤.Bridge方式适用于服务器主机的虚拟化.NAT方式适用于桌面主机的虚拟化. NAT的网络结构图: Bridge的网络结构见图: 一.Bridge方式 问题 客户机安装完成后,需要为其设置网络接口,以便和主机网络,客户机之间的网络通信.事实上,如果要在安装时使用网络通信,需要提前设置客户机的网络连接. KVM客户机网络连接有两种方式: 用户网络(User Networking):让虚拟机访问主机

基于Linux命令行KVM虚拟机的安装配置与基本使用

背景 由于生产环境的服务器并不会安装桌面环境,简单操作的图形化安装也不适合批量部署安装.因此,我还是更倾向于在命令下安装配置KVM虚拟机.结合了一些资料和个人使用的状况,我大致列出了一些基本和常用的使用方法. 安装配置 一.环境介绍 操作系统:centos6.6 内核版本:2.6 IP地址:172.16.57.24 二.检查CPU 和 Xen 不同,KVM 需要有 CPU 的支持(Intel VT 或 AMD SVM),在安装 KVM 之前检查一下 CPU 是否提供了虚拟技术的支持 egrep

RHEL7 kvm虚拟机桥接网络配置

摘要:RHEL7 KVM虚拟机网络配置Bridge方式.Bridge方式的配置原理和步骤. Bridge方式适用于服务器主. bridge 的网络结构见图: Bridge方式 问题 客户机安装完成后,需要为其设置网络接口,以便和主机网络,客户机之间的网络通信.事实上,如果要在安装时使用网络通信,需要提前设置客户机的网络连接. KVM 客户机网络连接有两种方式: 用户网络(User Networking):让虚拟机访问主机.互联网或本地网络上的资源的简单方法,但是不能从网络或其他的客户机访问客户机

linux kvm虚拟机快速构建及磁盘类型

KVM命令管理 virsh命令:用来管理各虚拟机的接口命令查看/创建/停止/关闭...支持交互模式格式:virsh 控制指令 [虚拟机名称] [参数] [[email protected] 桌面]# virsh nodeinfo(查看虚拟机服务器的cpu信息)CPU 型号: x86_64CPU: 2CPU 频率: 1900 MHzCPU socket: 2每个 socket 的内核数: 1每个内核的线程数: 1NUMA 单元: 1内存大小: 1906912 KiB[[email protecte

KVM虚拟化笔记(五)------kvm虚拟机控制台登录配置

kvm生成的虚机如果要通过字符界面进行虚拟机控制台操作,需要修改相关的配置文件才能实现.具体步骤如下: (1),添加ttyS0的许可,允许root登录 [[email protected] qemu]# echo "ttyS0" >> /etc/securetty [[email protected] qemu]# echo "ttyS0" >> /etc/securetty [[email protected] qemu]# cat /et

搭建MySQL一主多从————VMware Workstation 虚拟机nat网络配置(一)

运行 VMware Workstation Pro 在桌面找到该图标,双击运行即可,如果没有安装请下载安装.流程编辑 ==>虚拟网络编辑器 ==> VMnet0 如果没有 添加网络 最后设置完后,点击确定即可. 配置虚拟机网络点击确定即可. 原文地址:http://blog.51cto.com/3622288/2083948