第一部分 網(wǎng)卡配置
[root@localhost ~]# brctl show
bridge-prac 8000.42ffc4af9663 no tap0
virbr0 8000.525400752ca9 yes virbr0-nic
vnet0
[root@localhost ~]# brctl delif virbr0 vnet0 從virbr0交換機(jī)上刪除網(wǎng)卡vnet0
[root@localhost ~]# brctl addif virbr0 vnet0 在virbr0交換機(jī)上添加網(wǎng)卡vnet0
橋接模式
[root@localhost ~]#cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# vi ifcfg-br0 編輯ifcfg-br0配置文件
TYPE=Bridge
NAME=br0
DEVICE=br0
ONBOOT="yes"
BOOTPROTO=static
IPADDR=192.168.50.10
GATEWAY=192.168.50.2
NETMASK=255.255.255.0
DNS1=114.114.114.114
DNS2=8.8.8.8
[root@localhost network-scripts]# cp ifcfg-ens33 ifcfg-ens33.bak 備份ifcfg-ens3配置文件
[root@localhost network-scripts]# vi ifcfg-ens33 編輯ifcfg-ens3配置文件
DEVICE="ens33"
ONBOOT="yes"
BRIDGE=br0
[root@localhost network-scripts]# systemctl start libvirtd 重啟libvirtd服務(wù)
[root@localhost network-scripts]# systemctl start network 重啟network服務(wù)
第二部分virt manager
[root@localhost ~]# cp /opt/cirros-0.4.0-x86_64-disk.img /var/lib/libvirt/images
創(chuàng)建名為VM-3的虛擬機(jī)
[root@localhost ~]# sudo virt-install
--name=VM-3
--ram=512
--vcpus=1
--disk path=/var/lib/libvirt/images/cirros-0.4.0-x86_64-disk.img,format=qcow2,size=5
--network network=default
--os-type=linux
--os-variant=generic
--graphics none
--console pty,target_type=serial
--boot hd
[root@localhost ~]# virsh start VM-3 開(kāi)啟VM-3虛擬機(jī)
$ sudo ifconfig eth1 192.168.50.11 netmask 255.255.255.0 配置地址
$ sudo route add default gw 192.168.50.2 dev eth1 修改網(wǎng)關(guān)轮洋,使得流量默認(rèn)走eth1
$ route
$ ping -I eth1 192.168.50.2 -c 4
[root@localhost ~]# virsh destroy VM-3 強(qiáng)制關(guān)閉虛擬機(jī)VM-3
Domain VM-3 destroyed
第三部分 刪除橋接網(wǎng)卡
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# rm -rf ifcfg-br0 刪除網(wǎng)絡(luò)br0
[root@localhost network-scripts]# rm -rf ifcfg-ens33 刪除網(wǎng)絡(luò)ens33
[root@localhost network-scripts]# cp ifcfg-ens33.bak ifcfg-ens33 還原備份文件ens33
[root@localhost network-scripts]# systemctl restart libvirtd 重啟libvirtd服務(wù)
[root@localhost network-scripts]# systemctl restart network 重啟網(wǎng)絡(luò)
重啟系統(tǒng)
[root@localhost ~]# virsh start VM-3 啟動(dòng)虛擬機(jī)VM-3
第四部分 創(chuàng)建nat網(wǎng)絡(luò)
[root@localhost ~]# cd /etc/libvirt/qemu/networks/
[root@localhost networks]# cp default.xml nat1.xml
[root@localhost networks]# uuidgen
8f91a490-b803-4121-b9b9-d9c71006cc2d
[root@localhost networks]# vi nat1.xml
[root@localhost networks]# systemctl restart libvirtd
[root@localhost networks]# virsh start VM-3
Domain VM-3 started
$ sudo ifconfig eth1 192.168.120.5 netmask 255.255.255.0 配置地址
$ sudo route add default gw 192.168.120.1 dev eth1 修改網(wǎng)關(guān)肘交,使得流量默認(rèn)走eth1
$ route
$ ping www.baidu.com