![如何在 kvm+libvirt 中为虚拟机设置主机虚拟接口(故障转移)?](https://linux22.com/image/773619/%E5%A6%82%E4%BD%95%E5%9C%A8%20kvm%2Blibvirt%20%E4%B8%AD%E4%B8%BA%E8%99%9A%E6%8B%9F%E6%9C%BA%E8%AE%BE%E7%BD%AE%E4%B8%BB%E6%9C%BA%E8%99%9A%E6%8B%9F%E6%8E%A5%E5%8F%A3%EF%BC%88%E6%95%85%E9%9A%9C%E8%BD%AC%E7%A7%BB%EF%BC%89%EF%BC%9F.png)
有一个 Ubuntu Server 20.04 和 2 个地址,一个在eno1
接口中具有第一个默认公共地址,另一个在故障转移中具有第二个地址。
我可以使用名为 netplan 的虚拟接口创建failover1
并且运行良好:
network:
version: 2
ethernets:
eno1:
dhcp4: true
match:
macaddress: xx:xx:xx:xx:xx:xx
set-name: eno1
bridges:
failover1:
addresses:
- xxx.xxx.xxx.xxx/32
dhcp4: true
root@server:~# ip addr
...
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
inet xxx.xxx.xxx.xxx/24 brd xxx.xxx.xxx.xxx scope global dynamic eno1
valid_lft 86125sec preferred_lft 86125sec
...
4: failover1: <BROADCAST,MULTICAST> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
inet xxx.xxx.xxx.xxx/32 scope global failover1
valid_lft forever preferred_lft forever
我的虚拟机使用默认 nat 网络工作正常:
<network>
<name>default</name>
<uuid>...</uuid>
<forward mode='nat'/>
<bridge name='virbr0' stp='on' delay='0'/>
<mac address='xx:xx:xx:xx:xx:xx'/>
<ip address='192.168.122.1' netmask='255.255.255.0'>
<dhcp>
<range start='192.168.122.2' end='192.168.122.254'/>
</dhcp>
</ip>
</network>
使用 Web 浏览器导航时,请使用主要公共地址,但需要使用仅限辅助地址。
我尝试使用以下方法创建物理桥:
<network>
<name>bridged-network</name>
<forward mode="bridge" />
<bridge name="failover1" />
</network>
但是虚拟机无法访问互联网,但从主机使用 wget 可以正常工作:
wget -qO- http://checkip.dyndns.com/ --bind-address xxx.xxx.xxx.xxx
<html><head><title>Current IP Check</title></head><body>Current IP Address: xxx.xxx.xxx.xxx</body></html>
我尝试使用 passthrout,但是不起作用:
<network>
<name>passthrough</name>
<forward mode='hostdev' managed='yes'>
<pf dev='failover1'/>
</forward>
</network>
root@server:~# virsh net-start passthrough
error: Failed to start network passthrough
error: internal error: No usable Vf's present on SRIOV PF failover1
我尝试在模式下使用直接网络设备vepa
:brigde
<interface type='direct'>
<source dev='failover1' mode='vepa'/>
</interface>
但是没有来自虚拟机的互联网连接。
如何为虚拟机设置特定的故障转移地址或接口?