Bài 08 · Phụ lục

FortiGate-VM làm Firewall trên cụm Hyper-V

Dựng firewall vành đai FortiGate ngay trên cụm — phục vụ NAT/VIP, phân vùng DMZ/Internal và bảo vệ dịch vụ public của hệ thống Capstone (Bài 07), có HA.

Về Bài 07 — Capstone

Tại sao chạy FortiGate-VM trên cụm?

Thay vì mua thiết bị firewall vật lý, có thể chạy FortiGate-VM (FGT_VM64_HV) như một VM HA trên chính cụm Hyper-V. Nó đảm nhận vai trò firewall vành đai của hệ thống Capstone: định tuyến WAN, NAT/VIP đưa dịch vụ ra Internet, và tách DMZ ⇄ Internal.

Ưu điểm

  • HA theo cụm (failover khi 1 host chết)
  • Không tốn thiết bị vật lý riêng
  • Snapshot/backup như VM thường
  • Mở rộng/nâng cấp linh hoạt

Lưu ý

  • Image Hyper-V của FortiGate là Generation 1
  • Cần license (eval 15 ngày / BYOL / subscription)
  • Phải tắt VMQ + bật MAC spoofing trên vNIC
  • WAN cần card/vSwitch nối thẳng Internet

Chuẩn bị

  • Tải image FGT_VM64_HV-*.hyperv.zip từ support.fortinet.com → giải nén lấy file .vhd.
  • License: tài khoản Fortinet → eval/đăng ký, hoặc file .lic (BYOL).
  • Tài nguyên tối thiểu: 1 vCPU, 2 GB RAM (RAM tĩnh, tắt Dynamic Memory), ổ thêm cho log.
  • Đặt VHD lên CSV (C:\ClusterStorage\Volume1) để VM có HA.

Ánh xạ cổng ⇄ vSwitch ⇄ VLAN

Port FortiGatevSwitch Hyper-VVùngIP mẫu
port1 (WAN)External-WANInternet203.0.113.10/24
port2 (LAN)vSwitch-LAN · VLAN 20Server-Internal10.100.20.1/24 (gateway)
port3 (DMZ)vSwitch-LAN · VLAN 40DMZ10.100.40.1/24 (gateway)
port4 (MGMT)vSwitch-Mgmt · VLAN 10Management10.100.10.1/24

FortiGate làm gateway cho VLAN 20 & 40 — các VM nội bộ/DMZ trỏ default gateway về IP port tương ứng của FortiGate.

🧪 LAB — Triển khai FortiGate-VM + NAT dịch vụ public

Mục tiêu: dựng FGT01 trên cụm với 4 cổng, cấu hình WAN/LAN/DMZ, rồi tạo VIP NAT 443 → RPROXY01 (DMZ) để đưa web app ra Internet — khớp Capstone Bài 07.

1

Chuẩn bị vSwitch (WAN ra Internet + LAN trunk + Mgmt)

# Card nối Internet làm External-WAN; card nội bộ làm vSwitch-LAN (trunk VLAN) New-VMSwitch -Name "External-WAN" -NetAdapterName "NIC-WAN" -AllowManagementOS $false # vSwitch-LAN và vSwitch-Mgmt giả định đã tạo ở các bài trước

Cách GUI: Hyper-V Manager → Virtual Switch Manager → New → External → tên "External-WAN" → chọn card nối Internet → bỏ tick "Allow management OS".

2

Tạo VM FortiGate (Gen1) + gắn VHD + 4 vNIC

$fgt = "FGT01" # Dùng chính file .vhd của FortiGate (không tạo đĩa mới) New-VM -Name $fgt -Generation 1 -MemoryStartupBytes 2GB ` -VHDPath "C:\ClusterStorage\Volume1\FGT01\fortios.vhd" -SwitchName "External-WAN" Set-VMMemory -VMName $fgt -DynamicMemoryEnabled $false # port2 LAN, port3 DMZ, port4 MGMT Add-VMNetworkAdapter -VMName $fgt -SwitchName "vSwitch-LAN" Add-VMNetworkAdapter -VMName $fgt -SwitchName "vSwitch-LAN" Add-VMNetworkAdapter -VMName $fgt -SwitchName "vSwitch-Mgmt"

Cách GUI: Hyper-V Manager → New → Virtual Machine → Generation 1 → "Use an existing virtual hard disk" trỏ tới fortios.vhd → switch "External-WAN". Memory: bỏ Dynamic. VM Settings → Add Hardware → Network Adapter ×3 (LAN/DMZ/Mgmt).

