如何通过其他 Linux 机器将流量路由到 VPN

Ste*_*ano 1 routing gateway

在这种情况下,我有两台机器 RasPi 和其他 Ubuntu 服务器。

我的 RasPi (192.168.100.105) 有 Debian 并且已经建立了 UDP openvpn 连接。RasPi 连接到远程 VPN 连接 172.16.199.99。

我尝试使用路由路由此流量:

ubuntu@server:~$ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.100.254  0.0.0.0         UG    0      0        0 eth0
172.16.199.0    192.168.100.105  255.255.255.0   UG    0      0        0 eth0
192.168.100.0    *               255.255.255.0   U     0      0        0 eth0
Run Code Online (Sandbox Code Playgroud)

但不幸的是它不起作用。在 RasPi (192.168.100.105) 上,我可以 ping 172.16.199.99(在 openvpn 中远程 ip)但是在添加此路由后在 Ubuntu 服务器上:

mainframe@server:~$ sudo route add -net 172.16.199.0 netmask 255.255.255.0 gw 192.168.100.105 dev eth0
Run Code Online (Sandbox Code Playgroud)

我应该在 RasPi 上安装任何其他软件包来运行网关吗?

如何运行路由和 RasPi 作为此外部 vpn ip (172.16.199.99) 的网关?

小智 5

路由是双向的。

目前,您只指定了从您的 PC 通过 Pi 并沿着 VPN 到达目的地的数据包的路由。在 VPN 链接的另一端,您还需要为数据包指定路由,以便通过 VPN 向下传输并通过 Pi 到达您的计算机。

后者将是一条类似的路线:

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.100.0   172.16.199.100  255.255.255.0   UG    0      0        0 tun0
Run Code Online (Sandbox Code Playgroud)

IE,:

route add -net 192.168.100.0/24 gw 172.16.199.100
Run Code Online (Sandbox Code Playgroud)

(或任何 IP 地址在您的 VPN 的 Pi 端)。

您的网络拓扑如下所示(黑色部分):

在此处输入图片说明

VPN 连接为蓝色。

您拥有或需要拥有的路线是绿色的。您已经在 PC 上拥有了一个 - 这是您需要添加的服务器上的相反路线。