如何共享 VPN 连接到私有子网中的实例?

how to share VPN connection to instances in private subnet?

我创建了 2 个实例:

我按照本指南进行操作,并且可以正常使用。 VM-B 可以访问互联网(通过 VM-A):https://aws.amazon.com/premiumsupport/knowledge-center/vpc-nat-instance/

VM-A 我已经设置了 OpenVPN,它可以连接到我们办公室的 VPN 服务器。

现在我希望 VM-B 能够使用 VM-A 的 VPN 连接来访问我们办公室的机器但我找不到方法。

我想我知道为什么它不起作用,因为在 VM-B 的路由 table 中我有:

Destination    Target
10.0.0.0/16    local
0.0.0.0/0      eni-xxxx

网络接口 eni-xxxx 属于 VM-A。所以流量就在那里。

相反,我想添加类似这样的内容,但似乎不可能,因为 "tun0" 不是有效的资源 ID:

Destination
10.100.7.2 (network in our office accessible via VPN)

Target
tun0 (the network interface created by OpenVpn)

关于如何解决这个问题有什么建议吗?

附加问题: 使用 "route add" 命令添加路由是一种好习惯,还是使用 VPC 仪表板中的 Web 界面 "Route Tables" 更好?

我找到了解决方案。我在防火墙中遗漏了一条伪装地址的规则。 在 VM-A 上:

# the subnet of VM-B is 10.0.30.0/24
$ sudo iptables -t nat -A POSTROUTING -o tun0 -s 10.0.30.0/24 -j MASQUERADE