3

Bắt buộc: tắt VMQ + bật MAC spoofing + gán VLAN, rồi vào cụm

# FortiOS cần MAC spoofing ON và VMQ OFF để chạy/định tuyến đúng Get-VMNetworkAdapter -VMName $fgt | Set-VMNetworkAdapter -MacAddressSpoofing On -VmqWeight 0 # VLAN cho port2 (LAN20) và port3 (DMZ40) — theo thứ tự adapter $nics = Get-VMNetworkAdapter -VMName $fgt Set-VMNetworkAdapterVlan -VMNetworkAdapter $nics[1] -Access -VlanId 20 Set-VMNetworkAdapterVlan -VMNetworkAdapter $nics[2] -Access -VlanId 40 Add-ClusterVirtualMachineRole -VirtualMachine $fgt Start-VM $fgt

Cách GUI: VM Settings → từng Network Adapter → Advanced Features → tick "Enable MAC address spoofing", bỏ tick "Virtual Machine Queue (VMQ)"; với port2/port3 tick "Enable virtual LAN identification" → VLAN 20 / 40. Failover Cluster Manager → Roles → Configure Role → Virtual Machine (HA).

4

Cấu hình cơ bản qua console (đăng nhập admin, mật khẩu trống)

# Đặt IP WAN/LAN/DMZ config system interface edit port1 set mode static set ip 203.0.113.10 255.255.255.0 set allowaccess ping https ssh next edit port2 set ip 10.100.20.1 255.255.255.0 set allowaccess ping https ssh next edit port3 set ip 10.100.40.1 255.255.255.0 next end # Default route ra Internet config router static edit 1 set gateway 203.0.113.1 set device port1 next end

Cách GUI: Đăng nhập FortiGate Web UI (https://<IP port>) → Network → Interfaces → sửa port1 (WAN), port2 (LAN), port3 (DMZ) → IP/Administrative Access; Network → Static Routes → tạo default route ra port1.

5

VIP NAT 443 → RPROXY01 + policy WAN→DMZ

# Port-forward 443 từ WAN tới reverse proxy trong DMZ config firewall vip edit "VIP-HTTPS" set extip 203.0.113.10 set extintf port1 set portforward enable set mappedip 10.100.40.10 set extport 443 set mappedport 443 next end config firewall policy edit 1 set name "WAN-to-DMZ-HTTPS" set srcintf port1 set dstintf port3 set srcaddr all set dstaddr "VIP-HTTPS" set action accept set schedule always set service HTTPS set utm-status enable next end

Cách GUI: FortiGate Web UI → Policy & Objects → Virtual IPs → Create New (port-forward 443 → 10.100.40.10); rồi Policy & Objects → Firewall Policy → Create New (WAN→DMZ, dst = VIP, service HTTPS, bật UTM).

Kiểm chứng: từ Internet mở https://203.0.113.10 → ra RPROXY01 → WEB01. Trên FortiGate: get router info routing-table all thấy default route; diagnose sniffer packet thấy lưu lượng 443. Tắt 1 host → FGT01 failover, firewall vẫn hoạt động.

HA: 2 lớp dự phòng

  • HA cấp cụm (cơ bản): FGT01 là VM HA — 1 host chết, cụm bật lại FGT01 trên node kia (gián đoạn ngắn ~30–60s).
  • FGCP HA (nâng cao): chạy 2 VM FortiGate (FGT01 active + FGT02 passive) trên 2 host khác nhau (anti-affinity), đồng bộ cấu hình + session — chuyển mạch gần như tức thì. Cần thêm 1 vNIC HA heartbeat và bật MAC spoofing.

Với FGCP, đặt 2 FortiGate anti-affinity để không bao giờ nằm cùng 1 host vật lý.

Hardening FortiGate

  • Đổi mật khẩu admin mặc định; bật 2FA cho admin.
  • Giới hạn quản trị bằng trusted host (chỉ VLAN Management); tắt HTTP/Telnet.
  • Chỉ mở allowaccess cổng cần thiết trên từng interface (WAN không bật https/ssh).
  • Bật UTM: IPS, AV, Web Filter, Application Control trên policy WAN→DMZ.
  • Cập nhật firmware + chữ ký FortiGuard định kỳ; bật log gửi về MON01.