文档

FortiGate防火墙配置示例

更新时间:

使用IPsec-VPN实现本地数据中心IDC(Internet Data Center)和阿里云VPC之间的网络互通时,在阿里云侧完成VPN网关的配置后,您还需在本地数据中心的网关设备中添加VPN配置才能成功在本地数据中心和阿里云VPC之间建立IPsec-VPN连接。本文介绍如何在FortiGate防火墙中添加VPN配置。

场景示例

image

本文以上图场景为例。某公司在阿里云拥有一个专有网络VPC(Virtual Private Cloud),VPC网段为10.0.0.0/16,VPC中使用云服务器ECS(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

  • FortiGate防火墙连接公网的物理接口:port1,并为port1接口配置公网IP地址122.XX.XX.248。

  • FortiGate防火墙连接本地数据中心的物理接口:port4,并为port4接口配置私网IP地址192.168.10.221/24。

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网关实例(公网网络类型)

不涉及

  • IPsec地址1:8.XX.XX.146

  • IPsec地址2:8.XX.XX.74

说明

创建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网关路由的任务,具体操作步骤:

说明

本文场景中,本地数据中心使用FortiGate防火墙的一个公网IP地址与阿里云建立双隧道模式的IPsec-VPN连接,因此仅需创建一个用户网关,创建IPsec连接时,两条隧道关联同一个用户网关即可。

开始配置

说明

下文以FortiOS V6.2.4为例介绍如何配置FortiGate防火墙。以下内容仅作示例使用,具体配置命令请以厂商的配置手册为准。

静态路由方式

  1. 登录FortiGate防火墙命令行配置界面。

  2. 为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
  3. 为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
  4. 配置防火墙策略。

    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
  5. 配置访问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动态路由方式

  1. 登录FortiGate防火墙命令行配置界面。

  2. 为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
  3. 为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
  4. 配置防火墙策略。

    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
  5. 为隧道接口配置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
  6. 配置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

单隧道配置示例

单击查看配置示例。

场景示例

image

本文以上图场景为例。某公司在阿里云拥有一个VPC,VPC网段为192.168.10.0/24,VPC中使用ECS部署了应用服务。同时该公司在本地拥有一个数据中心,本地数据中心中要与VPC互通的网段为192.168.66.0/24。公司计划在本地数据中心与云上VPC之间建立IPsec-VPN连接,实现资源互访。

网段规划及VPN配置示例

网段规划

资源

示例值

VPC

待和本地数据中心互通的私网网段

192.168.10.0/24

VPN网关(公网网络类型)

VPN网关公网IP地址

101.XX.XX.127

本地数据中心

待和VPC互通的私网网段

192.168.66.0/24

FortiGate防火墙的公网IP地址

122.XX.XX.248

FortiGate防火墙连接公网的物理接口

WAN:为WAN口配置公网IP地址122.XX.XX.248

FortiGate防火墙连接本地数据中心的物理接口

LAN:为LAN口配置私网IP地址192.168.66.125/24

VPN配置示例

配置项

阿里云侧示例值

FortiGate防火墙侧示例值

预共享密钥

ff123TT****

ff123TT****

IKE配置

IKE版本

ikev1

ikev1

协商模式

main

main

加密算法

aes

aes

认证算法

sha1

sha1

DH分组

group2

group2

SA生存周期(秒)

86400

86400

IPsec配置

加密算法

aes

aes

认证算法

sha1

sha1

DH分组

group2

group2

SA生存周期(秒)

86400

86400

前提条件

本文仅描述如何在FortiGate防火墙中添加VPN配置,不再描述阿里云VPN网关侧的配置,本文使用静态路由方式。在开始配置前,请确保您已在阿里云侧完成创建VPN网关、创建用户网关、创建IPsec连接、配置VPN网关路由的操作。具体操作,请参见建立VPC到本地数据中心的连接(单隧道模式)

开始配置

说明

下文以FortiOS 7.0为例介绍如何配置FortiGate防火墙。以下内容仅作示例使用,具体配置命令请以厂商的配置手册为准。

  1. 登录FortiGate防火墙命令行配置界面。

  2. 为FortiGate防火墙添加IPsec-VPN第一阶段配置(IKE配置)。

    config vpn ipsec phase1-interface
        edit "to_AliCloud"
            set interface "wan"
            set peertype any
            set net-device disable
            set proposal aes128-sha1
            set dpd on-idle
            set dhgrp 2
            set keylife 86400
            set remote-gw 101.XX.XX.127        #指定隧道对端地址为VPN网关实例公网IP地址。
            set psksecret ff123TT****          #指定隧道的预共享密钥,阿里云侧和FortiGate防火墙侧需保持一致。
        next
    end
  3. 为FortiGate防火墙添加IPsec-VPN第二阶段配置(IPsec配置)。

config vpn ipsec phase2-interface
    edit "to_AliCloud"
        set phase1name "to_AliCloud"            #关联隧道的phase1-interface。
        set proposal aes128-sha1
        set dhgrp 2
        set keylifeseconds 86400
        set auto-negotiate enable
    next
end
  1. 配置防火墙策略。

    onfig firewall address                             #定义地址段
        edit "Local_192.168.66.0/24"
            set subnet 192.168.66.0 255.255.255.0
        next
        edit "Remote_192.168.10.0/24"
            set subnet 192.168.10.0 255.255.255.0
        next
        edit "AliCloud_VPN_Gateway"
            set subnet 101.XX.XX.127 255.255.255.255
        next
    end
    
    config firewall policy
        edit 4
            set srcintf "lan"
            set dstintf "to_AliCloud"                  #指定隧道下从FortiGate防火墙去往阿里云方向允许通过的网段。
            set action accept
            set srcaddr "Local_192.168.66.0/24"
            set dstaddr "Remote_192.168.10.0/24"
            set schedule "always"
            set service "ALL"
        next
        edit 5
            set srcintf "to_AliCloud"                   #指定隧道下从阿里云去往FortiGate防火墙方向允许通过的网段。
            set dstintf "lan"
            set action accept
            set srcaddr "Remote_192.168.10.0/24"
            set dstaddr "Local_192.168.66.0/24"
            set schedule "always"
            set service "ALL"
        next
    end
  2. 配置访问VPC的静态路由。

    config router static
        edit 3
            set dst 192.168.10.0 255.255.255.0   
            set device "to_AliCloud"
        next
        edit 4
            set dst 192.168.10.0 255.255.255.0
            set distance 254
            set blackhole enable
        next
    end
  3. 为FortiGate配置Local-in policy。

    重要

    为FortiGate配置Local-in policy,在没有IKE会话建立的情况下,丢弃阿里云侧发来的IKE协商包。请注意此步骤非常重要,不配置很可能会出现与IPsec-VPN连接中断后无法重新建立的情况。

    config firewall local-in-policy
        edit 1
            set intf "wan"
            set srcaddr "AliCloud_VPN_Gateway"
            set dstaddr "all"
            set service "IKE"
            set schedule "always"
            set action deny
        next
    end