Skip to content

FortiGate での NAT 設定例

FortiGate での NAT 設定例をメモしておきます。

検証環境

対象 バージョン
FortiOS 7.2.4

構成

file

初期設定

NAT とは関係の無い、定型の初期設定を行います。

config system console
    set output standard
end

config system global
    set admin-https-redirect disable
    set admintimeout 480
    set timezone 60
end

config system interface
    edit "port1"
        set mode static
        set ip 172.16.1.1 255.255.255.0
        set allowaccess ping https ssh http telnet
    next
end

config router static
    edit 1
        set dst 0.0.0.0 0.0.0.0
        set gateway 172.16.1.254
        set device "port1"
    next
end

インターフェイスアドレス&静的ルーティング設定

NAT の前提となる、インターフェイスアドレスと静的ルーティング設定を行います。

config system interface
    edit "port2"
        set mode static
        set ip 100.0.2.3 255.255.255.0
        set allowaccess ping
    next
    edit "port3"
        set mode static
        set ip 192.168.3.3 255.255.255.0
        set allowaccess ping
    next
end

config router static
    edit 2
        set dst 100.0.0.0 255.0.0.0
        set gateway 100.0.2.2
        set device "port2"
    next
    edit 3
        set dst 192.168.0.0 255.255.0.0
        set gateway 192.168.3.4
        set device "port3"
    next
end

LAN → INTERNET への NAT 設定

LAN → INTERNET への NAT 設定を行います。 INTERNET へ通信する際、パケットの送信元を「FortiGate の出力インターフェイスのアドレス」(今回は port2) へ変換する為、set nat enable を設定しています。

config firewall policy
    edit 1
        set name "policy1"
        set srcintf "port3"
        set dstintf "port2"
        set action accept
        set srcaddr "all"
        set dstaddr "all"
        set schedule "always"
        set service "ALL"
        set nat enable
    next
end

INTERNET → LAN への NAT 設定

100.0.2.100 というアドレスへ通信が発生した場合、LAN 内のサーバへトラフィックを転送する NAT 設定を行います。 VIP (Virtual IP) を設定した後、その VIP を宛先アドレスに設定する形でセキュリティポリシーを設定します。 今回は「送信元アドレスはそのまま維持する」為、set nat enable設定しません

config firewall vip
    edit "VIP_NatAddr1"
        set extip 100.0.2.100
        set mappedip "192.168.4.5"
        set extintf "port2"
    next
end

config firewall policy
    edit 2
        set name "NatAddr1"
        set srcintf "port2"
        set dstintf "port3"
        set action accept
        set srcaddr "all"
        set dstaddr "VIP_NatAddr1"
        set schedule "always"
        set service "ALL"
    next
end