labunix's blog

labunixのラボUnix

FortigateのIPプールでのSNATを試してみた。

■FortigateのIPプールでのSNATを試してみた。
 以下の続き。

 Fortigateの[送信インターフェイスを使用する]NATについて調べてみた。
 http://labunix.hateblo.jp/entry/20150621/1434826042

■コンソールだとすぐに流れてしまうので注意。

$ script sample_flow.log; \
  sudo screen /dev/ttyS0

■TCPの10項目をトレースして、コンソールに表示する。

# diagnose debug flow show console enable
   diagnose debug flow filter proto 6
   diagnose debug flow trace start 10[送信インターフェイスを使用する]SNATのログ。

$ grep [SD]NAT sample_flow.log | sed s/".*line=[0-9]* "//g
msg="DNAT 192.168.1.250:25->172.31.31.254:25"
msg="Allowed by Policy-2: AV SNAT"
msg="SNAT 172.31.31.254->192.168.1.250:25"
msg="DNAT 192.168.1.250:25->172.31.31.254:25"
msg="SNAT 192.168.1.253->172.31.31.252:40498"
msg="DNAT 172.31.31.252:40498->192.168.1.253:40498"
msg="SNAT 192.168.1.253->172.31.31.252:40498"
msg="DNAT 172.31.31.252:40498->192.168.1.253:40498"
msg="SNAT 192.168.1.253->172.31.31.252:40498"

■Virtual IPの「Vmail」設定そのものが出力されていることが分かる。

# show | grep -f Vmail
config firewall vip
    edit "Vmail" <---
        set extip 192.168.1.250
        set extintf "wan1"
        set mappedip "172.31.31.254"
    next
end
config firewall policy
    edit 2
        set srcintf "wan1"
        set dstintf "internal"
        set srcaddr "all"
        set dstaddr "Vmail" <---
        set action accept
        set schedule "always"
        set service "SMTP"
        set utm-status enable
        set av-profile "default"
        set spamfilter-profile "default"
        set profile-protocol-options "default"
        set ssl-ssh-profile "certificate-inspection"
        set nat enable
    next
end

■送信元NATをIPプールのオブジェクトで指定。
 IPプールの種類は11# show | grep -f Vmail-Src
config firewall ippool
    edit "Vmail-Src" <---
        set type one-to-one
        set startip 192.168.1.250
        set endip 192.168.1.250
    next
end
config firewall policy
    edit 2
        set srcintf "wan1"
        set dstintf "internal"
        set srcaddr "all"
        set dstaddr "Vmail"
        set action accept
        set schedule "always"
        set service "SMTP"
        set utm-status enable
        set av-profile "default"
        set spamfilter-profile "default"
        set profile-protocol-options "default"
        set ssl-ssh-profile "certificate-inspection"
        set nat enable
        set ippool enable
        set poolname "Vmail-Src" <---
    next
end

■SNATのIPがIPプールのIPに変わったことで、通信が読みやすくなった。
 というか、こっちのNATの方がよく使う。

$ grep [SD]NAT sample_flow.log | sed s/".*line=[0-9]* "//g
msg="DNAT 192.168.1.250:25->172.31.31.254:25"
msg="Allowed by Policy-2: AV SNAT"
msg="SNAT 172.31.31.254->192.168.1.250:25"
msg="DNAT 192.168.1.250:25->172.31.31.254:25"
msg="SNAT 192.168.1.253->192.168.1.250:40628"
msg="DNAT 192.168.1.250:40628->192.168.1.253:40628"
msg="SNAT 192.168.1.253->192.168.1.250:40628"