【问题标题】:Openswan tunnel not working after network restart网络重启后Openswan隧道不工作
【发布时间】:2012-06-04 11:51:48
【问题描述】:

我在尝试创建 ipsec 连接时观察到一些奇怪的行为。 我在 cisco asa 和我的 Linux 机器之间配置了 ipsec,它按预期工作。但是当我在我的Linux机器上重新启动网络服务或在cisco端重新启动端口时,隧道停止工作但隧道状态为up:

/etc/init.d/ipsec status
/usr/libexec/ipsec/addconn Non-fips mode set in /proc/sys/crypto/fips_enabled
IPsec running  - pluto pid: 2684
pluto pid 2684
1 tunnels up
some eroutes exist

当我尝试连接到另一端(telnet、ping、ssh)时,连接不起作用。

我的 /etc/ipsec.conf 如下所示:

# /etc/ipsec.conf - Openswan IPsec configuration file
#
# Manual:     ipsec.conf.5
#
# Please place your own config files in /etc/ipsec.d/ ending in .conf

version 2.0     # conforms to second version of ipsec.conf specification

# basic configuration
config setup
        # Debug-logging controls:  "none" for (almost) none, "all" for lots.
        # klipsdebug=none
        # plutodebug="control parsing"
        # For Red Hat Enterprise Linux and Fedora, leave protostack=netkey
        protostack=netkey
        nat_traversal=yes
        virtual_private=
        oe=off
        # Enable this if you see "failed to find any available worker"
        nhelpers=0

#You may put your configuration (.conf) file in the "/etc/ipsec.d/" and uncomment this.
include /etc/ipsec.d/*.conf

我的 /etc/ipsec.d/myvpn.conf 看起来像这样:

conn myvpn
        authby=secret                # Key exchange method
        left=server-ip                     # Public Internet IP address of the
                                     # LEFT VPN device
        leftsubnet=server-ip/32            # Subnet protected by the LEFT VPN device
        leftnexthop=%defaultroute    # correct in many situations
        right=asa-ip                 # Public Internet IP address of
                                     # the RIGHT VPN device
        rightsubnet=network/16       # Subnet protected by the RIGHT VPN device
        rightnexthop=asa-ip          # correct in many situations
        auto=start                   # authorizes and starts this connection
                                     # on booting
        auth=esp
        esp=aes-sha1
        compress=no

当我重新启动 openswan 服务时,一切都开始工作了,但我认为应该有一些逻辑可以自动执行此操作。有谁知道我错过了什么?

【问题讨论】:

    标签: linux centos vpn ipsec


    【解决方案1】:

    如果双方都可用,您可能希望启用失效对等检测。当隧道实际上不再工作并断开或重置它时,死对等检测会发出通知。

    如果不可用,您还可以尝试将会话重新协商时间降低到非常低;您的隧道将频繁创建新密钥并设置新隧道以定期替换旧隧道,当会话关闭时,在超时后有效地重新创建隧道。

    对于我自己在 Linux 上的 PPP 会话,我只需在 /etc/ppp/ip-up.local 中有一个“service ipsec restart”,以便在 PPP 设备恢复联机时重新启动所有隧道。

    YMMV.

    【讨论】:

    • 我遇到了类似的问题,虽然 ipsec 显示隧道已启动,但在 ifconfig 之后没有创建隧道0 接口。
    • 如果您使用内置的 VPN 支持,则不会创建特殊的隧道接口。只有在使用特殊的 KLIPS 驱动程序时,您才能获得用于 VPN 设备的新接口。
    【解决方案2】:

    尝试 DPD,但不起作用。

    所以我刚刚向 mikebabcock 学习。

    在我的 /etc/ppp/ip-down 中添加以下行

    service ipsec restart
    

    有了这个解决方法,现在 L2TP/IPSec 就像一个魅力一样工作。

    【讨论】:

      【解决方案3】:

      我不喜欢每次断开连接时都重新启动 ipsec 的想法。实际上 /usr/libexec/ipsec/_updown 在 ipsec 中运行不同的操作。相同的脚本可以在 leftupdown/rightupdown 上运行。但问题是,当远程客户端连接回您的主机时,它不会执行任何实际命令。要解决此问题,您需要在 /usr/libexec/ipsec/_updown.netkey 中的 up-client) 之后添加 doroute replace(当然,如果您使用 Netkey):

      # ...skipped...
      #
      up-client)
      # connection to my client subnet coming up
      # If you are doing a custom version, firewall commands go here.
          doroute replace
      #
      # ...skipped...
      

      但请注意,如果您更新软件包,此文件将被覆盖,因此只需将其放在其他位置,然后将以下命令添加到您的连接配置:

      rightupdown="/usr/local/libexec/ipsec/_updown"
      leftupdown="/usr/local/libexec/ipsec/_updown"
      

      现在,只要远程连接回您的服务器,路由就会恢复。

      【讨论】:

        【解决方案4】:

        对我来说,出于奇怪的原因DPD 并非在每种情况下都能正常工作。 我使用此脚本每分钟检查一次状态。脚本在 Peer(例如防火墙)上运行:

        C=$(ipsec auto --status | grep "established" | wc -l)
        if [ $C -eq 0 ]
        then
         echo "Tunnel is down... Restarting"
         ipsec restart
        else
         echo "Tunnel is up...Bye!"
        fi
        

        【讨论】:

          【解决方案5】:


          这可能是由于 iptables 规则而发生的。
          一定要开启对远程公网ip地址的udp端口500和esp协议。

          例子:

          iptables -A 输出 -p udp -d 1.2.3.4 --dport 500 -j 接受 iptables -A 输出 -p esp -d 1.2.3.4 -j 接受

          再见

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2018-10-31
            • 2020-04-15
            • 2014-03-12
            • 1970-01-01
            • 2020-12-10
            • 1970-01-01
            • 1970-01-01
            • 2017-07-14
            相关资源
            最近更新 更多