1.创建一个桥接网络
#在服务器上创建一个桥接网络
[root@kvm-server-01 ~]# virsh iface-bridge eth0 br0
Created bridge br0 with attached device eth0
Bridge interface br0 started
[root@kvm-server-01 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BRIDGE="br0"
[root@kvm-server-01 ~]# cat /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE="br0"
ONBOOT="yes"
TYPE="Bridge"
BOOTPROTO="none"
IPADDR="10.0.0.11"
NETMASK="255.255.255.0"
GATEWAY="10.0.0.2"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
DHCPV6C="no"
STP="on"
DELAY="0"
#查看桥接网络信息
[root@kvm-server-01 ~]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.000c296116c9 yes eth0
virbr0 8000.525400e53513 yes virbr0-nic
2.让KVM虚拟主机使用桥接网络br0
- 修改虚拟机的配置文件
centos7.6-2.xml
#修改虚拟机的配置文件
[root@kvm-server-01 ~]# virsh edit centos7.6-2
<interface type='bridge'> #修改network网络类型为bridge
<mac address='52:54:00:f2:98:04'/>
<source bridge='br0'/> #修改网卡名为 network='default' ==> bridge='br0'
#使用console登录
[root@kvm-server-01 opt]# virsh console centos7.6-2
#修改网卡配置
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
BOOTPROTO=none
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=10.0.0.124
PREFIX=24
GATEWAY=10.0.0.2
DNS1=10.0.0.2
#重启网卡
[root@localhost ~]# systemctl restart network
#访问外网测试
[root@localhost ~]# ping -c1 baidu.com
PING baidu.com (39.156.69.79) 56(84) bytes of data.
64 bytes from 39.156.69.79: icmp_seq=1 ttl=128 time=30.1 ms
--- baidu.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 30.114/30.114/30.114/0.000 ms
[root@localhost ~]#
#在本地PC直接连接kvm虚拟机centos7.6-2
[C:\~]$ ssh 10.0.0.124
Connecting to 10.0.0.124:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
WARNING! The remote SSH server rejected X11 forwarding request.
Last login: Thu Jul 30 11:07:55 2020
[root@localhost ~]#