我在尝试创建ipsec连接时发现了一些奇怪的行为。 我在cisco asa和我的Linux机器之间配置了ipsec,它按预期工作。但是,当我在Linux机器上重新启动网络服务或重新启动cisco端的端口时,隧道将停止工作但隧道状态已启动:
/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服务时,一切都开始工作,但我认为应该有一些逻辑可以自动完成。有谁知道我错过了什么?
答案 0 :(得分:5)
如果双方都可用,您可能希望启用死对等检测。当隧道实际上不再工作并断开连接或重置隧道时,死对等检测会发出通知。
如果没有,您还可以尝试将会话重新协商时间降低到非常低的水平;您的隧道将频繁创建新密钥并设置新隧道以定期替换旧隧道,以便在会话中断后超时后有效地重新创建隧道。
对于Linux本身的PPP会话,我只需在/etc/ppp/ip-up.local中使用“service ipsec restart”,即可在PPP设备重新联机时重启所有隧道。
因人而异。
答案 1 :(得分:3)
试试DPD,但不行。
所以我刚从mikebabcock那里学到了。
在/ etc / ppp / ip-down
中添加以下行service ipsec restart
通过这种解决方法,现在L2TP / IPSec就像一个魅力。
答案 2 :(得分:1)
我不喜欢每次失去连接时重启ipsec的想法。实际上,/usr/libexec/ipsec/_updown
在ipsec中针对不同的操作运行。可以在leftupdown / rightupdown上运行相同的脚本。但问题是,当远程客户端连接回主机时,它不会执行任何实际命令。要解决此问题,您需要在/usr/libexec/ipsec/_updown.netkey中doroute replace
之后添加up-client)
(如果您当然使用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"
现在,只要远程连接回服务器,路由就会恢复。
答案 3 :(得分:1)
同样对我来说,由于奇怪的原因,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
答案 4 :(得分:1)
这可能是因为iptables规则而发生的
确保已将udp端口500和esp协议启用到远程公共IP地址。
示例:
iptables -A OUTPUT -p udp -d 1.2.3.4 --dport 500 -j ACCEPT iptables -A OUTPUT -p esp -d 1.2.3.4 -j ACCEPT
再见