IPSec VPN的配置

在两个站点之间建立IPSec VPN

IPSec VPN的配置步骤:

1.按照拓扑图配置各个路由器接口IP地址、PC基础信息

按照拓扑图自行完成,最后查看AR1、AR2、AR3的接口ip地址

[AR1]dis ip int brief 
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 3
The number of interface that is DOWN in Physical is 1
The number of interface that is UP in Protocol is 3
The number of interface that is DOWN in Protocol is 1

Interface                         IP Address/Mask      Physical   Protocol  
GigabitEthernet0/0/0              202.108.10.1/30      up         up        
GigabitEthernet0/0/1              10.10.10.1/24        up         up        
GigabitEthernet0/0/2              unassigned           down       down      
NULL0                             unassigned           up         up(s) 
[AR2]dis ip int brief 
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 3
The number of interface that is DOWN in Physical is 1
The number of interface that is UP in Protocol is 3
The number of interface that is DOWN in Protocol is 1

Interface                         IP Address/Mask      Physical   Protocol  
GigabitEthernet0/0/0              202.108.20.1/30      up         up        
GigabitEthernet0/0/1              10.10.20.1/24        up         up        
GigabitEthernet0/0/2              unassigned           down       down      
NULL0
[AR3]dis ip int brief 
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 3
The number of interface that is DOWN in Physical is 1
The number of interface that is UP in Protocol is 3
The number of interface that is DOWN in Protocol is 1

Interface                         IP Address/Mask      Physical   Protocol  
GigabitEthernet0/0/0              202.108.10.2/30      up         up        
GigabitEthernet0/0/1              202.108.20.2/30      up         up        
GigabitEthernet0/0/2              unassigned           down       down      
NULL0
2.在AR1和AR2上通过静态默认路由的方式,指定去往对端的路由
[AR1]ip route-static 0.0.0.0 0 202.108.10.2
[AR2]ip route-static 0.0.0.0 0 202.108.20.2

测试站点1与站点2之间的连通性

[AR1]ping 202.108.20.1
  PING 202.108.20.1: 56  data bytes, press CTRL_C to break
    Request time out
    Reply from 202.108.20.1: bytes=56 Sequence=2 ttl=254 time=40 ms
    Reply from 202.108.20.1: bytes=56 Sequence=3 ttl=254 time=20 ms
    Reply from 202.108.20.1: bytes=56 Sequence=4 ttl=254 time=30 ms
    Reply from 202.108.20.1: bytes=56 Sequence=5 ttl=254 time=30 ms

  --- 202.108.20.1 ping statistics ---
    5 packet(s) transmitted
    4 packet(s) received
    20.00% packet loss
    round-trip min/avg/max = 20/30/40 ms

从测试结果得出AR1与AR2可以连通。

PC>ping 10.10.20.20

Ping 10.10.20.20: 32 data bytes, Press Ctrl_C to break
Request timeout!
Request timeout!
Request timeout!
Request timeout!
Request timeout!

--- 10.10.20.20 ping statistics ---
  5 packet(s) transmitted
  0 packet(s) received
  100.00% packet loss

但是站点1的内网主机PC1与站点2的内网主机之间无法相互访问。

3.使用高级IP ACL指定需要通过IPSec隧道进行保护的流量
[AR1]acl 3010
[AR1-acl-adv-3010]rule permit ip source 10.10.10.0 0.0.0.255 destination 10.10.20.0 0.0.0.255
[AR1-acl-adv-3010]rule deny ip

AR1上只放行源IP为10.10.10.0/24,同时目的IP为10.10.20.0/24的流量

[AR2]acl 3020
[AR2-acl-adv-3020]rule permit ip source 10.10.20.0 0.0.0.255 destination 10.10.10.0 0.0.0.255
[AR2-acl-adv-3020]rule deny ip

AR1上只放行源IP为10.10.20.0/24,同时目的IP为10.10.10.0/24的流量。

4.创建IPSec安全提议,并指定IPSec使用的各项参数
[AR1]ipsec proposal prop10  
[AR1-ipsec-proposal-prop10]encapsulation-mode tunnel 
[AR1-ipsec-proposal-prop10]transform esp    
[AR1-ipsec-proposal-prop10]esp authentication-algorithm sha2-256
[AR1-ipsec-proposal-prop10]esp encryption-algorithm aes-128

