拓扑图


需求

  1. 北京–上海–建立VPN隧道,并验证
  2. 要求2个公司能上网,但不影响VPN隧道
  3. 要求北京总部与广州新成立的分公司也建立VPN隧道
  4. 要求广州和上海之间不建立VPN隧道,但广州和上海可以互相安全的通信

思路

IPsecVPN和NAT同时存在时先匹配NAT,然后再匹配VPN

只配置VPN的情况下无法访问互联网,NAT(PAT)对源进行转换,而IPsecVPN(隧道模式)对整个IP包进行加密后添加了新的头部。

由于在第二阶段(数据连接)使用ACL进行流量过滤(一般只允许目标IP是私网地址的通过),直接访问公网IP的数据包不会被VPN匹配,VPN没有干掉数据包的能力,而是直接被路由出去,一旦数据包到达公网,由于其携带私有IP,会直接被公网路由器干掉。

需要对NAT(PAT)的ACL做限制,禁止所有私网到私网的NAT转换(也称为NAT豁免),否则NAT将源替换为公网IP后,VPN不会对其进行加密。

关于第三点,总部的ISAKMP框架不需要变动,只需要重新配置一个VPN隧道,并重新配置MAP映射表(一个端口只能映射一个MAP表,通过表号区分)

关于第四点,可以通过ACL将广州的数据包中转到总部,然后通过VPN隧道去往上海分公司,不需要做NAT豁免,数据包从外网端口进的。


步骤

总部配置VPN过程:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#int f0/0
Router(config-if)#ip add 192.168.1.254 255.255.255.0
Router(config-if)#no sh

Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
exit
Router(config)#int f0/1
Router(config-if)#ip add 100.1.1.1 255.255.255.0
Router(config-if)#no sh

Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up
exit
Router(config)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up

Router(config)#int f0/1
Router(config-if)#ip route 0.0.0.0 0.0.0.0 100.1.1.2

/*创建传输集*/
Router(config)#crypto isakmp policy 1

/*对称加密算法*/
Router(config-isakmp)#encryption aes

/*DH算法的长度*/
Router(config-isakmp)#group 2

/*使用预共享秘钥进行加密和身份验证*/
Router(config-isakmp)#authentication pre-share

/*验证数据完整性*/
Router(config-isakmp)#hash sha
/*生存时间*/
Router(config-isakmp)#lifetime 86400
Router(config-isakmp)#exit

/*隧道标识,用于区分隧道*/
Router(config)#crypto isakmp key password address 200.1.1.2

/*使用ACL对VPN流量进行过滤*/
Router(config)#access-list 100 permit ip 192.168.1.0 0.0.0.255 172.16.1.0 0.0.0.255

/*定义数据连接的算法和传输名*/
Router(config)#crypto ipsec transform-set kctran esp-aes esp-sha-hmac

/*创建MAP映射表kcmap*/
Router(config)#crypto map kcmap 1 ipsec-isakmp
% NOTE: This new crypto map will remain disabled until a peer
and a valid access list have been configured.
Router(config-crypto-map)#match address 100

Router(config-crypto-map)#set transform-set kctran
Router(config-crypto-map)#set peer 200.1.1.2
Router(config-crypto-map)#exit
Router(config)#int f0/1
Router(config-if)#crypto map kcmap
*Jan 3 07:16:26.785: %CRYPTO-6-ISAKMP_ON_OFF: ISAKMP is ON
Router(config-if)#exit
Router(config)#

配置NAT(PAT)

北京总部

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.

/*对两个内网IP流量做NAT豁免*/
Router(config)#acc 101 deny ip 192.168.1.0 0.0.0.255 172.16.1.0 0.0.0.255
Router(config)#acc 101 permit ip any any
Router(config)#int f0/0
Router(config-if)#ip nat inside
Router(config-if)#exit
Router(config)#int f0/1
Router(config-if)#ip nat outside
Router(config-if)#exit
Router(config)#ip nat inside source list 101 int f0/1 overload
Router(config)#

上海分公司

1
2
3
4
5
6
7
8
9
10
11
/*对两个内网IP流量做NAT豁免*/
Router(config)#acc 101 deny ip 172.16.1.0 0.0.0.255 192.168.1.0 0.0.0.255
Router(config)#acc 101 permit ip any any

Router(config)#int f0/1
Router(config-if)#ip nat inside
Router(config-if)#exit
Router(config)#int f0/0
Router(config-if)#ip nat outside
Router(config-if)#exit
Router(config)#ip nat inside source list 101 int f0/0 overload

以上完成了VPN和NAT同时部署


广州和总部部署VPN

广州部署:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#crypto isakmp policy 1
Router(config-isakmp)#encryption aes
Router(config-isakmp)#group 2
Router(config-isakmp)#authentication pre-share
Router(config-isakmp)#lifetime 86400
Router(config-isakmp)#hash sha
Router(config-isakmp)#exit
Router(config)#crypto isakmp key password address 100.1.1.1
Router(config)#acc 100 permit ip 10.1.1.0 0.0.0.255 192.168.1.0 0.0.0.255
Router(config)#crypto ipsec transform-set kctran esp-aes esp-sha-hmac
Router(config)#crypto map kcmap 1 ipsec-isakmp
% NOTE: This new crypto map will remain disabled until a peer
and a valid access list have been configured.
Router(config-crypto-map)#set transform-set kctran
Router(config-crypto-map)#set peer 100.1.1.1
Router(config-crypto-map)#match address 100
Router(config-crypto-map)#exit
Router(config)#int f0/0
Router(config-if)#crypto map kcmap
*Jan 3 07:16:26.785: %CRYPTO-6-ISAKMP_ON_OFF: ISAKMP is ON
Router(config-if)#exit

总部配置过程:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#do sh acc
Extended IP access list 100
10 permit ip 192.168.1.0 0.0.0.255 172.16.1.0 0.0.0.255 (2 match(es))
Extended IP access list 101
10 deny ip 192.168.1.0 0.0.0.255 172.16.1.0 0.0.0.255 (12 match(es))
20 permit ip any any (10 match(es))
Router(config)#ip access-list extended 101
Router(config-ext-nacl)#15 deny ip 192.168.1.0 0.0.0.255 10.1.1.0 0.0.0.255
Router(config-ext-nacl)#exit
Router(config)#acc 102 permit ip 192.168.1.0 0.0.0.255 10.1.1.0 0.0.0.255

/*第二条隧道标识和身份验证*/
Router(config)#crypto isakmp key password address 120.1.1.1

Router(config)#crypto map kcmap 2 ipsec-isakmp
% NOTE: This new crypto map will remain disabled until a peer
and a valid access list have been configured.
Router(config-crypto-map)#set transform-set kctran
Router(config-crypto-map)#set peer 120.1.1.1
Router(config-crypto-map)#match add 102
Router(config-crypto-map)#exit

在配置了多条VPN隧道时不能使用同一ACL进行过滤,否则会匹配错误的公网地址


在不添加隧道的情况下使广州和上海使用VPN通信,可以通过ACL实现,但要注意ACL表会根据隧道标识的公网IP进行匹配。在总部允许10.1.1.0/24的数据包从第一个隧道通过

在广州允许广州到上海的数据包通过广州到北京的隧道

1
Router(config)#acc 100 permit ip 10.1.1.0 0.0.0.255 172.16.1.0 0.0.0.255

总部允许广州的数据包通过

1
2
3
4
5
6
7
8
9
10
11
12
13
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#do sh acc
Extended IP access list 100
10 permit ip 192.168.1.0 0.0.0.255 172.16.1.0 0.0.0.255
Extended IP access list 101
10 deny ip 192.168.1.0 0.0.0.255 172.16.1.0 0.0.0.255
20 deny ip 192.168.1.0 0.0.0.255 10.1.1.0 0.0.0.255 (20 match(es))
30 permit ip any any (2 match(es))
Extended IP access list 102
10 permit ip 192.168.1.0 0.0.0.255 10.1.1.0 0.0.0.255 (9 match(es))
Router(config)#acc 100 permit ip 10.1.1.0 0.0.0.255 172.16.1.0 0.0.0.255
Router(config)#

上海配置ACL,用于回包

1
2
3
4
5
6
7
Router(config)#acc 100 permit ip 172.16.1.0 0.0.0.255

/*由于部署了NAT,还需要做NAT豁免,否则数据包一到公网就被干掉*/

Router(config)#ip acc extended 101
Router(config-ext-nacl)#11 deny ip 172.16.1.0 0.0.0.255 10.1.1.0 0.0.0.255
Router(config-ext-nacl)#exit

最后总部做一条ACL,允许上海向广州回包

1
Router(config)#acc 102 permit ip 172.16.1.0 0.0.0.255 10.1.1.0 0.0.0.255