ubuntu下配置虚拟机 建立桥接模式

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里面选择这个网桥即可实现虚拟机桥接
请添加图片描述
注意:

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值