AR1创建名为prop10的IPSec安全协议,指定了用来建立连接的各种参数,包括数据封装模式,安全协议、认证和加密算法。

[AR2]ipsec proposal prop20  
[AR2-ipsec-proposal-prop20]esp authentication-algorithm sha2-256
[AR2-ipsec-proposal-prop20]esp encryption-algorithm aes-128

AR2创建名为prop20的IPSec安全协议,AR1与AR2通过对比双方支持的IPSec安全提议,并对IPSec所需要使用的认证和加密算法进行协商。

查看AR1上的IPSec安全协议

[AR1]dis ipsec proposal 

Number of proposals: 1

IPSec proposal name: prop10                            
 Encapsulation mode: Tunnel                            
 Transform         : esp-new
 ESP protocol      : Authentication SHA2-HMAC-256                             
                     Encryption     AES-128
5.创建IKE安全提议,并指定IKE使用的各项参数
[AR1]ike proposal 10
[AR1-ike-proposal-10]authentication-method pre-share 
[AR1-ike-proposal-10]authentication-algorithm sha1
[AR1-ike-proposal-10]encryption-algorithm aes-cbc-128
[AR2]ike proposal 20    
[AR2-ike-proposal-20]authentication-algorithm sha1
[AR2-ike-proposal-20]encryption-algorithm aes-cbc-128

IKE安全提议的编号取值范围是1~99,在IKE安全提议中,指定IKE尾交换和保护密钥所使用的认证方式,认证和加密算法。

6.创建IKE对等体,并在其中引用配置的IKE安全提议
[AR1]ike peer ike10 v1
[AR1-ike-peer-ike10]ike-proposal 10 
[AR1-ike-peer-ike10]pre-shared-key cipher huawei123
[AR1-ike-peer-ike10]remote-address 202.108.20.1
[AR2]ike peer ike20 v1  
[AR2-ike-peer-ike20]ike-proposal 20
[AR2-ike-peer-ike20]pre-shared-key cipher huawei123
[AR2-ike-peer-ike20]remote-address 202.108.10.1

使用系统视图命令ike peer ike20 v1创建了一个对等体,在IKE视图中,制定了对端IP地址、应用了之前建立的IKE安全提议,并定义了预共享密钥。

在AR1上查看IKE对等体

[AR1]dis ike peer verbose 

Number of IKE peers: 1

------------------------------------------
   Peer name              : ike10
   Exchange mode          : main on phase 1
   Pre-shared-key cipher  : "@J*U2S*(7F,YWX*NZ55OA!!
   Proposal               : 10
   Local ID type          : IP
   DPD                    : Disable
   DPD mode               : Periodic
   DPD idle time          : 30
   DPD retransmit interval: 15
   DPD retry limit        : 3
   Host name              : 
   Peer IP address        : 202.108.20.1 
   VPN name               : 
   Local IP address       : 
   Local name             : 
   Remote name            : 
   NAT-traversal          : Disable
   Configured IKE version : Version one
   PKI realm              : NULL
   Inband OCSP            : Disable
  ---- More ----

从输出命令可以看到,目前为止所配置的与IKE相关的所有参数,对等体名称(ike10),IKE安全提议号(10),IKE对等体IP地址(202.108.20.1)和IKE版本(Version one)。

7.创建IPSec安全策略,并在其中应用ACL、IPSec安全提议和IKE对等体

配置安全策略

[AR1]ipsec policy po10 10 isakmp 
[AR1-ipsec-policy-isakmp-po10-10]ike-peer ike10
[AR1-ipsec-policy-isakmp-po10-10]proposal prop10
[AR1-ipsec-policy-isakmp-po10-10]security acl 3010
[AR2]ipsec policy po20 20 isakmp 
[AR2-ipsec-policy-isakmp-po20-20]ike-peer ike20 
[AR2-ipsec-policy-isakmp-po20-20]proposal prop20    
[AR2-ipsec-policy-isakmp-po20-20]security acl 3020

将步骤2-5中创建的参数全部应用到了IPSec安全策略中。
在AR1中查看IPSec安全策略

[AR1]dis ipsec policy

