顯示具有 Firewall 標籤的文章。 顯示所有文章
顯示具有 Firewall 標籤的文章。 顯示所有文章

2026年4月30日 星期四

Lab : Setting up a FortiGate VPN Client (OPNsense) with OTP

 

 使用軟體 opnsense

 https://opnsense.org/


先前導讀相關 Blog  

https://xrcd2.blogspot.com/2025/05/pfsense-fortigate.html

https://xrcd2.blogspot.com/2025/04/freeradius-google-authenticator-2fa.html


下載 ISO 用它開機後,使用 帳/密:  installer / opnsense 進入安裝模式,如有使用二張網卡,預設 WAN port 會使用 DHCP 取得IP/GW/DNS等相關資訊,LAN port IP 預設則為 192..168.1.1/24 可以透過 browser 連入 OPNsense,可使用 帳/密:  root / opnsense 登入OPNsense管理頁面.

接下來可以安裝  os-freeradius / os-net-snmp  等外掛,在安裝及設定完成後可以移除不使用的 WAN port ,以下這台OPNsense僅做 RADIUS 伺服器使用.


以下運用假設情境為 FortiGate VPN Client 透過 RADIUS 做 OTP 登入認證.


運作機制說明:使用者輸入密碼再加上 Google Authenticator APP 產生的 6 碼動態驗證碼(TOTP 協定)。[OTP 碼直接在密碼後面接者輸入即可.]

FortiGate 收到後將驗證請求轉發至後端的 RADIUS 伺服器(FreeRADIUS ).RADIUS 伺服器與綁定 Google Authenticator (OTP) 演算法的驗證比對後回傳驗證成功.


實驗簡要架構說明:


假設情境:

FortiGate VPN Client ===>(密碼加OTP)===> Fortigate Firewall ===> RADIUS (OPNsense Plugin) ===>  OPNsense 登入認證 (user id/pwd/otp) 


重點一.必需將 OPNsense \System\  Access \ Servers 新增一個 OTP-Server 

          Type 為 Local + Timebased One Time Password


重點二. 必需將 OPNsense \System\  Access \ Users \ 新增一個使用者並

         設定上密碼 及使用 OTP (這些資訊是用來提供 VPN 登入認證使用) 


重點三. 不使用 OPNsense \ Services \ FreeRADIUS \ Users 這個功能.


實驗證明: 

還真的不行,但OTP用來做  OPNsense 登入應該是可以的.

它的 FreeRADIUS 僅支援一般的帳密,不支援 OTP 


還是只能走回老路用   pfSense

FortiGate VPN Client ===>(密碼加OTP)===> Fortigate Firewall ===> RADIUS (pfSense Plugin) ===>  pfSense 登入認證 (user id/pwd/otp) 



OTP Demo










2026年3月13日 星期五

FortiGate SD-WAN Lab

 FortiGate SD-WAN Lab


實驗目地: 希望維持 WAN1 為主路由 )、 WAN2 為備路由 , 且 WAN2 的 Virtual Server 會通的設定方式.

又不影響到既有 WAN1上原有的任何服務或規則之下,加入新擴增 WAN2 的其它運用.

事前導讀請參關 FortiGate Policy Routes (PBR) Lab

 https://xrcd2.blogspot.com/2026/03/fortigate-policy-routes-pbr-lab.html


方案 (1) 浮動靜態路由模式 / 主備模式

 (設定簡略)

config router static

    edit 1

        set gateway 110.100.100.30

        set priority 1

        set device "port2"

    next

    edit 2

        set gateway 220.100.100.30

        set priority 2

        set device "port3"

    next

end



這個最為簡單,不需配合 Policy Routes (PBR) 相關設定. (推)



方案  (2) 軟體定義廣域網路(SD-WAN)模式.


這就需要大改了,但日後維運上更為方便.


SD-WAN移轉改接測試如下所示....

---> Rule 規則移轉 GG   (要人工介入大改後方可使用)

===> 這個方案需大改 [不推]


(設定簡略)

config system sdwan

    set status enable

    config zone

        edit "virtual-wan-link"

        next

    end

    config members

        edit 1

            set interface "port3"

            set gateway 220.100.100.30

        next

        edit 2

            set interface "port2"

            set gateway 110.100.100.30

        next

    end

    config health-check

        edit "WAN.1.GW"

            set server "110.100.100.30"

            set members 2

        next

        edit "WAN.2.GW"

            set server "220.100.100.30"

            set members 1

        next

    end

    config service

        edit 1

            set name "Prefer_WAN1"

            set mode priority

            set dst "all"

            set src "all"

            set health-check "WAN.1.GW"

            set priority-members 2 1

        next

    end

end


config router static

    edit 1

        set distance 1

        set sdwan-zone "virtual-wan-link"

    next

end


















DNAT




差異設定對照 rule

(1) 2 WAN

 


(2) SD-WAN 



差異設定對照 Static Routes

(1) 2 WAN



(2) SD-WAN 



Routing Table


(1) 2 WAN



(2) SD-WAN



SD-WAN Rule





FortiGate Policy Routes (PBR) Lab

 FortiGate Policy Routes (PBR) Lab

實驗目地: 希望維持 WAN1 為主路由 (Priority 10)、 WAN2 為備路由 (Priority 20), 且 WAN2 的 Virtual Server 會通.

實驗架構簡圖








Port3 Setting 


show routing table


 

Test WAN2 DNAT




順便再測一下 WAN1 DNAT 是否可以併存...(設定步驟這裡就省略了)



 

實驗設定(略)


