FortiGate IPSec VPN 限制特定国家 IP 连接

  參加完 2025 資安大會後感覺透過限制 IP 來源的防護政策還是有一定的效果因此就在評估對現有 FortiGate VPN 增加相關設定首先已確認 FortiGate 可以設定以 國家/ 地理位址 做為辨識的「位址物件」所以後續就剩相關政策的設定與套用

  原先 AI 建議可以在《防火牆政策》設定 Wan → IPSec 來過濾但實際測試並沒有擋下來猜測是因為當建置 IPSec VPN 後FortiGate 會在《進入本機流量政策 (Local-In)》加入一個政策允許任何 IP 透過 IPSec 連入而造成《防火牆政策》無效因此要阻擋的話也需要從這個 Local In Policy 下手了

My firmware version is 7.4.7,In the graphical interface,Local In Policy can only be viewed,Cannot be modified,Therefore, after creating the 'Address Objects' for the relevant countries,Next, you need to enter the 'CLI Console',To modify the Local In Policy via commands。
(According to the official documentation,7.6.0 You can then configure it through the GUI。)

[FortiGate Environment]

  • Firmware version:7.4.7
  • VPN connection method:IPSec
  • Configuration purpose:只允許特定國家 IP 可以連線 IPSec VPN

【CLI 控制台】
  先說明一下以優先順序而言一般可能會先設定允許的規則再設定拒絕 All但因為我想先確認 Deny All 有生效所以我會先設定 Deny 的規則等最後全部設完再用 move 去調整 policy 的順序

1. 拒絕所有 IP 連線 IPSec VPN

config firewall local-in-policy
    edit 1
        set intf "virtual-wan-link" # virtual-wan-link 為 Interface 的名稱
        set srcaddr "all"
        set dstaddr "all"
        set action deny
        set service "IKE" "ESP"
        set schedule "always"
    next
end

2. 允許特定國家 IP 連線 IPSec VPN

config firewall local-in-policy
    edit 2
        set intf "virtual-wan-link"
        set srcaddr "Country-Allow"
        set dstaddr "all"
        set action accept
        set service "IKE" "ESP"
        set schedule "always"
    next
end

3. 调整 local-in-policy 顺序

config firewall local-in-policy
move 2 before 1
end

4. 查看最终设置结果

show firewall local-in-policy

 

【番外篇】
 在测试的过程中,如果想观察相关流量情况,可以通过以下指令进行。

1. 用 sniffer 观察任何进入 500, 4500 端口的流量

diag sniffer packet any 'port 500 or port 4500' 4 # 4 最詳細,1 最簡單

// 按 CTRL + C 結束

2. 用 debug 模式观察来自 123.123.123.123 的前 100 笔流量

diag debug reset
diag debug flow filter addr 123.123.123.123
diag debug flow trace start 100
diag debug enable

diag debug disable
diag debug reset

3. 用 debug 模式观察 IKE 流量

diag debug reset
diag debug console timestamp enable
diag debug application ike -1 # 等級從 1 ~ 15,-1 代表最詳細
diag debug enable

diag debug disable
diag debug reset

 

《相关链接》

1 条留言

留下回复

您的电子邮件地址不会被公开. 必填项已标注 *

本网站使用 Akismet 来减少垃圾评论. 了解您的评论数据如何被处理.