===========================================
IPSec policy group: "po10"
Using interface: 
===========================================

    Sequence number: 10
    Security data flow: 3010
    Peer name    :  ike10
    Perfect forward secrecy: None
    Proposal name:  prop10
    IPSec SA local duration(time based): 3600 seconds
    IPSec SA local duration(traffic based): 1843200 kilobytes
    Anti-replay window size: 32
    SA trigger mode: Automatic
    Route inject: None
    Qos pre-classify: Disable

从输出中可以找到刚才应用的IKE对等体名称(ike10),IPSec安全提议(prop10),以及指定了搜保护流量的ACL(3010)。

8.建立连接的两端,在面向Internet的接口上应用安全策略。
[AR1]interface g0/0/0   
[AR1-GigabitEthernet0/0/0]ipsec policy po10
[AR2]int g0/0/0 
[AR2-GigabitEthernet0/0/0]ipsec policy po20

在AR1和AR2上查看已建立的IKE SA

[AR1]DIS IKE SA
    Conn-ID  Peer            VPN   Flag(s)                Phase  
  ---------------------------------------------------------------
        3    202.108.20.1    0     RD|ST                  2     
        2    202.108.20.1    0     RD|ST                  1     

  Flag Description:
  RD--READY   ST--STAYALIVE   RL--REPLACED   FD--FADING   TO--TIMEOUT
  HRT--HEARTBEAT   LKG--LAST KNOWN GOOD SEQ NO.   BCK--BACKED UP
[AR2]dis ike sa
    Conn-ID  Peer            VPN   Flag(s)                Phase  
  ---------------------------------------------------------------
        3    202.108.10.1    0     RD                     2     
        2    202.108.10.1    0     RD                     1     

  Flag Description:
  RD--READY   ST--STAYALIVE   RL--REPLACED   FD--FADING   TO--TIMEOUT
  HRT--HEARTBEAT   LKG--LAST KNOWN GOOD SEQ NO.   BCK--BACKED UP

AR1上面多了一个ST标记,表示AR1是IKE SA协商过程的发起方。AR1和AR2都有的标记RD表示IKE SA已经成功建立。

在AR1和AR2上查看已经建立的IPSec SA

[AR1]dis ipsec sa br

Number of SAs:2
    Src address     Dst address        SPI    VPN  Protocol     Algorithm
-------------------------------------------------------------------------------
   202.108.10.1    202.108.20.1 1024164772      0    ESP   E:AES-128 A:SHA2_256_
128
   202.108.20.1    202.108.10.1  168286895      0    ESP   E:AES-128 A:SHA2_256_
128
<AR2>dis ipsec sa brief 

Number of SAs:2
    Src address     Dst address        SPI    VPN  Protocol     Algorithm
-------------------------------------------------------------------------------
   202.108.10.1    202.108.20.1 1024164772      0    ESP   E:AES-128 A:SHA2_256_
128
   202.108.20.1    202.108.10.1  168286895      0    ESP   E:AES-128 A:SHA2_256_
128

SPI的作用是唯一标识一个IPSec SA。在IPSec流量封装过程中,路由器从SADB中查找相应的SA的SPI值并添加ESP头部。

PC1向PC2发起ping测试

PC>ping 10.10.20.20

Ping 10.10.20.20: 32 data bytes, Press Ctrl_C to break
Request timeout!
From 10.10.20.20: bytes=32 seq=2 ttl=127 time=31 ms
From 10.10.20.20: bytes=32 seq=3 ttl=127 time=31 ms
From 10.10.20.20: bytes=32 seq=4 ttl=127 time=16 ms
From 10.10.20.20: bytes=32 seq=5 ttl=127 time=15 ms

--- 10.10.20.20 ping statistics ---
  5 packet(s) transmitted
  4 packet(s) received
  20.00% packet loss
  round-trip min/avg/max = 0/23/31 ms
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 200,961评论 5 473
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 84,444评论 2 377
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 148,009评论 0 333
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,082评论 1 272
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,101评论 5 363
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,271评论 1 278
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,738评论 3 393
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,395评论 0 255
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,539评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,434评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,481评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,160评论 3 317
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,749评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,816评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,038评论 1 256
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,548评论 2 346
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,140评论 2 341

推荐阅读更多精彩内容