config system interface

    edit "port1"

        set vdom "root"

        set ip 192.168.1.1 255.255.255.0

        set allowaccess ping https ssh http fgfm

        set type physical

        set snmp-index 1

    next

    edit "port2"

        set vdom "root"

        set ip 110.100.100.1 255.255.255.224

        set allowaccess ping

        set type physical

        set snmp-index 2

    next

    edit "port3"

        set vdom "root"

        set ip 220.100.100.1 255.255.255.224

        set allowaccess ping

        set type physical

        set src-check disable

        set snmp-index 3

    next



config firewall policy

    edit 1

        set name "WEB-IN"

        set uuid 872489d8-1ee5-51f1-91a3-9838e225d9f8

        set srcintf "port3"

        set dstintf "port1"

        set action accept

        set srcaddr "all"

        set dstaddr "WEB-DNAT"

        set schedule "always"

        set service "ALL"

    next

end





config firewall vip

    edit "WEB-DNAT"

        set uuid 528b1c78-1ee5-51f1-b558-b153d89f1cf2

        set extip 220.100.100.20

        set mappedip "192.168.1.20"

        set extintf "port3"

    next

end




config router static

    edit 1

        set gateway 110.100.100.30

        set device "port2"

    next

    edit 2

        set gateway 220.100.100.30

        set distance 20

        set device "port3"

    next

end



config router policy

    edit 1

        set input-device "port1"

        set srcaddr "WEB-Server"

        set dstaddr "all"

        set gateway 220.100.100.30

        set output-device "port3"

    next

end

2025年8月2日 星期六

X-Forwarded-For (XFF) LAB

以下實驗在於 X-Forwarded-For (XFF) 測試,驗證透過開源的CDN 軟體 Varnish

加上 FortiGate 的 Virtual server load balance 機制.取得真實 Client IP .

Varnish HTTP Cache 

https://www.varnish-cache.org


實驗架構



連線流程


Client [192.168.100.0/24] (設定 hosts 192.168.100.20 wps.cdn.tw ) 

--> CDN IP (192.168.100.20) --> 原站 IP [192.168.100.10] (FTG SLB VIP)

-->  FTG Firewall (192.168.100.125/192.168.1.1)

--> SLB Member (RealServer IP 192.168.1.11 or 12)

--> Nginx log  取得真實 Client IP


重要設定

[root@CDN ~]#  cat /etc/varnish/default.vcl

vcl 4.0;


backend default {

    .host = "127.0.0.1";

    .port = "8080";

}


acl purge {

    "localhost";

    "127.0.0.1";

}


sub vcl_recv {


    if (req.method == "PURGE") {

        if (!client.ip ~ purge) {

            return(synth(405, "DENY"));

        }

        return (purge);

    }


    if (req.url ~ "\.(gif|jpg|jpeg|swf|ttf|css|js|flv|mp3|mp4|pdf|ico|png)(\?.*|)$") {

        unset req.http.cookie;

    }

}


sub vcl_pipe {

    return (pipe);

}


sub vcl_pass {

    return (fetch);

}


sub vcl_backend_response {

.............


[root@CDN ~]#  cat /etc/nginx/nginx.conf


.....


server {

  listen 80;

  server_name wps.cdn.tw;

  port_in_redirect off;

  add_header Strict-Transport-Security "max-age=31536000;";

  add_header X-Content-Type-Options nosniff;

  location / {

    proxy_pass http://127.0.0.1:6081;

    proxy_set_header Host $http_host;

    proxy_set_header X-Forwarded-Host $http_host;

    proxy_set_header X-Real-IP $remote_addr;

    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    proxy_set_header X-Forwarded-Proto https;

    proxy_set_header HTTPS "on";

  }


}


server {

  listen 8080;

  server_name wps.cdn.tw;

  location / {

    proxy_pass http://192.168.100.10;

    proxy_set_header  Host $http_host;


.....



[root@CDN ~]#  dnf info varnish.x86_64

Last metadata expiration check: 1:15:24 ago on Sat 02 Aug 2025 01:18:24 PM CST.

Installed Packages

Name         : varnish

Version      : 6.6.2

Release      : 6.el9_6.1

Architecture : x86_64

Size         : 3.0 M

Source       : varnish-6.6.2-6.el9_6.1.src.rpm

Repository   : @System

From repo    : ol9_appstream

Summary      : High-performance HTTP accelerator

URL          : https://www.varnish-cache.org/

License      : BSD

Description  : This is Varnish Cache, a high-performance HTTP accelerator.

             :

             : Varnish Cache stores web pages in memory so web servers don’t have to

             : create the same web page over and over again. Varnish Cache serves

             : pages much faster than any application server; giving the website a

             : significant speed up.

             :

             : Documentation wiki and additional information about Varnish Cache is

             : available on: https://www.varnish-cache.org/


RealServer 上 Nginx log 設定


log_format  main  '$http_x_forwarded_for |

                    $http_x_real_ip |

                    $remote_addr - $remote_user [$time_local] "$request" '

                   '$status $body_bytes_sent "$http_referer" '

                   '"$http_user_agent" "$http_x_forwarded_for"';


Demo














2025年7月18日 星期五

PaloAlto Dual ISP with ECMP testing

 














tracert (Trace Route)





show routing route ecmp yes




其它補充:

如果要指定某一個 Source IP / Range ..走特定的 WAN x / ISP x ,
就同一般的[網通設備]一樣.
使用 政策路由 Policy-Based Route [PBR] 設定即可,
等同於 PaloAlto  的  Policy Based Forwarding  [PBF] 設定


判斷邏輯為: 
檢查是否有 PBF Rule -->  有命中則 依 PBF 決定路由
若沒命中則視  Routing Table  (可用 ECMP ) 決定其路由