使用IPsec-VPN實現本機資料中心IDC(Internet Data Center)和阿里雲VPC之間的網路互連時,在阿里雲側完成VPN網關的配置後,您還需在本機資料中心的網關裝置中添加VPN配置才能成功在本機資料中心和阿里雲VPC之間建立IPsec-VPN串連。本文介紹如何在FortiGate防火牆中添加VPN配置。
情境樣本
本文以上圖情境為例。某公司在阿里雲擁有一個Virtual Private Cloud(Virtual Private Cloud),VPC網段為10.0.0.0/16,VPC中使用Elastic Compute Service(Elastic Compute Service)部署了應用服務。同時該公司在本地擁有一個資料中心,本機資料中心中要與VPC互連的網段為192.168.0.0/16。公司計劃在本機資料中心與雲上VPC之間建立IPsec-VPN串連,實現資源互訪。
本文情境中,本機資料中心使用一台FortiGate防火牆的一個公網IP地址與阿里雲建立雙隧道模式的IPsec-VPN串連。如果您的情境需要建立單隧道模式的IPsec-VPN串連,請參見文末的單隧道配置樣本。
網段規劃及VPN配置樣本
網段規劃
資源 | 網段 | IP地址 |
本機資料中心 | 待和VPC互連的網段:192.168.0.0/16 | 伺服器IP地址:192.168.10.211 |
FortiGate防火牆 | 介面所屬網段:192.168.0.0/16 |
|
VPC | 主網段:10.0.0.0/16 交換器1:10.0.10.0/24 交換器2:10.0.20.0/24 | ECS IP地址:10.0.10.247 |
VPN網關執行個體(公網網路類型) | 不涉及 |
說明 建立VPN網關執行個體後,系統會自動為VPN網關執行個體分配地址。 |
BGP網段規劃
本文將分別描述IPsec-VPN串連使用靜態路由方式和BGP動態路由方式下如何配置FortiGate防火牆。如果您不需要使用BGP動態路由方式,可以忽略本部分。以下為本文的BGP網段規劃。
資源 | 隧道 | BGP隧道網段 | BGP IP地址 | BGP AS號(本端自治系統號) |
VPN網關執行個體 | 隧道1 | 169.254.10.0/30 說明 一個VPN網關執行個體下,每個隧道的網段需保持唯一。 | 169.254.10.1 | 65535 |
隧道2 | 169.254.20.0/30 | 169.254.20.1 | ||
FortiGate防火牆 | 隧道1 | 169.254.10.0/30 | 169.254.10.2 | 65500 |
隧道2 | 169.254.20.0/30 | 169.254.20.2 |
VPN配置樣本
本文情境中隧道1(主隧道)和隧道2(備隧道)使用相同的樣本值。
每條隧道下,阿里雲側和FortiGate防火牆側VPN配置需保持相同。
配置項 | 阿里雲側樣本值 | FortiGate防火牆側樣本值 | |
預先共用金鑰 | 123456**** | 123456**** | |
IKE配置 | IKE版本 | ikev2 | ikev2 |
協商模式 | main | main | |
密碼編譯演算法 | des | des 說明 本文情境中FortiGate防火牆使用的軟體版本不支援aes演算法,因此本文以des演算法作為樣本,推薦使用aes演算法。 | |
認證演算法 | sha1 | sha1 | |
DH分組 | group2 | group2 | |
SA生存周期(秒) | 86400 | 86400 | |
IPsec配置 | 密碼編譯演算法 | des | des 說明 本文情境中FortiGate防火牆使用的軟體版本不支援aes演算法,因此本文以des演算法作為樣本,推薦使用aes演算法。 |
認證演算法 | sha1 | sha1 | |
DH分組 | group2 | group2 | |
SA生存周期(秒) | 86400 | 86400 | |
前提條件
本文僅描述如何在FortiGate防火牆中添加VPN配置,不再描述阿里雲VPN網關側的配置。因此在您開始配置前,請確保您已經完成建立VPN網關執行個體、建立使用者網關、建立IPsec串連、配置VPN網關路由的任務,具體操作步驟:
靜態路由方式,請參見建立VPC到本機資料中心的串連(雙隧道模式)。
BGP動態路由方式,請參見建立VPC到本機資料中心的串連(雙隧道模式和BGP路由)。
本文情境中,本機資料中心使用FortiGate防火牆的一個公網IP地址與阿里雲建立雙隧道模式的IPsec-VPN串連,因此僅需建立一個使用者網關,建立IPsec串連時,兩條隧道關聯同一個使用者網關即可。
開始配置
下文以FortiOS V6.2.4為例介紹如何配置FortiGate防火牆。以下內容僅作樣本使用,具體配置命令請以廠商的配置手冊為準。
靜態路由方式
登入FortiGate防火牆命令列配置介面。
為FortiGate防火牆添加IPsec-VPN第一階段配置(IKE配置)。
#為隧道1添加IPsec-VPN第一階段配置 config vpn ipsec phase1-interface edit "to_aliyun_test1" set interface "port1" #指定介面為公網出口的介面。 set ike-version 2 set peertype any set net-device disable set proposal des-sha1 set localid-type address #指定localid的格式為IP地址格式,與阿里雲側隧道1 remoteid的格式保持一致。 set dhgrp 2 set remote-gw 8.XX.XX.146 #指定隧道1的對端地址為VPN網關執行個體的IPsec地址1。 set psksecret 123456**** #指定隧道1的預先共用金鑰,阿里雲側和FortiGate防火牆側需保持一致。 next end #為隧道2添加IPsec-VPN第一階段配置 config vpn ipsec phase1-interface edit "to_aliyun_test2" set interface "port1" #指定介面為公網出口的介面。 set ike-version 2 set peertype any set net-device disable set proposal des-sha1 set localid-type address #指定localid的格式為IP地址格式,與阿里雲側隧道2 remoteid的格式保持一致。 set dhgrp 2 set remote-gw 8.XX.XX.74 #指定隧道2的對端地址為VPN網關執行個體的IPsec地址2。 set psksecret 123456**** #指定隧道2的預先共用金鑰,阿里雲側和FortiGate防火牆側需保持一致。 next end為FortiGate防火牆添加IPsec-VPN第二階段配置(IPsec配置)。
#為隧道1添加IPsec-VPN第二階段配置 config vpn ipsec phase2-interface edit "to_aliyun_test1" set phase1name "to_aliyun_test1" #關聯隧道1的phase1-interface。 set proposal des-sha1 set dhgrp 2 set auto-negotiate enable set keylifeseconds 86400 next end #為隧道2添加IPsec-VPN第二階段配置 config vpn ipsec phase2-interface edit "to_aliyun_test2" set phase1name "to_aliyun_test2" #關聯隧道2的phase1-interface。 set proposal des-sha1 set dhgrp 2 set auto-negotiate enable set keylifeseconds 86400 next end配置防火牆策略。
config firewall policy edit 1 set name "forti_to_aliyun1" #指定隧道1下從FortiGate防火牆去往阿里雲方向允許通過的網段。 set srcintf "port4" set dstintf "to_aliyun_test1" set srcaddr "all" set dstaddr "all" set action accept set schedule "always" set service "ALL" next edit 2 set name "aliyun_to_forti1" #指定隧道1下從阿里雲去往FortiGate防火牆方向允許通過的網段。 set srcintf "to_aliyun_test1" set dstintf "port4" set srcaddr "all" set dstaddr "all" set action accept set schedule "always" set service "ALL" next edit 3 set name "forti_to_aliyun2" #指定隧道2下從FortiGate防火牆去往阿里雲方向允許通過的網段。 set srcintf "port4" set dstintf "to_aliyun_test2" set srcaddr "all" set dstaddr "all" set action accept set schedule "always" set service "ALL" next edit 4 set name "aliyun_to_forti2" #指定隧道2下從阿里雲去往FortiGate防火牆方向允許通過的網段。 set srcintf "to_aliyun_test2" set dstintf "port4" set srcaddr "all" set dstaddr "all" set action accept set schedule "always" set service "ALL" next end配置訪問VPC的靜態路由。
config router static edit 1 set dst 10.0.0.0 255.255.0.0 set priority 0 set device "to_aliyun_test1" next edit 2 set dst 10.0.0.0 255.255.0.0 set priority 10 #降低指向隧道2路由的優先順序,使流量優先通過隧道1傳輸。 set device "to_aliyun_test2" next end
BGP動態路由方式
登入FortiGate防火牆命令列配置介面。
為FortiGate防火牆添加IPsec-VPN第一階段配置(IKE配置)。
#為隧道1添加IPsec-VPN第一階段配置 config vpn ipsec phase1-interface edit "to_aliyun_test1" set interface "port1" #指定介面為公網出口的介面。 set ike-version 2 set peertype any set net-device disable set proposal des-sha1 set localid-type address #指定localid的格式為IP地址格式,與阿里雲側隧道1 remoteid的格式保持一致。 set dhgrp 2 set remote-gw 8.XX.XX.146 #指定隧道1的對端地址為VPN網關執行個體的IPsec地址1。 set psksecret 123456**** #指定隧道1的預先共用金鑰,阿里雲側和FortiGate防火牆側需保持一致。 next end #為隧道2添加IPsec-VPN第一階段配置 config vpn ipsec phase1-interface edit "to_aliyun_test2" set interface "port1" #指定介面為公網出口的介面。 set ike-version 2 set peertype any set net-device disable set proposal des-sha1 set localid-type address #指定localid的格式為IP地址格式,與阿里雲側隧道2 remoteid的格式保持一致。 set dhgrp 2 set remote-gw 8.XX.XX.74 #指定隧道2的對端地址為VPN網關執行個體的IPsec地址2。 set psksecret 123456**** #指定隧道2的預先共用金鑰,阿里雲側和FortiGate防火牆側需保持一致。 next end為FortiGate防火牆添加IPsec-VPN第二階段配置(IPsec配置)。
#為隧道1添加IPsec-VPN第二階段配置 config vpn ipsec phase2-interface edit "to_aliyun_test1" set phase1name "to_aliyun_test1" #關聯隧道1的phase1-interface。 set proposal des-sha1 set dhgrp 2 set auto-negotiate enable set keylifeseconds 86400 next end #為隧道2添加IPsec-VPN第二階段配置 config vpn ipsec phase2-interface edit "to_aliyun_test2" set phase1name "to_aliyun_test2" #關聯隧道2的phase1-interface。 set proposal des-sha1 set dhgrp 2 set auto-negotiate enable set keylifeseconds 86400 next end配置防火牆策略。
config firewall policy edit 1 set name "forti_to_aliyun1" #指定隧道1下從FortiGate防火牆去往阿里雲方向允許通過的網段。 set srcintf "port4" set dstintf "to_aliyun_test1" set srcaddr "all" set dstaddr "all" set action accept set schedule "always" set service "ALL" next edit 2 set name "aliyun_to_forti1" #指定隧道1下從阿里雲去往FortiGate防火牆方向允許通過的網段。 set srcintf "to_aliyun_test1" set dstintf "port4" set srcaddr "all" set dstaddr "all" set action accept set schedule "always" set service "ALL" next edit 3 set name "forti_to_aliyun2" #指定隧道2下從FortiGate防火牆去往阿里雲方向允許通過的網段。 set srcintf "port4" set dstintf "to_aliyun_test2" set srcaddr "all" set dstaddr "all" set action accept set schedule "always" set service "ALL" next edit 4 set name "aliyun_to_forti2" #指定隧道2下從阿里雲去往FortiGate防火牆方向允許通過的網段。 set srcintf "to_aliyun_test2" set dstintf "port4" set srcaddr "all" set dstaddr "all" set action accept set schedule "always" set service "ALL" next end為隧道介面配置BGP IP地址。
config system interface edit "to_aliyun_test1" set ip 169.254.10.2 255.255.255.255 #配置隧道1介面的BGP IP地址。 set remote-ip 169.254.10.1 255.255.255.255 #指定隧道1對端的BGP IP地址。 next edit "to_aliyun_test2" set ip 169.254.20.2 255.255.255.255 #配置隧道2介面的BGP IP地址。 set remote-ip 169.254.20.1 255.255.255.255 #指定隧道2對端的BGP IP地址。 next end配置BGP動態路由。
config router bgp set as 65500 set router-id 122.XX.XX.248 config neighbor edit "169.254.10.1" #指定隧道1的對端BGP鄰居。 set remote-as 65535 edit "169.254.20.1" set remote-as 65535 #指定隧道2的對端BGP鄰居。 next end config network edit 1 set prefix 192.168.0.0 255.255.0.0 #宣告本機資料中心側需要和VPC互連的網段。 next end config redistribute "connected" #將直串連口的路由重新導向發布到BGP中。 set status enable end end