VPN服务器无法从外部访问自己

VPN server can't access itself externally

我在 docker 上通过 Google 云 ubuntu 机器使用 softether VPN。当我将我的计算机连接到它的客户端并获取我的外部 IP 时,我得到了 VPN 的 IP,因此 Google 云机器的 IP。

当我尝试连接被Google云防火墙阻止的其他机器时,我可以访问。此外,当我尝试在内部访问 Google 云机器上的服务时,它可以工作,但是当我尝试通过 VPN(在 FW 白名单中)从外部访问 google 云机器时我无法访问。

同样的现象也发生在AWS上。我也试过open vpn也没用

这是我的 docker softether VPN 撰写文件:

version: '3'

services:
  softether:
    image: siomiz/softethervpn
# with host mode - maybe the services on vpn host is not accessible, like http, etc..
    privileged: true
    cap_add:
      - NET_ADMIN
#    network_mode: host
# with normal mode - you cant add any local bridge, but every service on vpn host is accessible
    ports:
      - '500:500/udp'
      - '4500:4500/udp'
      - '1701:1701/tcp'
      - '5555:5555/tcp'
    environment:
      - PSK=${PSK}
      - USERS=${USERS}
    restart: unless-stopped

Google 防火墙规则:

同样,我可以使用内部IP通过浏览器访问机器的服务,但不能使用外部IP。我确定:

  1. FW规则在同一个网络中
  2. 这是入口规则
  3. 外部 IP 正确
  4. 我可以访问其他机器上的其他服务(通过不同的规则)
  5. 在我的计算机上使用 VPN 时,我的外部 IP 地址发生了变化

有什么想法吗?

经过一番思考(并与他人讨论)后,我现在认为这完全是另外一回事。

据我所知,您正在尝试的在技术上是不可能的,因此我将完全更改此答案,将旧答案留在底部。

您有一个主机 VM(在 Compute Engine 中)运行将您的容器用作 VPN,但它是 behind NAT. You can make machines from the Internet (outside your VPC at least) connect succesfully to you VPN. It's NAT'ed by design:

If the network interface has an external IP address assigned to it, Google Cloud automatically performs one-to-one NAT for packets whose sources match the interface's primary internal IP address because the network interface meets the Google Cloud internet access requirements. The existence of an external IP address on an interface always takes precedence and always performs one-to-one NAT, without using Cloud NAT.

这意味着没有实际的外部 IP 连接到您的 VM 的以太网接口(您可以使用 ifconfigip address 命令检查)。

因此 - 当您尝试连接(如果您的 VPN 服务器所在的 VPC 从内部)到自身(但使用它的外部 nat'ed 地址)时,由于路由问题,您将无法连接.

如果你使用 VPC,所有来自外部的连接都通过 GCP 的 NAT 不会“知道”将来自内部的数据包发送到哪里** - 我和一个在几个路由器上试验这个的人谈过结果是一样的——没有联系(使用简单的词)。

如果您想从 VPC 内部连接到您的 VPN 容器 - 使用它的内部地址。我不知道有什么办法。

如果您想在 GCP 中保护您的 VPN 服务器,请考虑为此使用 IAP。 . . .

-.-.-.-.-.-.-.- __ O L D ______ A N S W E R __ -.-.-.-.-.-.-.-

您的 compose 文件看起来没问题,我只建议您尝试更改引号的撇号字符:

    ports:
      - "500:500/udp"
      - "4500:4500/udp"
      - "1701:1701/tcp"
      - "5555:5555/tcp"

如果这不起作用,请检查与您的 Jenkins VM 的连接;

  • 你能从其他机器通过 public IP SSH 连接到它吗?
  • 检查 VM 的内部防火墙设置;
  • 你的容器 运行s 吗? (sudo docker ps)
  • 检查 internal OS firewall ports are open;

您还可以使用 nmap 实用程序检查打开的端口 - 请参阅我在 上的其他回答。

如果这没有帮助,请查看此内容以了解如何 运行 SoftEther VPN in a container