1.宿主机设置
brctl show #查看桥接网卡
brctl addbr br0 #添加桥接网卡br0
brctl addif br0 eth0 #将br0桥接到eth0网卡上
ip addr del dev eth0 10.0.0.20/24 #删除eth0网卡ip地址
ifconfig br0 10.0.0.20/24 up #设置br0网卡ip地址并启用
route add default gw 10.0.0.1 #设置网关
ping baidu.com #测试联网
注意:生产场景中需要将以上操作用脚本执行,因为中途会删除eth0的ip地址导致连接断开。
2.虚拟机网卡配置文件修改
virsh list --all #显示虚拟机列表
virsh edit CentOS-x86_64 #修改虚拟机参数
修改前:
<interface type='network'>
<mac address='52:54:00:31:79:4b'/>
<source network='default'/>
修改后:
<interface type='bridge'>
<mac address='52:54:00:31:79:4b'/>
<source bridge='br0'/>
3.虚拟机设置
vi /etc/sysconfig/network-scripts/ifcfg-eth0 #添加ip等信息
systemctl restart network #重启网卡