【问题标题】:Server not reachable within a VPN (SNX) out of a Docker container在 Docker 容器外的 VPN (SNX) 内无法访问服务器
【发布时间】:2021-05-22 14:12:09
【问题描述】:

我正在使用最新的 Manjaro 内核:x86_64 Linux 5.10.15-1-MANJARO。

我通过 VPN 连接到我的公司网络。 为此,我使用构建版本 800010003 的 SNX。

当我启动一个应该从公司网络连接到机器的 Docker 容器(Docker 版本 20.10.3,构建 48d30b5b32)时,我收到以下消息。

[maurice@laptop ~]$ docker run --rm alpine ping company-server
ping:错误地址“公司服务器”

使用来自“公司服务器”的 IP 也不起作用。

无论使用名称还是 IP,容器外的 ping 都可以正常工作。

resolv.conf 在我看来是正确的。

[maurice@laptop ~]$ docker run --rm alpine cat /etc/resolv.conf
# 由网络管理器生成
搜索局域网
名称服务器 10.1.0.250
名称服务器 10.1.0.253
名称服务器 192.168.86.1

到目前为止我发现了什么。

如果我将包 glibc 和 lib32-glibc 降级到版本 2.32-5,容器的 ping 功能将再次起作用。由于依赖关系,我还必须将 gcc、gcc-libs 和 lib32-gcc-libs 降级到版本 10.2.0-4。

我尝试了全新的 Pop OS 20.10 安装,同样的问题。 我还用另一个运行良好的 VPN (OpenVPN) 进行了测试。但是,这只是一个测试场景,不能作为替代方案。

我几天来一直在寻找解决方案,但没有找到任何东西。如果有人能帮我解决这个问题,那就太好了。

【问题讨论】:

  • 我正在使用 arch 与您描述的相同问题 操作系统:Manjaro 20.2.1 Nibia 内核:x86_64 Linux 5.10.15-1-MANJARO
  • 我遇到了与描述相同的问题。我还在 aur.archlinux.org snx 软件包站点上添加了一条评论,但还没有得到任何答案。该问题似乎也出现在其他 Linux 发行版上。

标签: linux docker vpn checkpoint


【解决方案1】:

TL;DR: 在内核 >5.8 上,tunsnx 接口不再使用全局范围创建,需要重新创建。救命小脚本https://gist.github.com/Fahl-Design/ec1e066ec2ef8160d101dff96a9b56e8

加长版:

这是我的发现和(临时)修复它的解决方案:

重现步骤:

  • 连接你的 snx 隧道

  • 看到 ping 失败到隧道后面的服务器

    docker run --rm -ti --net=company_net busybox /bin/sh -c "ping 192.168.210.210"
    
  • 运行此命令检查“tunsnx”接口的ip和范围

    ip -o address show "tunsnx" | awk -F ' +' '{print $4 " " $6 " " $8}'
    

如果你得到类似的东西

192.168.210.XXX 192.168.210.30/32 247

或(谢谢 Timz)

192.168.210.XXX 192.168.210.30/32 nowhere

范围设置为“全局”且无法建立连接

要解决此问题,如建议的“ronan lanore”,您需要将范围更改为全局

这可以通过一个像这样的小帮助脚本来完成:

#!/usr/bin/env bash
#
# Usage: [dry_run=1] [debug=1] [interface=tunsnx] docker-fix-snx
#
# Credits to: https://github.com/docker/for-linwux/issues/288#issuecomment-825580160
#
# Env Variables:
#   interface - Defaults to tunsnx
#   dry_run - Set to 1 to have a dry run, just printing out the iptables command
#   debug   - Set to 1 to see bash substitutions

set -eu

_log_stderr() {
  echo "$*" >&2
}

if [ "${debug:=0}" = 1 ]; then
  set -x
  dry_run=${dry_run:=1}
fi

: ${dry_run:=0}
: ${interface:=tunsnx}

data=($(ip -o address show "$interface" | awk -F ' +' '{print $4 " " $6 " " $8}'))

LOCAL_ADDRESS_INDEX=0
PEER_ADDRESS_INDEX=1
SCOPE_INDEX=2

if [ "$dry_run" = 1 ]; then
  echo "[-] DRY-RUN MODE"
fi

if [ "${data[$SCOPE_INDEX]}" == "global" ]; then
  echo "[+] Interface ${interface} is already set to global scope. Skip!"
  exit 0
else
  echo "[+] Interface ${interface} is set to scope ${data[$SCOPE_INDEX]}."

  tmpfile=$(mktemp --suffix=snxwrapper-routes)
  echo "[+] Saving current IP routing table..."
  if [ "$dry_run" = 0 ]; then
    sudo ip route save >$tmpfile
  fi

  echo "[+] Deleting current interface ${interface}..."
  if [ "$dry_run" = 0 ]; then
    sudo ip address del ${data[$LOCAL_ADDRESS_INDEX]} peer ${data[$PEER_ADDRESS_INDEX]} dev ${interface}
  fi

  echo "[+] Recreating interface ${interface} with global scope..."
  if [ "$dry_run" = 0 ]; then
    sudo ip address add ${data[$LOCAL_ADDRESS_INDEX]} dev ${interface} peer ${data[$PEER_ADDRESS_INDEX]} scope global
  fi

  echo "[+] Restoring routing table..."
  if [ "$dry_run" = 0 ]; then
    sudo ip route restore <$tmpfile 2>/dev/null
  fi

  echo "[+] Cleaning temporary files..."
  rm $tmpfile

  echo "[+] Interface ${interface} is set to global scope. Done!"
  if [ "$dry_run" = 0 ]; then
    echo "[+] Result:"
    ip -o address show "tunsnx" | awk -F ' +' '{print $4 " " $6 " " $8}'
  fi
  exit 0
fi

[ "$debug" = 1 ] && set +x

【讨论】:

  • 在我的情况下,我在执行 'ip -o address show ...' 命令时得到范围“无处”。但我测试了你的脚本,它工作正常。非常感谢!
【解决方案2】:

现在对我来说同样的问题。没有什么大的变化,只是 tunsnx 接口范围从全局更改为 247。删除它并使用全局范围重新创建。

【讨论】:

  • 您能否详细解释一下您是如何解决这个问题的,分别是如何手动删除和重新创建界面?据我了解,SNX 会自动创建接口并在断开连接时将其删除。
  • 我使用 netwrok-manager 脚本进入 disptached.d ip address del ${snxInfo[$LOCAL_ADDRESS_INDEX]} peer ${snxInfo[$PEER_ADDRESS_INDEX]} dev ${iface} ip address add ${snxInfo[$LOCAL_ADDRESS_INDEX]} dev ${iface} peer ${snxInfo[$PEER_ADDRESS_INDEX]} scope global
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-04-26
  • 2021-05-22
  • 2021-06-22
  • 2021-02-08
  • 2017-04-06
  • 2018-04-20
  • 2018-02-17
相关资源
最近更新 更多