KVM 宿主机上创建桥接网络 宿主机上执行#virsh iface-bridge etho br0 只能执行一次 创建名为bridge的网桥设备,并将现有网络设备接口附加到新网桥。新桥默认立即启动, 在启用STP且延迟为0的情况下;这些设置可以通过--no STP、--no start和延迟的整数秒数进行更改。所有IP地址 接口配置将移至新的桥接设备 iface-bridge interface bridge [--no-stp] [delay] [--no-start] Create a bridge device named bridge, and attach the existing network device interface to the new bridge. The new bridge defaults to starting immediately, with STP enabled and a delay of 0; these settings can be altered with --no-stp, --no-start, and an integer number of seconds for delay. All IP address configuration of interface will be moved to the new bridge device.

See also iface-unbridge for undoing this operation.

~~ 有的可能会遇到报错如下:失败并且 终端断开连接,不要慌有解决办法
 [root@localhost centos6.9-4]# virsh iface-bridge ens33 br0

使用附加设备 br0 生成桥接 ens33 失败

Socket error Event: 32 Error: 10053. Connection closing...Socket close.

Connection closed by foreign host.~~ *解决办法 ** 登上宿主机打开终端执行重启网络服务命令 皆可解决 CentOS7#systemctl restart network CentOS8 #nmcli connection reload ens160 #nmcli connention up ens160 执行后Xshell重新连接 ,可以连上检查网络已有桥接网络 br0 [root@localhost ~]# grep -i "." /etc/sysconfig/network-scripts/ifcfg- /etc/sysconfig/network-scripts/ifcfg-br0:DEVICE="br0" /etc/sysconfig/network-scripts/ifcfg-br0:ONBOOT="yes" /etc/sysconfig/network-scripts/ifcfg-br0:TYPE="Bridge" /etc/sysconfig/network-scripts/ifcfg-br0:BOOTPROTO="none" /etc/sysconfig/network-scripts/ifcfg-br0:IPADDR="10.1.3.2" /etc/sysconfig/network-scripts/ifcfg-br0:NETMASK="255.255.255.0" /etc/sysconfig/network-scripts/ifcfg-br0:GATEWAY="10.1.3.254" /etc/sysconfig/network-scripts/ifcfg-br0:IPV6INIT="yes" /etc/sysconfig/network-scripts/ifcfg-br0:IPV6_AUTOCONF="yes" /etc/sysconfig/network-scripts/ifcfg-br0:DHCPV6C="no" /etc/sysconfig/network-scripts/ifcfg-br0:STP="on" /etc/sysconfig/network-scripts/ifcfg-br0:DELAY="0" /etc/sysconfig/network-scripts/ifcfg-ens33:DEVICE="ens33" /etc/sysconfig/network-scripts/ifcfg-ens33:ONBOOT="yes" /etc/sysconfig/network-scripts/ifcfg-ens33:BRIDGE="br0" /etc/sysconfig/network-scripts/ifcfg-ens33.bak:TYPE="Ethernet" /etc/sysconfig/network-scripts/ifcfg-ens33.bak:PROXY_METHOD="none" /etc/sysconfig/network-scripts/ifcfg-ens33.bak:BROWSER_ONLY="no" /etc/sysconfig/network-scripts/ifcfg-ens33.bak:BOOTPROTO="none" /etc/sysconfig/network-scripts/ifcfg-ens33.bak:DEFROUTE="yes" /etc/sysconfig/network-scripts/ifcfg-ens33.bak:IPV4_FAILURE_FATAL="yes" /etc/sysconfig/network-scripts/ifcfg-ens33.bak:IPV6INIT="yes" /etc/sysconfig/network-scripts/ifcfg-ens33.bak:IPV6_AUTOCONF="yes" /etc/sysconfig/network-scripts/ifcfg-ens33.bak:IPV6_DEFROUTE="yes" /etc/sysconfig/network-scripts/ifcfg-ens33.bak:IPV6_FAILURE_FATAL="no" /etc/sysconfig/network-scripts/ifcfg-ens33.bak:IPV6_ADDR_GEN_MODE="stable-privacy" /etc/sysconfig/network-scripts/ifcfg-ens33.bak:NAME="ens33" /etc/sysconfig/network-scripts/ifcfg-ens33.bak:UUID="68f524ae-37f5-4924-8c2b-c1f9042b13d9" /etc/sysconfig/network-scripts/ifcfg-ens33.bak:DEVICE="ens33" /etc/sysconfig/network-scripts/ifcfg-ens33.bak:ONBOOT="yes" /etc/sysconfig/network-scripts/ifcfg-ens33.bak:IPADDR="10.1.3.2" /etc/sysconfig/network-scripts/ifcfg-ens33.bak:PREFIX="24" /etc/sysconfig/network-scripts/ifcfg-ens33.bak:GATEWAY="10.1.3.254" /etc/sysconfig/network-scripts/ifcfg-ens33.bak:DNS1="8.8.8.8" /etc/sysconfig/network-scripts/ifcfg-ens33.bak:IPV6_PRIVACY="no" /etc/sysconfig/network-scripts/ifcfg-lo:DEVICE=lo /etc/sysconfig/network-scripts/ifcfg-lo:IPADDR=127.0.0.1 /etc/sysconfig/network-scripts/ifcfg-lo:NETMASK=255.0.0.0 /etc/sysconfig/network-scripts/ifcfg-lo:NETWORK=127.0.0.0 /etc/sysconfig/network-scripts/ifcfg-lo:# If you're having problems with gated making 127.0.0.0/8 a martian, /etc/sysconfig/network-scripts/ifcfg-lo:# you can change this to something else (255.255.255.255, for example) /etc/sysconfig/network-scripts/ifcfg-lo:BROADCAST=127.255.255.255 /etc/sysconfig/network-scripts/ifcfg-lo:ONBOOT=yes /etc/sysconfig/network-scripts/ifcfg-lo:NAME=loopback [root@localhost ~]# ll /etc/sysconfig/network-scripts/ifcfg- -rw-r--r--. 1 root root 187 12月 31 15:55 /etc/sysconfig/network-scripts/ifcfg-br0 -rw-------. 1 root root 41 12月 31 15:55 /etc/sysconfig/network-scripts/ifcfg-ens33 -rw-r--r--. 1 root root 395 7月 8 06:58 /etc/sysconfig/network-scripts/ifcfg-ens33.bak -rw-r--r--. 1 root root 254 8月 24 2018 /etc/sysconfig/network-scripts/ifcfg-lo 通过man iface-bridge 查看命令用法

虚机网络设置 #virsh destroy vm1 #virsh edit vm1 编辑文件两处如下截图

#virsh start vm1 启动虚机 为虚机设置IP编辑网络配置文件或者配置DHCP自动获取(上层网络编辑器是否开启DHCP) 查看虚机内部网络信息 #virsh [root@localhost ~]# virsh 欢迎使用 virsh,虚拟化的交互式终端。

输入:'help' 来获得命令的帮助信息 'quit' 退出

virsh # iface- iface-begin iface-commit iface-destroy iface-edit iface-mac iface-rollback iface-unbridge
iface-bridge iface-define iface-dumpxml iface-list iface-name iface-start iface-undefine
virsh # net-list 名称 状态 自动开始 持久

default 活动 是 是

virsh # net-edit default 未更改网络 default XML 配置

virsh #