ubuntu下配置虚拟机 建立桥接模式
目录
本次配置redhat虚拟机 硬盘文件已有
1.安装虚拟机软件及相关环境
1.1 确认是否支持虚拟环境
cat /proc/cpuinfo | grep -E 'vmx|svm'
vmx 因特尔公司的芯片
svm amd公司芯片的相关服务
1.2 相关软件安装
如果有相关服务进行后安装
sudo apt install qemu qemu-kvm libvirt-bin bridge-utils virt-viewer virt-manager
基本就这些软件 有些我也高不清楚功能
1.3 配置虚拟机
打开virt-manager软件进行配置(和win下面配置VMware虚拟机差别不大)
或者使用命令行创建()
sudo qemu-img create -f qcow2 -b /var/lib/libvirt/images/westos.qcow2 /var/lib/libvirt/images/westosa.qcow2
sudo virt-install \
--memory 1024 \
--vcpus 1 \
--name westos \
--disk /var/lib/libvirt/images/westosa.qcow2,bus=virtio \
--network bridge=virbr0,model=virtio \
--import
这些命令就是创建一个硬盘文件的快照
指定内存 cpu内核数 虚拟机名称 硬盘文件所在地 网络模式选择虚拟服务创建的virbro (NAT模式)
2.虚拟机网络创建
ubuntu 和redhat创建桥接的方法不太一样,如下:
2.1 ubuntu创建桥接模式
2.1.1 ubuntu图形界面创建桥接
图形界面模式使用
nm-connection-editor
参照官网https://www.xmodulo.com/configure-linux-bridge-network-manager-ubuntu.html
但是我尝试了无数遍都不能成功,每次都是创建的桥接现实橙色(等待大佬解惑)
使用以下命令查看目前所有连接
nmcli connection show
于是使用修改配置文件的方法
2.2.2 ubuntu修改配置文件创建桥接
方法详见官网
https://help.ubuntu.com/community/NetworkConnectionBridge#Bridging_Ethernet_Connections_from_the_GUI
安装相关软件
sudo apt-get update
sudo apt-get install bridge-utils
编辑 /etc/network/interfaces 文件
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# Bridge between eth0 and eth1
auto br0
iface br0 inet dhcp
# For static configuration delete or comment out the above line and uncomment the following:
# iface br0 inet static
# address 192.168.1.10
# netmask 255.255.255.0
# gateway 192.168.1.1
# dns-nameservers 192.168.1.5
# dns-search example.com
bridge_ports eth0 eth1
bridge_stp off
bridge_fd 0
bridge_maxwait 0
以上是桥接两个网络的例子 自动获取ip
建立虚拟机所用的br0如下所示
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
# Bridge for redhat
auto br0
# iface br0 inet dhcp
# For static configuration delete or comment out the above line and uncomment the following:
iface br0 inet static
address 172.25.254.66
netmask 255.255.255.0
# gateway 192.168.1.1
# dns-nameservers 192.168.1.5
# dns-search example.com
bridge_ports enp6s0
bridge_stp on
bridge_fd 0
bridge_maxwait 0
修改完后重新启动服务
sudo /etc/init.d/networking restart
可以可看到新创建的网桥:绿色
再去virt-manager里面选择这个网桥即可实现虚拟机桥接
注意: