Router:sam-i-am(VPN Server)
Current configuration:
!
version 12.2
service timestamps debug uptime
service timestamps log up time
no service pass
Word-encryption
!
hostname sam-i-am
!
ip subnet-zero
!--- IKE配置
sam-i-am(config)#crypto isakmp policy 1 //定義策略為1
sam-i-am(isakmp)#hash
md5 //定義MD5散列算法
sam-i-am(isakmp)#authentication
PRe-share //定義為預共享密鑰認證方式
sam-i-am(config)#crypto isakmp key cisco123 address 0.0.0.0 0.0.0.0
!--- 配置預共享密鑰為cisco123,對等端為所有IP
!--- IPSec協議配置
sam-i-am(config)#crypto ipsec transform-set rtpset esp-des esp-md5-hmac
!--- 創建變換集 esp-des esp-md5-hmac
sam-i-am(config)#crypto dynamic-map rtpmap 10 //創建動態保密圖rtpmap 10
san-i-am(crypto-map)#set transform-set rtpset //使用上面的定義的變換集rtpset
san-i-am(crypto-map)#match address 115 //援引訪問列表確定受保護的流量
sam-i-am(config)#crypto map rtptrans 10 ipsec-isakmp dynamic rtpmap
!--- 將動態保密圖集加入到正規的圖集中
!
interface Ethernet0
ip address 10.2.2.3 255.255.255.0
no ip directed-broadcast
ip nat inside
no mop enabled
!
interface Serial0
ip address 99.99.99.1 255.255.255.0
no ip directed-broadcast
ip nat outside
crypto map rtptrans //將保密映射應用到S0接口上
!
ip nat inside source route-map nonat interface Serial0 overload
!--- 這個NAT配置啟用了路由策略,內容為10.2.2.0到10.1.1.0的訪問不進行地址
翻譯!--- 到其他網絡的訪問都翻譯成SO接口的IP地址
ip classless
ip route 0.0.0.0 0.0.0.0 Serial0 //配置靜態路由協議
no ip http server
!
access-list 115 permit ip 10.2.2.0 0.0.0.255 10.1.1.0 0.0.0.255
access-list 115 deny ip 10.2.2.0 0.0.0.255 any
!
access-list 120 deny ip 10.2.2.0 0.0.0.255 10.1.1.0 0.0.0.255
access-list 120 permit ip 10.2.2.0 0.0.0.255 any
!
sam-i-am(config)#route-map nonat permit 10 //使用路由策略
sam-i-am(router-map)#match ip address 120
!
line con 0
transport input none
line aux 0
line vty 0 4
password ww
login
!
end
Router:dr_whoovie(VPN Client)
Current configuration:
!
version 12.2
service timestamps debug uptime
service timestamps log uptime
no service password-encryption
!
hostname dr_whoovie
!
ip subnet-zero
!
dr_whoovie(config)#crypto isakmp policy 1 //定義策略為1
dr_whoovie(isakmp)#hash md5 //定義MD5散列算法
dr_whoovie(isakmp)#authentication pre-share //定義為預共享密鑰認證方式
dr_whoovie(config)#crypto isakmp key cisco123 address 99.99.99.1
!--- 配置預共享密鑰為cisco123,對等端為服務器端IP99.99.99.1
!--- IPSec協議配置
dr_whoovie(config)#crypto ipsec transform-set rtpset esp-des esp-md5-hmac
!--- 創建變換集 esp-des esp-md5-hmac
dr_whoovie(config)#crypto map rtp 1 ipsec-isakmp
!--- 使用IKE創建保密圖rtp 1
dr_whoovie(crypto-map)#set peer 99.99.99.1 //確定遠程對等端
dr_whoovie(crypto-map)#set transform-set rtpset //使用上面的定義的變換集rtpset
dr_whoovie(crypto-map)#match address 115 //援引訪問列表確定受保護的流量
!
interface Ethernet0
ip address 10.1.1.1 255.255.255.0
no ip directed-broadcast
ip nat inside
no mop enabled
!
interface Serial0
ip address negotiated //IP地址自動獲取
no ip directed-broadcast
ip nat outside
encapsulation ppp //S0接口封裝ppp協議
no ip mroute-cache
no ip route-cache
crypto map rtp //將保密映射應用到S0接口上
!
ip nat inside source route-map nonat interface Serial0 overload
!--- 這個NAT配置啟用了路由策略,內容為10.1.1.0到10.2.2.0的訪問不進行地址翻譯
!--- 到其他網絡的訪問都翻譯成SO接口的IP地址
ip classless
ip route 0.0.0.0 0.0.0.0 Serial0 //配置靜態路由協議
no ip http server
!
access-list 115 permit ip 10.1.1.0 0.0.0.255 10.2.2.0 0.0.0.255
access-list 115 deny ip 10.1.1.0 0.0.0.255 any
access-list 120 deny ip 10.1.1.0 0.0.0.255 10.2.2.0 0.0.0.255
access-list 120 permit ip 10.1.1.0 0.0.0.255 any
!
dialer-list 1 protocol ip permit
dialer-list 1 protocol ipx permit
route-map nonat permit 10 //使用路由策略
match ip address 120
!
line con 0
transport input none
line aux 0
line vty 0 4
password ww
login
!
end

screen.width-255) {this.width=screen.width-255;this.alt='本圖片已被縮小,點擊查看原大小圖片。';}" border=0>
-----------IKE配置----------------
IPSec VPN對等端為了建立信任關系,必須交換某種形式的認證密鑰。
Internet 密鑰交換(Internet Key Exchange,IKE)是一種為IPSec治理和交換密鑰的標準方法。
一旦兩個對等端之間的IKE協商取得成功,那么IKE就創建到遠程對等端的安全關聯(security association,SA)。SA是單向的;在兩個對等端之間存在兩
個SA。
IKE使用UDP端口500進行協商,確保端口500不被阻塞。
配置
1、(可選)啟用或者禁用IKE
(global)crypto isakmp enable
或者
(global)no crypto isakmp enable
默認在所有接口上啟動IKE
2、創建IKE策略
(1)定義策略
(global)crypto isakmp policy priority
注釋:policy 1表示策略1,假如想多配幾個VPN,可以寫成policy 2、policy3┅
(2)(可選)定義加密算法
(isakmp)encryption {des 3des}
加密模式可以為56位的DES-CBC(des,默認值)或者168位的3DES(3des)
(3)(可選)定義散列算法
(isamkp)hash {sha md5}
默認sha
(4)(可選)定義認證方式
(isamkp)authentication {rsa-sig rsa-encr pre-share}
rsa-sig 要求使用CA并且提供防止抵賴功能;默認值
rsa-encr 不需要CA,提供防止抵賴功能
pre-share 通過手工配置預共享密鑰
(5)(可選)定義Diffie-Hellman標識符
(isakmp)group {1 2}
注釋:除非購買高端路由器,或是VPN通信比較少,否則最好使用group 1長度的密鑰,group命令有兩個參數值:1和2。參數值1表示密鑰使用768位密鑰,
參數值2表示密鑰使用1024位密鑰,顯然后一種密鑰安全性高,但消耗更多的CPU時間。
(6)(可選)定義安全關聯的生命期
(isakmp)lifetime seconds
注釋:對生成新SA的周期進行調整。這個值以秒為單位,默認值為86400,也就是一天。值得注重的是兩端的路由器都要設置相同的SA周期,否則VPN在正
常初始化之后,將會在較短的一個SA周期到達中斷。
3、(rsa-sig)使用證書授權(CA)
(1)確保路由器有主機名和域名
(global)hostname hostname
(global)ip domain-name domain
(2)產生RSA密鑰
(global)crypto key generate rsa
(3)使用向IPSec對等端發布證書的CA
--設定CA的主機名
(global)crypto ca identity name
--設定聯絡CA所使用的URL
(ca-identity)enrollment url url
URL應該采用http://ca-domain-name

