使用动态 DNS 通过 ssh 连接到 VPN 中的一台机器

使用动态 DNS 通过 ssh 连接到 VPN 中的一台机器

我已经在本地网络上设置了路由器,使用动态 DNS(无 IP)来获取“静态”主机名。我已将端口 22 转发到本地 PC,并且我可以使用 ssh 远程登录。我还需要机器连接到 VPN 网络才能访问我必须使用的服务器。不幸的是,一旦我启动 VPN,我就会断开连接,并且无法再使用静态主机名重新连接。我仍然可以 ping 主机名,因为路由器会应答,但我无法再 ssh 到我需要访问的机器。

 ssh: connect to host myhostname.no-ip.biz port 22: Connection timed out

我使用 vpnc 连接到 vpn,但它是我所在大学提供的自定义版本。他们表示,通常的 vpnc 客户端不兼容。他们还提供了一个配置文件,如下所示

IPSec gateway vpn.uni-mannheim.de
IPSec ID doniluma
IPSec secret wlan
IKE Authmode hybrid
CA-File uni-ma.pem
Xauth username myusername

以及证书文件。是否有可能调整路由或类似操作,以便我可以在用 vpnc-connect 初始化 vpn 后(重新)连接?

答案1

来自 VPNC 手册页:

   The vpnc daemon by itself does not set any routes, but it calls vpnc-script to do this job. vpnc-script displays a connect banner.  If
   the  concentrator  supplies  a network list for split-tunneling these networks are added to the routing table.  Otherwise the default-
   route will be modified to point to the tunnel.  Further a host route to the concentrator is added in the later case.   If  the  client
   host needs DHCP, care must be taken to add another host route to the DHCP-Server around the tunnel.

因此,您的流量很可能被导向您的大学,如果他们有严格的防火墙,端口 22 可能会在外面关闭。因此,您要么要求网络管理员更改 VPN 服务器设置,以便不设置连接的默认路由,要么必须更改客户端的行为。显然没有这样做的选项(至少我没有发现),但我找到了一种解决方法这里复制 /etc/vpnc/vpnc-script 并编辑原始文件。在我的版本中,我有两个set_default_route()函数声明。您必须更改它们才能不更改默认路由。第一个应该如下所示:

    set_default_route() {
        $IPROUTE route | grep '^default' | fix_ip_get_output > "$DEFAULT_ROUTE_FILE"
#        $IPROUTE route replace default dev "$TUNDEV"
        $IPROUTE route flush cache
    }

第二个

set_default_route() {
    DEFAULTGW="`get_default_gw`"
    echo "$DEFAULTGW" > "$DEFAULT_ROUTE_FILE"
#    route $route_syntax_del default $route_syntax_gw "$DEFAULTGW"
#    route add default $route_syntax_gw "$INTERNAL_IP4_ADDRESS" $route_syntax_interface
}

请注意,我没有测试这些修改,所以您可能需要稍微修改一下。

相关内容