我正在尝试(并且很难)设置一个干净的KVM环境: Ubuntu (20.04)主机(带有一个NIC)、多个ubuntu来宾、2个公共IP和每个IP一个Vlan。基本上看上去像:

我的需求是:
我没有找到任何关于如何实现这个架构的在线资源,也没有我的任何尝试。
还没有成功。我认为我可以通过网桥和(NAT) VLAN的正确组合来实现它,但我的一些研究表明,我可能需要使用Iptables路由。
Is可以实现这种结构,如果是,如何实现?
编辑:以使我的需求更加清楚:
Traffic from 0.0.0.0/0 destined to X.X.X.X on port 443 must be forwarded to VM1 in VLAN-1
Traffic from 0.0.0.0/0 destined to X.X.X.X on port 5432 must be forwarded to VM2 in VLAN-1
Traffic from 0.0.0.0/0 destined to Y.Y.Y.Y on port 443 must be forwarded to VM3 in VLAN-2
Traffic from VM1 in VLAN2 destined to 0.0.0.0/0 on any port must be routed through Y.Y.Y.Y ?发布于 2020-10-18 17:20:39
看看您的场景,我假设如下:
Traffic from 0.0.0.0/0 destined to X.X.X.X on port 443 must be forwarded to VM1 in VLAN-1
Traffic from 0.0.0.0/0 destined to X.X.X.X on port 5432 must be forwarded to VM2 in VLAN-1
Traffic from 0.0.0./0 destined to Y.Y.Y.Y on port 443 must be forwarded to VM3 in VLAN-2如果我的假设是正确的,我建议使用iptables。在这种情况下,您将执行端口转发.在KVM主机上执行以下操作:
$ sudo echo "1" > /proc/sys/net/ipv4/ip_forward
$ sudo iptables -t nat -A PREROUTING -p tcp -m tcp -d X.X.X.X --dport 443 -j DNAT --to-destination 10.0.1.1:443 #(VM1 in VLAN1)
$ sudo iptables -t nat -A PREROUTING -p tcp -m tcp -d X.X.X.X --dport 5432 -j DNAT --to-destination 10.0.1.2:5432 #(VM2 in VLAN1)
$ sudo iptables -t nat -A PREROUTING -p tcp -m tcp -d Y.Y.Y.Y --dport 443 -j DNAT --to-destination 10.0.2.3:5432 #(VM3 in VLAN2)
$ sudo iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT #(Allow retrun traffic)https://serverfault.com/questions/1039184
复制相似问题