尝试ipsec穿越NAT
1:网络拓扑图为:
***gateway<--------->Router<-------|------->jim
eth0:192.168.1.25 WAN LAN eth0:192.168.3.33
eth1:192.168.0.22
其中:WAN:192.168.0.1
LAN:192.168.3.1
Router型号:Aolynk BR204+
内核版本 BR204+V100R008
应用程序版本 BR204+V100R008
编译时间 Mon, 13 Aug 2007 10:46:13 +0800
引导器版本 V1.0.1
硬件版本 V1.0.1
把路由器的上网络控制-->访问控制-->里的端口全部打开(ip地址和时间设置好,端口号选择为1到65535,协议选择为ALL,操作选择为允许)
系统服务-->管理-->把响应来自WAN口的ping请求和关闭防火墙前面方框点为对号。
2:192.168.0.22机器上的ipsec.conf文件为
[root@shanghai5000 etc]# more ipsec.conf
# /etc/ipsec.conf - Openswan IPsec configuration file
# RCSID $Id: ipsec.conf.in,v 1.15.2.6 2006/10/19 03:49:46 paul Exp $
# This file: /usr/local/share/doc/openswan/ipsec.conf-sample
#
# Manual: ipsec.conf.5
version 2.0 # conforms to second version of ipsec.conf specification
# basic configuration
config setup
interfaces=%defaultroute
# plutodebug / klipsdebug = "all", "none" or a combation from below:
# "raw crypt parsing emitting control klips pfkey natt x509 private"
# eg: plutodebug="control parsing"
#
# ONLY enable plutodebug=all or klipsdebug=all if you are a developer !!
#
# NAT-TRAVERSAL support, see README.NAT-Traversal
nat_traversal=yes
virtual_private=%v4:10.0.0.0/8,%v4:192.168.0.0/16,%v4:172.16.0.0/12,%v4:!192.168.0.0/24
#
# enable this if you see "failed to find any available worker"
nhelpers=0
# Add connections here
conn %default
compress=yes
authby=rsasig
leftrsasigkey=%cert
rightrsasigkey=%cert
conn road
left=192.168.0.22
leftcert=***gateway.cert
leftsubnet=192.168.1.0/24
right=%any
auto=add
# sample ××× connections, see /etc/ipsec.d/examples/
#Disable Opportunistic Encryption
include /etc/ipsec.d/examples/no_oe.conf
3:192.168.3.33机器上的ipsec.conf文件为
[root@beijing5000 etc]# more ipsec.conf
# /etc/ipsec.conf - Openswan IPsec configuration file
# RCSID $Id: ipsec.conf.in,v 1.15.2.6 2006/10/19 03:49:46 paul Exp $
# This file: /usr/local/share/doc/openswan/ipsec.conf-sample
#
# Manual: ipsec.conf.5
version 2.0 # conforms to second version of ipsec.conf specification
# basic configuration
config setup
interfaces=%defaultroute
# plutodebug / klipsdebug = "all", "none" or a combation from below:
# "raw crypt parsing emitting control klips pfkey natt x509 private"
# eg: plutodebug="control parsing"
#
# ONLY enable plutodebug=all or klipsdebug=all if you are a developer !!
#
# NAT-TRAVERSAL support, see README.NAT-Traversal
nat_traversal=yes
virtual_private=%v4:10.0.0.0/8,%v4:192.168.0.0/16,%v4:172.16.0.0/12,%v4:!192.168.0.0/24
#
# enable this if you see "failed to find any available worker"
nhelpers=0
# Add connections here
conn %default
compress=yes
authby=rsasig
leftrsasigkey=%cert
rightrsasigkey=%cert
conn road
left=192.168.3.33
leftcert=jim.cert
right=192.168.0.22
rightcert=***gateway.cert
rightsubnet=192.168.1.0/24
auto=add
# sample ××× connections, see /etc/ipsec.d/examples/
#Disable Opportunistic Encryption
include /etc/ipsec.d/examples/no_oe.conf
4:在jim(192.168.3.33)机器上执行下列命令进行ipsec连接
[root@beijing5000 /]# ipsec auto --up road
104 "road" #1: STATE_MAIN_I1: initiate
003 "road" #1: received Vendor ID payload [Openswan (this version) 2.4.7 PLUTO_SENDS_VENDORID PLUTO_USES_KEYRR]
003 "road" #1: received Vendor ID payload [Dead Peer Detection]
003 "road" #1: received Vendor ID payload [RFC 3947] method set to=110
106 "road" #1: STATE_MAIN_I2: sent MI2, expecting MR2
003 "road" #1: NAT-Traversal: Result using RFC 3947 (NAT-Traversal): i am NATed
108 "road" #1: STATE_MAIN_I3: sent MI3, expecting MR3
004 "road" #1: STATE_MAIN_I4: ISAKMP SA established {auth=OAKLEY_RSA_SIG cipher=oakley_3des_cbc_192 prf=oakley_md5 group=modp1536}
117 "road" #2: STATE_QUICK_I1: initiate
010 "road" #2: STATE_QUICK_I1: retransmission; will wait 20s for response
010 "road" #2: STATE_QUICK_I1: retransmission; will wait 40s for response
031 "road" #2: max number of retransmissions (2) reached STATE_QUICK_I1. No acceptable response to our first Quick Mode message: perhaps peer likes no proposal
000 "road" #2: starting keying attempt 2 of an unlimited number, but releasing whack
[root@beijing5000 /]#
5:192.168.3.33机器上的日志为
Dec 2 17:12:11 beijing5000 ipsec__plutorun: Starting Pluto subsystem...
Dec 2 17:12:11 beijing5000 pluto[8349]: Starting Pluto (Openswan Version 2.4.7 PLUTO_SENDS_VENDORID PLUTO_USES_KEYRR; Vendor ID OEZ
~BaB]r\134p_)
Dec 2 17:12:11 beijing5000 pluto[8349]: Setting NAT-Traversal port-4500 floating to on
Dec 2 17:12:11 beijing5000 pluto[8349]: port floating activation criteria nat_t=1/port_fload=1
Dec 2 17:12:11 beijing5000 pluto[8349]: including NAT-Traversal patch (Version 0.6c)
Dec 2 17:12:11 beijing5000 pluto[8349]: ike_alg_register_enc(): Activating OAKLEY_AES_CBC: Ok (ret=0)
Dec 2 17:12:11 beijing5000 pluto[8349]: no helpers will be started, all cryptographic operations will be done inline
Dec 2 17:12:11 beijing5000 pluto[8349]: Using NETKEY IPsec interface code on 2.6.9-42.EL
Dec 2 17:12:11 beijing5000 pluto[8349]: Changing to directory '/etc/ipsec.d/cacerts'
Dec 2 17:12:11 beijing5000 pluto[8349]: loaded CA cert file 'cacert.pem' (1253 bytes)
Dec 2 17:12:11 beijing5000 pluto[8349]: Changing to directory '/etc/ipsec.d/aacerts'
Dec 2 17:12:11 beijing5000 pluto[8349]: Changing to directory '/etc/ipsec.d/ocspcerts'
Dec 2 17:12:11 beijing5000 pluto[8349]: Changing to directory '/etc/ipsec.d/crls'
Dec 2 17:12:11 beijing5000 pluto[8349]: loaded crl file 'crl.pem' (508 bytes)
Dec 2 17:12:11 beijing5000 pluto[8349]: loaded host cert file '/etc/ipsec.d/certs/jim.cert' (3581 bytes)
Dec 2 17:12:11 beijing5000 pluto[8349]: loaded host cert file '/etc/ipsec.d/certs/***gateway.cert' (3603 bytes)
Dec 2 17:12:11 beijing5000 pluto[8349]: added connection description "road"
Dec 2 17:12:11 beijing5000 pluto[8349]: listening for IKE messages
Dec 2 17:12:11 beijing5000 pluto[8349]: adding interface eth1/eth1 192.168.3.33:500
Dec 2 17:12:11 beijing5000 pluto[8349]: adding interface eth1/eth1 192.168.3.33:4500
Dec 2 17:12:11 beijing5000 pluto[8349]: adding interface lo/lo 127.0.0.1:500
Dec 2 17:12:11 beijing5000 pluto[8349]: adding interface lo/lo 127.0.0.1:4500
Dec 2 17:12:11 beijing5000 pluto[8349]: adding interface lo/lo ::1:500
Dec 2 17:12:11 beijing5000 pluto[8349]: loading secrets from "/etc/ipsec.secrets"
Dec 2 17:12:11 beijing5000 pluto[8349]: loaded private key file '/etc/ipsec.d/private/jim.key' (1728 bytes)
Dec 2 17:12:31 beijing5000 pluto[8349]: "road" #1: initiating Main Mode
Dec 2 17:12:31 beijing5000 pluto[8349]: "road" #1: received Vendor ID payload [Openswan (this version) 2.4.7 PLUTO_SENDS_VENDORID
PLUTO_USES_KEYRR]
Dec 2 17:12:31 beijing5000 pluto[8349]: "road" #1: received Vendor ID payload [Dead Peer Detection]
Dec 2 17:12:31 beijing5000 pluto[8349]: "road" #1: received Vendor ID payload [RFC 3947] method set to=110
Dec 2 17:12:31 beijing5000 pluto[8349]: "road" #1: enabling possible NAT-traversal with method RFC 3947 (NAT-Traversal)
Dec 2 17:12:31 beijing5000 pluto[8349]: "road" #1: transition from state STATE_MAIN_I1 to state STATE_MAIN_I2
Dec 2 17:12:31 beijing5000 pluto[8349]: "road" #1: STATE_MAIN_I2: sent MI2, expecting MR2
Dec 2 17:12:31 beijing5000 pluto[8349]: "road" #1: NAT-Traversal: Result using RFC 3947 (NAT-Traversal): i am NATed
Dec 2 17:12:31 beijing5000 pluto[8349]: "road" #1: I am sending my cert
Dec 2 17:12:31 beijing5000 pluto[8349]: "road" #1: I am sending a certificate request
Dec 2 17:12:31 beijing5000 pluto[8349]: "road" #1: transition from state STATE_MAIN_I2 to state STATE_MAIN_I3
Dec 2 17:12:31 beijing5000 pluto[8349]: "road" #1: STATE_MAIN_I3: sent MI3, expecting MR3
Dec 2 17:12:31 beijing5000 pluto[8349]: "road" #1: Main mode peer ID is ID_DER_ASN1_DN: 'C=ro, ST=roots, L=rootcity, O=rootorg, OU=
rootsection, CN=***gateway, E=***
[email protected]'
Dec 2 17:12:31 beijing5000 pluto[8349]: "road" #1: transition from state STATE_MAIN_I3 to state STATE_MAIN_I4
Dec 2 17:12:31 beijing5000 pluto[8349]: "road" #1: STATE_MAIN_I4: ISAKMP SA established {auth=OAKLEY_RSA_SIG cipher=oakley_3des_cbc
_192 prf=oakley_md5 group=modp1536}
Dec 2 17:12:31 beijing5000 pluto[8349]: "road" #2: initiating Quick Mode RSASIG+ENCRYPT+COMPRESS+TUNNEL+PFS+UP {using isakmp#1}
Dec 2 17:12:31 beijing5000 pluto[8349]: "road" #1: ignoring informational payload, type INVALID_ID_INFORMATION
Dec 2 17:12:31 beijing5000 pluto[8349]: "road" #1: received and ignored informational message
Dec 2 17:12:41 beijing5000 pluto[8349]: "road" #1: ignoring informational payload, type INVALID_MESSAGE_ID
Dec 2 17:12:41 beijing5000 pluto[8349]: "road" #1: received and ignored informational message
Dec 2 17:13:01 beijing5000 pluto[8349]: "road" #1: ignoring informational payload, type INVALID_MESSAGE_ID
Dec 2 17:13:01 beijing5000 pluto[8349]: "road" #1: received and ignored informational message
Dec 2 17:13:41 beijing5000 pluto[8349]: "road" #2: max number of retransmissions (2) reached STATE_QUICK_I1. No acceptable respons
e to our first Quick Mode message: perhaps peer likes no proposal
Dec 2 17:13:41 beijing5000 pluto[8349]: "road" #2: starting keying attempt 2 of an unlimited number, but releasing whack
Dec 2 17:13:41 beijing5000 pluto[8349]: "road" #3: initiating Quick Mode RSASIG+ENCRYPT+COMPRESS+TUNNEL+PFS+UP to replace #2 {using
isakmp#1}
Dec 2 17:13:41 beijing5000 pluto[8349]: "road" #1: ignoring informational payload, type INVALID_ID_INFORMATION
Dec 2 17:13:41 beijing5000 pluto[8349]: "road" #1: received and ignored informational message
Dec 2 17:13:51 beijing5000 pluto[8349]: "road" #1: ignoring informational payload, type INVALID_MESSAGE_ID
Dec 2 17:13:51 beijing5000 pluto[8349]: "road" #1: received and ignored informational message
6:192.168.0.22机器上的日志文件
Dec 2 10:59:50 shanghai5000 ipsec__plutorun: Starting Pluto subsystem...
Dec 2 10:59:50 shanghai5000 pluto[12365]: Starting Pluto (Openswan Version 2.4.7 PLUTO_SENDS_VENDORID PLUTO_USES_KEYRR; Vendor ID OEZ~BaB]r\134p_)
Dec 2 10:59:50 shanghai5000 pluto[12365]: Setting NAT-Traversal port-4500 floating to on
Dec 2 10:59:50 shanghai5000 pluto[12365]: port floating activation criteria nat_t=1/port_fload=1
Dec 2 10:59:50 shanghai5000 pluto[12365]: including NAT-Traversal patch (Version 0.6c)
Dec 2 10:59:50 shanghai5000 pluto[12365]: ike_alg_register_enc(): Activating OAKLEY_AES_CBC: Ok (ret=0)
Dec 2 10:59:50 shanghai5000 pluto[12365]: no helpers will be started, all cryptographic operations will be done inline
Dec 2 10:59:50 shanghai5000 pluto[12365]: Using NETKEY IPsec interface code on 2.6.9-42.ELsmp
Dec 2 10:59:51 shanghai5000 pluto[12365]: Changing to directory '/etc/ipsec.d/cacerts'
Dec 2 10:59:51 shanghai5000 pluto[12365]: loaded CA cert file 'cacert.pem' (1253 bytes)
Dec 2 10:59:51 shanghai5000 pluto[12365]: Changing to directory '/etc/ipsec.d/aacerts'
Dec 2 10:59:51 shanghai5000 pluto[12365]: Changing to directory '/etc/ipsec.d/ocspcerts'
Dec 2 10:59:51 shanghai5000 pluto[12365]: Changing to directory '/etc/ipsec.d/crls'
Dec 2 10:59:51 shanghai5000 pluto[12365]: loaded crl file 'crl.pem' (508 bytes)
Dec 2 10:59:51 shanghai5000 pluto[12365]: loaded host cert file '/etc/ipsec.d/certs/***gateway.cert' (3603 bytes)
Dec 2 10:59:51 shanghai5000 pluto[12365]: added connection description "road"
Dec 2 10:59:51 shanghai5000 pluto[12365]: listening for IKE messages
Dec 2 10:59:51 shanghai5000 pluto[12365]: adding interface eth1/eth1 192.168.0.22:500
Dec 2 10:59:51 shanghai5000 pluto[12365]: adding interface eth1/eth1 192.168.0.22:4500
Dec 2 10:59:51 shanghai5000 pluto[12365]: adding interface eth0/eth0 192.168.1.25:500
Dec 2 10:59:51 shanghai5000 pluto[12365]: adding interface eth0/eth0 192.168.1.25:4500
Dec 2 10:59:51 shanghai5000 pluto[12365]: adding interface lo/lo 127.0.0.1:500
Dec 2 10:59:51 shanghai5000 pluto[12365]: adding interface lo/lo 127.0.0.1:4500
Dec 2 10:59:51 shanghai5000 pluto[12365]: adding interface lo/lo ::1:500
Dec 2 10:59:51 shanghai5000 pluto[12365]: loading secrets from "/etc/ipsec.secrets"
Dec 2 10:59:51 shanghai5000 pluto[12365]: loaded private key file '/etc/ipsec.d/private/***gateway.key' (1761 bytes)
Dec 2 10:59:58 shanghai5000 pluto[12365]: packet from 192.168.0.1:500: received Vendor ID payload [Openswan (this version) 2.4.7 PLUTO_SENDS_VENDORID PLUTO_USES_KEYRR]
Dec 2 10:59:58 shanghai5000 pluto[12365]: packet from 192.168.0.1:500: received Vendor ID payload [Dead Peer Detection]
Dec 2 10:59:58 shanghai5000 pluto[12365]: packet from 192.168.0.1:500: received Vendor ID payload [RFC 3947] method set to=110
Dec 2 10:59:58 shanghai5000 pluto[12365]: packet from 192.168.0.1:500: received Vendor ID payload [draft-ietf-ipsec-nat-t-ike-03] meth=108, but already using method 110
Dec 2 10:59:58 shanghai5000 pluto[12365]: packet from 192.168.0.1:500: received Vendor ID payload [draft-ietf-ipsec-nat-t-ike-02] meth=107, but already using method 110
Dec 2 10:59:58 shanghai5000 pluto[12365]: packet from 192.168.0.1:500: received Vendor ID payload [draft-ietf-ipsec-nat-t-ike-02_n] meth=106, but already using method 110
Dec 2 10:59:58 shanghai5000 pluto[12365]: packet from 192.168.0.1:500: received Vendor ID payload [draft-ietf-ipsec-nat-t-ike-00]
Dec 2 10:59:58 shanghai5000 pluto[12365]: "road"[1] 192.168.0.1 #1: responding to Main Mode from unknown peer 192.168.0.1
Dec 2 10:59:58 shanghai5000 pluto[12365]: "road"[1] 192.168.0.1 #1: transition from state STATE_MAIN_R0 to state STATE_MAIN_R1
Dec 2 10:59:58 shanghai5000 pluto[12365]: "road"[1] 192.168.0.1 #1: STATE_MAIN_R1: sent MR1, expecting MI2
Dec 2 10:59:58 shanghai5000 pluto[12365]: "road"[1] 192.168.0.1 #1: NAT-Traversal: Result using RFC 3947 (NAT-Traversal): peer is NATed
Dec 2 10:59:58 shanghai5000 pluto[12365]: "road"[1] 192.168.0.1 #1: transition from state STATE_MAIN_R1 to state STATE_MAIN_R2
Dec 2 10:59:58 shanghai5000 pluto[12365]: "road"[1] 192.168.0.1 #1: STATE_MAIN_R2: sent MR2, expecting MI3
Dec 2 10:59:58 shanghai5000 pluto[12365]: "road"[1] 192.168.0.1 #1: Main mode peer ID is ID_DER_ASN1_DN: 'C=ro, ST=roots, L=rootcity, O=rootorg, OU=rootsection, CN=jimname,
[email protected]'
Dec 2 10:59:58 shanghai5000 pluto[12365]: "road"[1] 192.168.0.1 #1: switched from "road" to "road"
Dec 2 10:59:58 shanghai5000 pluto[12365]: "road"[2] 192.168.0.1 #1: deleting connection "road" instance with peer 192.168.0.1 {isakmp=#0/ipsec=#0}
Dec 2 10:59:58 shanghai5000 pluto[12365]: "road"[2] 192.168.0.1 #1: I am sending my cert
Dec 2 10:59:58 shanghai5000 pluto[12365]: "road"[2] 192.168.0.1 #1: transition from state STATE_MAIN_R2 to state STATE_MAIN_R3
Dec 2 10:59:58 shanghai5000 pluto[12365]: | NAT-T: new mapping 192.168.0.1:500/4500)
Dec 2 10:59:58 shanghai5000 pluto[12365]: "road"[2] 192.168.0.1 #1: STATE_MAIN_R3: sent MR3, ISAKMP SA established {auth=OAKLEY_RSA_SIG cipher=oakley_3des_cbc_192 prf=oakley_md5 group=modp1536}
Dec 2 10:59:58 shanghai5000 pluto[12365]: "road"[2] 192.168.0.1 #1: cannot respond to IPsec SA request because no connection is known for 192.168.1.0/24===192.168.0.22[C=ro, ST=roots, L=rootcity, O=rootorg, OU=rootsection, CN=***gateway, E=***
[email protected]]...192.168.0.1[C=ro, ST=roots, L=rootcity, O=rootorg, OU=rootsection, CN=jimname,
[email protected]]===192.168.3.33/32
Dec 2 10:59:58 shanghai5000 pluto[12365]: "road"[2] 192.168.0.1 #1: sending encrypted notification INVALID_ID_INFORMATION to 192.168.0.1:4500
Dec 2 11:00:08 shanghai5000 pluto[12365]: "road"[2] 192.168.0.1 #1: Quick Mode I1 message is unacceptable because it uses a previously used Message ID 0x2080082e (perhaps this is a duplicated packet)
Dec 2 11:00:08 shanghai5000 pluto[12365]: "road"[2] 192.168.0.1 #1: sending encrypted notification INVALID_MESSAGE_ID to 192.168.0.1:4500