Debian GNU/Linux 上的虚拟接口之间的路由

Debian GNU/Linux 上的虚拟接口之间的路由

我在两个虚拟接口之间路由时遇到了一些困难。以下是设置。

  • 1个物理接口(eth0 192.168.1.51)
  • 1 个别名接口(eth0:1 192.168.10.1)
  • 1 个别名接口(eth0:2 192.168.20.1)

  • 1 个虚拟机,1 个接口(eth0 192.168.10.2)

  • 1 个虚拟机,1 个接口(eth0 192.168.20.2)

我所做的就是在 192.168.20.0/24 和 192.168.10.0/24 之间路由流量

以此目的:

  1. 在第一个虚拟机上,我添加了一条到 192.168.10.1 的默认路由
  2. 在第二台虚拟机上,我添加了一条到 192.168.20.1 的默认路由

在物理机器上,我将路由(它们会自动添加)添加到相应的网络。

从虚拟机 1 中,我可以 ping 通 192.168.10.1 和 192.168.20.1,但不能 ping 通 192.168.20.2。从第二台虚拟机中,情况也一样 — — 我能 ping 通 192.168.10.1 和 20.1,但不能 ping 通 20.2)

ip 转发已激活:root@expire:~/.ovpn# sysctl -a | grep forward

net.ipv4.conf.all.forwarding = 1
net.ipv4.conf.all.mc_forwarding = 0
net.ipv4.conf.default.forwarding = 1
net.ipv4.conf.default.mc_forwarding = 0
net.ipv4.conf.docker0.forwarding = 1
net.ipv4.conf.docker0.mc_forwarding = 0
net.ipv4.conf.eth0.forwarding = 1
net.ipv4.conf.eth0.mc_forwarding = 0
net.ipv4.conf.lo.forwarding = 1
net.ipv4.conf.lo.mc_forwarding = 0
net.ipv4.conf.tun0.forwarding = 1
net.ipv4.conf.tun0.mc_forwarding = 0
net.ipv4.conf.wlan0.forwarding = 1
net.ipv4.conf.wlan0.mc_forwarding = 0
net.ipv4.ip_forward = 1

有谁能提示一下如何进行吗?

谢谢。

附言:我希望不是使用 iptables

编辑:eth0:1 和 eth0:2 是别名接口,而不是虚拟接口。感谢 Tero Kilkanen

答案1

我认为没有人能让它像这样工作。eth0:N实际上不是一个虚拟接口,而是单个接口的 IP 别名。

虚拟接口由虚拟机管理程序在启动虚拟机时创建。例如,在我的其中一台服务器中,Xenvif2.0在启动虚拟机时会创建一个虚拟接口。

根据您的配置,您在同一个物理接口上拥有多个 IP 网络的地址,这是行不通的。

因此,您需要配置网络,以便您拥有的每个虚拟机在主机端都有自己的接口。您可能希望接口类型为路由。然后主机和客户虚拟机都会在 IPv4 子网中获得 IP 地址。

此后,您可以在虚拟机上配置正常路由。

相关内容