A/ 带有以太网的主机 (Fedora 33) 如果eth0
. ip 192.168.18.11(/24)
和
B1/ Kvm guest with ifvnet0
被奴役到virbr101
. ip 192.168.101.88(/24)(手动路由,静态 IP)
或
B2/Kvm guest with ifvnet1
被奴役到virbr102
. ip 192.168.102.210(/24) (virt-manager 路由, DHCP)
使用下面显示的配置,我似乎缺少让它工作的步骤。不知道如何调试我的设置。
会发生什么:
- 从 A,我可以 ping B 和 ssh 进入 B
- 从 B,我可以 ping A
- 从A,我可以ping 192.168.18.1
- 从 B,我无法 ping 192.168.18.1,这就是我现阶段要解决的问题
B1 和 B2 之间的区别在于,如果我 ping 一个命名服务器,例如 google.com,用 B1 它说没有到主机的路由,用 B2 它找到 IP 地址,但没有 ping 回复。
nmcli
使用+ brctl
+的路由网络nft
在主机上,virbr101
:
ip link add virbr101-mac address 52:54:41:0b:00:01 type dummy
brctl addif virbr101 virbr101-mac
文件ifcfg-virbr101
:
DEVICE=virbr101
NAME=virbr101
# Change to 'no' to disable NetworkManager for this interface.
NM_CONTROLLED=yes
ONBOOT=yes
TYPE=Bridge
DELAY=2
STP=on
IPADDR=192.168.101.1
NETMASK=255.255.255.0
激活此界面:
nmcli connection load /etc/sysconfig/network-scripts/ifcfg-virbr101
nmcli connection up virbr101
启用 ip 转发:
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
echo "net.ipv4.conf.all.forwarding=1" >> /etc/sysctl.conf
echo "net.ipv6.conf.all.forwarding=1" >> /etc/sysctl.conf
sysctl -p
使用以下nft
命令路由接口:
delete table ip filter
add table ip filter
add chain ip filter INPUT
add chain ip filter FORWARD
add chain ip filter OUTPUT
add rule ip filter FORWARD oifname "virbr101" ip daddr 192.168.101.0/24 counter accept
add rule ip filter FORWARD iifname "virbr101" ip saddr 192.168.101.0/24 counter accept
add rule ip filter FORWARD iifname "virbr101" oifname "virbr101" counter accept
add rule ip filter FORWARD iifname "virbr101" counter reject
add rule ip filter FORWARD oifname "virbr101" counter reject
路由网络使用virt-manager
网络:
<network>
<name>bridged102</name>
<uuid>2e8d6e42-b70e-43c8-8523-02008070f03c</uuid>
<forward dev="ens3" mode="route">
<interface dev="ens3"/>
</forward>
<bridge name="virbr0" stp="on" delay="0"/>
<mac address="52:54:00:42:1d:e4"/>
<domain name="bridged102"/>
<ip address="192.168.102.1" netmask="255.255.255.0">
<dhcp>
<range start="192.168.102.128" end="192.168.102.254"/>
</dhcp>
</ip>
</network>
访客界面:
<interface type="network">
<mac address="52:54:00:ee:a6:67"/>
<source network="bridged102" portid="238df934-14ac-422e-bfbd-a4047a9444fb" bridge="virbr0"/>
<target dev="vnet1"/>
<model type="virtio"/>
<link state="up"/>
<alias name="net1"/>
<address type="pci" domain="0x0000" bus="0x00" slot="0x08" function="0x0"/>
</interface>
对于virt-manager
解决方案,我遵循了以下示例:libvirt docs // Network XML format // Routed network config