ort/cgi-bin-location的形式
--(可選)使用RA模式
(ca-identity)enrollment mode ra
(ca-identity)query url url
--(可選)設定注冊重試參數
(ca-identity)enrollment retry period minutes
(ca-identity)enrollment retry count number
minutes(1到60;默認為1) number(1到100;默認為0,代表無窮次)
--(可選)可選的證書作廢列表
(ca-identity)crl optional
(4)(可選)使用可信的根CA
--確定可信的根CA
(global)crypto ca trusted-root name
--(可選)從可信的根請求CRL
(ca-root)crl query url
--定義注冊的方法
(ca-root)root {CEP url TFTP server file PROXY url}
(5)認證CA
(global)crypto ca authenticate name
(6)用CA注冊路由器
(global)crypto ca enroll name
4、(rsa-encr)手工配置RSA密鑰(不使用CA)
(1)產生RSA密鑰
(global)crypto key generate rsa
(2)指定對等端的ISAKMP標識
(global)crypto isakmp identity {address hostname}
(3)指定其他所有對等端的RSA密鑰
--配置公共密鑰鏈
(global)crypto key pubkey-chain rsa
--用名字或地址確定密鑰
(pubkey-chain)named-key key-name [encryption signature]
(pubkey-chain)addressed-key key-name [encryption signature]
--(可選)手工配置遠程對等端的IP地址
(pubkey-key)address ip-addr
--指定遠程對等端的公開密鑰
(pubkey-key)key-string key-string
5、(preshare)配置預共享密鑰
(global)crypto isakmp key key-string {add
rss hostname} {peer-address peer-hostname}
注釋:返回到全局設置模式確定要使用的預先共享密鑰和指歸VPN另一端路由器IP地址,即目的路由器IP地址。相應地在另一端路由器配置也和以上命令類
似
6、(可選)使用IKE模式
(1)定義要分發的“內部”或者受保護IP地址庫
(global)ip local pool pool-name start-address end-address
(2)啟動IKE模式協商
(global)crypto isakmp client configuration address-pool local pool-name
--------------IPSec配置----------------
IPSec 使用加密、數據完整性、源發鑒別以及拒絕重演分組來保護和認證網絡層對等端之間的IP分組
IPSec對于構建內因網、外因網以及遠程用戶接入VPN來說非常有用處
IPSec支持以下標準
--Internet協議的安全體系結構
--IKE(Internet密鑰交換)
--DES(數據加密標準)
--MD5
--SHA
--AH(Authentication Header,認證首部)數據認證和反重演(anti-reply)服務
--ESP(Encapsulation Security Payload,封裝安全凈荷)數據隱私、數據驗證以及反重演(anti-reply)服務
敏感流量由訪問列表所定義,并且通過crypto map(保密圖)集被應用到接口上。
配置
1、為密鑰治理配置IKE
2、(可選)定義SA的全局生命期
(global)crypto ipsec security-association lifetime seconds seconds
(global)crypto ipsec security-association lifetime killobytes kilobytes
3、定義保密訪問列表來定義受保護的流量
(global)access-list access-list-number ....
或者
(global)ip access-list extended name
擴展的訪問列表必須定義由IPSec保護哪種IP流量。保密圖(crypto map)援引這個訪問列表來確定在接口上要保護的流量。
4、定義IPSec交換集
(1)創建變換集
(global)crypto ipsec transform-set name [transform1 transform2 transform3]
可以在一個保密圖(crypto map)中定義多個變換集。假如沒有使用IKE,那么只能定義一種變換集。用戶能夠選擇多達三種變換。
(可選)選擇一種AH變換
--ah-md5-hmac
--ah-sha-hmac
--ah-rfc-1828
(可選)選擇一種ESP加密編號
--esp-des
--esp-3des
--esp-rfc-1829
--esp-null
以及這些驗證方法之一
--esp-md5-hmac
--esp-sha-hmac
(可選)選擇IP壓縮變換
--comp-lzs
(2)(可選)選擇變換集的模式
(crypto-transform)mode {tunnel transport}
5、使用IPSec策略定義保密映射
保密圖(crypto map)連接了保密訪問列表,確定了遠程對等端、本地地址、變換集和協商方法。
(1)(可選)使用手工的安全關聯(沒有IKE協商)
--創建保密圖
(global)crypto map map-name sequence ipsec-manual
--援引保密訪問列表來確定受保護的流量
(crypto-map)match address access-list
--確定遠程的IPSec對等端
(crypto-map)set peer {hostname ip_addr}
--指定要使用的變換集
(crypto-map)set transform-set name
變換集必須和遠程對等端上使用的相同
--(僅適用于AH驗證)手工設定AH密鑰
(crypto-map)set
session-key inbound ah spi hex-key-data
(crypto-map)set session-key outbound ah spi hex-key-data
--(僅適用于ESP驗證)手工設定ESP SPI和密鑰
(crypto-map)set session-key inbound ah spi hex-key-data [authenticator hex-key-data]
(crypto-map)set session-key outbound ah spi hex-key-data [authenticator hex-key-data]
(2)(可選)使用IKE建立的安全關聯
--創建保密圖
(global)crypto map map-name sequence ipsec-isakmp
--援引保密訪問列表來確定受保護的流量
(crypto-map)match address access-list
--確定遠程的IPSec對等端
(crypto-map)set peer {hostname ip_addr}
--指定要使用的變換集
(crypto-map)set transform-set name
變換集必須和遠程對等端上使用的相同
--(可選)假如SA生命期和全局默認不同,那么定義它:
(crypto-map)set security-association lifetime seconds seconds
(crypto-map)set security-association lifetime kilobytes kilobytes
--(可選)為每個源/目的主機對使用一個獨立的SA
(crypto-map)set security-association level per-host
--(可選)對每個新的SA使用完整轉發安全性
(crypto-map)set pfs [group1 group2]
(3)(可選)使用動態安全關聯
--創建動態的保密圖
(global)crypto dynamic-map dyn-map-name dyn-seq-num
--(可選)援引保密訪問列表確定受保護的流量
(crypto-map)match address access-list
--(可選)確定遠程的IPSec對等端
(crypto-map)set peer {hostname ip_addr}
--(可選)指定要使用的變換集
(crypto-map)set transform-set tranform-set-name
--(可選)假如SA生命期和全局默認不同,那么定義它:
(crypto-map)set security-association lifetime seconds seconds
(crypto-map)set security-association lifetime kilobytes kilobytes
--(可選)對每個新的SA使用完整轉發安全性
(crypto-map)set pfs [group1 group2]
--將動態保密圖集加入到正規的圖集中
(global)crypto map map-name sequence ipsec-isakmp dynamic dyn-map-name [discover]
--(可選)使用IKE模式的客戶機配置
(global)crypto map map-name client configuration address [initiate respond]
--(可選)使用來自AAA服務器的預共享IKE密鑰
(global)crypto map map-name isakmp authorization list list-name
6、將保密映射應用到接口上
(1)指定要使用的保密映射
(interface)crypto map map-name
(2)(可選)和其他接口共享保密映射
(global)crypto map map-name local-address interface-id