大网数据广告活动
服务器运维问答

Can I have my KVM guests on the same subnet as the host?

· 52CE 我爱测

Using virtual network "default" I get the guests on their own subnet, NAT'ed to the host's subnet. Using a separate bridge, it seems possible to have guests on the same subnet as the host, but apparently this requires a dedicated…

问题原文

原帖链接 · Trygve Flathen · CC BY-SA 4.0

Using virtual network "default" I get the guests on their own subnet, NAT'ed to the host's subnet.

Using a separate bridge, it seems possible to have guests on the same subnet as the host, but apparently this requires a dedicated physical nic on the host?

I have experimented with macvtap vepa or bridge, but could not get a link this way.

Is it possible to have the guests appear just like any other physical machine on the same subnet as the host? And if so, how? I need this as my application uses broadcast communication.

I am using QEMU/KVM, on rhel and ubuntu. Guests are also rhel or ubuntu. I define/manage the VMs using virt-install, virsh (and virt-manager for testing/debugging). The server does not have any extra nic's available for these purposes, only the one used by the host itself.

已采纳解答

原帖链接 · Mikael H · CC BY-SA 4.0

Process on Ubuntu 20.04:

Set up the logical network bridge on the host

Create /etc/netplan/01-kvmbridge.yaml. Example:

network:
  ethernets:
    enp2s0f0:
      dhcp4: false
  bridges:
    br0:
      interfaces: [enp2s0f0]
      dhcp4: true
      mtu: 1500
      parameters:
        stp: true
        forward-delay: 15

Notes: NIC name will differ depending on driver. Address assignment doesn't have to be by DHCP.

Run sudo netplan try to test the config and sudo netplan apply to apply it once you're satisfied it works. Note that changing a network config over ssh may not be a good idea.

Tell KVM how to access the connection

Create a file ~/kvmbridge.xml with the following contents:

<network>
  <name>host-bridge</name>
  <forward mode="bridge"/>
  <bridge name="br0"/>
</network>

Enable the bridge:

virsh net-define ~/kvmbridge.xml
virsh net-start host-bridge
virsh net-autostart host-bridge

You should now be able to select the network host-bridge for your VMs to have them coexist on the same network as the host.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2021-08-23)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。