labunix's blog

labunixのラボUnix

Fortigateの[送信インターフェイスを使用する]NATについて調べてみた。

■Fortigateの[送信インターフェイスを使用する]NATについて調べてみた。

 静的NAT、動的ATの区別では静的NAT。
 [送信インタフェースのアドレスを使用]はCheckPoint社の[Hide NAT]みたいなもの。
 Juniper社のSRXだと普通に[ソースNAT/インターフェイスNAT]。

■注意事項
 Fortigate-80CはFortiASIC-NPを搭載したモデルでは無いのでNPを無効にする必要は無い。
 メモリは512MB。100MbpsのNICという点でも少ない。(WANは最大1GBps)
 Pentium II世代のCeleron (Covington)だけど、動作周波数から考えると
 Pentium III世代の600MHz。どちらにせよ古い世代のCPU。
 デスクトップモデルはリソースに余裕が無いため、
 パケットキャプチャを行うのは評価に限定した方が良い。

# get system status | grep ^Ver
Version: FortiGate-80C v5.2.3,build0670,150318 (GA)

# get hardware status | grep "^ASIC\|^RAM"
ASIC version: CP6
ASIC SRAM: 64M
RAM: 499 MB

# diagnose hardware sysinfo memory | grep "^ \|^Mem:"
        total:    used:    free:  shared: buffers:  cached: shm:
Mem:  523649024 275009536 248639488        0   241664 148897792 123682816

# get hardware nic wan1 | grep Speed
Speed                           100
# get hardware nic dmz | grep Speed
Speed                   100
# get hardware nic internal | grep Speed
Speed                   100

# diagnose hardware sysinfo cpu | grep "^model\|^cpu"
cpu family      : 6
model           : 5
model name      : Celeron (Covington)
cpu MHz         : 600.037
cpuid level     : 2

■許可ポリシーのNAT
 NATはFortigateの送信インターフェイスのIPを使用する設定なので、
 以下の流れを想定。戻りはすべて逆方向。

    メールクライアントIP
  -> wan1(Vmail IP)              -> wan1(interfaceIP)
  -> internal(interfaceIP)    -> internal(Vmail IP)
  -> メールサーバIP

# show firewall policy | grep -f "internal\|wan1"
config firewall policy
    edit 1
        set srcintf "internal" <---
        set dstintf "wan1" <---
        set srcaddr "all"
        set dstaddr "all"
        set action accept
        set schedule "always"
        set service "ALL"
        set utm-status enable
        set av-profile "default"
        set webfilter-profile "default"
        set spamfilter-profile "default"
        set ips-sensor "default"
        set application-list "default"
        set profile-protocol-options "default"
        set ssl-ssh-profile "certificate-inspection"
        set nat enable
    next
    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 spamfilter-profile "default"
        set profile-protocol-options "default"
        set ssl-ssh-profile "certificate-inspection"
        set nat enable
    next
end

# show firewall vip | grep -f Vmail
config firewall vip
    edit "Vmail" <---
        set extip 192.168.1.250
        set extintf "wan1"
        set portforward enable
        set mappedip "172.31.31.254"
        set extport 25
        set mappedport 25
    next
end

■送信元インターフェイスのIPを使用するNATなので、
 Linux(メールサーバ側)からはFortigateのinternalのIPしか見えない。

$ sudo tcpdump -n -i eth2 tcp port 25 | sudo tee sample1.log > /dev/null 2>&1
$ sudo sed s/".* IP \| Flags.*"//g sample1.log | sort | uniq -c;echo
     17 172.31.31.252.54031 > 172.31.31.254.25:
     17 172.31.31.252.54032 > 172.31.31.254.25:
     17 172.31.31.252.54033 > 172.31.31.254.25:
     17 172.31.31.252.54034 > 172.31.31.254.25:
     17 172.31.31.252.54035 > 172.31.31.254.25:
     17 172.31.31.252.54036 > 172.31.31.254.25:
     17 172.31.31.252.54037 > 172.31.31.254.25:
      6 172.31.31.252.54038 > 172.31.31.254.25:
     11 172.31.31.254.25 > 172.31.31.252.54031:
     11 172.31.31.254.25 > 172.31.31.252.54032:
     13 172.31.31.254.25 > 172.31.31.252.54033:
     13 172.31.31.254.25 > 172.31.31.252.54034:
     11 172.31.31.254.25 > 172.31.31.252.54035:
     13 172.31.31.254.25 > 172.31.31.252.54036:
     13 172.31.31.254.25 > 172.31.31.252.54037:
      4 172.31.31.254.25 > 172.31.31.252.54038:

■送信元インターフェイスのIPを使用するNATなので、
 Linux(メールクライアント側)からはFortigateのVmailのIPしか見えない。

$ sudo tcpdump -n -i eth0 tcp port 25 | sudo tee sample2.log > /dev/null 2>&1
$ sudo sed s/".* IP \| Flags.*"//g sample2.log | sort | uniq -c;echo
     14 192.168.1.250.25 > 192.168.1.253.54193:
     14 192.168.1.250.25 > 192.168.1.253.54194:
     14 192.168.1.250.25 > 192.168.1.253.54195:
     15 192.168.1.250.25 > 192.168.1.253.54198:
     15 192.168.1.250.25 > 192.168.1.253.54199:
     15 192.168.1.250.25 > 192.168.1.253.54202:
     14 192.168.1.250.25 > 192.168.1.253.54205:
      5 192.168.1.250.25 > 192.168.1.253.54206:
      4 192.168.1.253.54192 > 192.168.1.250.25:
     16 192.168.1.253.54193 > 192.168.1.250.25:
     18 192.168.1.253.54194 > 192.168.1.250.25:
     19 192.168.1.253.54195 > 192.168.1.250.25:
     19 192.168.1.253.54198 > 192.168.1.250.25:
     19 192.168.1.253.54199 > 192.168.1.250.25:
     19 192.168.1.253.54202 > 192.168.1.250.25:
     19 192.168.1.253.54205 > 192.168.1.250.25:
      6 192.168.1.253.54206 > 192.168.1.250.25:

■Fortigateからはルール作成時のデフォルト、
 「NAT有効[送信インタフェースのアドレスを使用]」が効いている。

    192.168.1.253(mail client)
 -> 192.168.1.250(Vmail/extip/extport) -> 192.168.1.253(wan1)
 -> 172.31.31.252(internal)            -> 172.31.31.254(Vmail/mappedip/mappedport)
 -> 172.31.31.254(mail server)

$ script sample3.log;telnet 172.31.31.252
...
login:
Password:
...
# diagnose sniffer packet any 'tcp port 25'
# exit
$ exit
$ cat sample3.log | cut -c 10-48 | grep "^192.168.1..*.25\|^172.31.31..*.25" | sort -nr | uniq -c
      4 192.168.1.253.54117 -> 192.168.1.250.25
      8 192.168.1.253.54115 -> 192.168.1.250.25
      6 192.168.1.253.54114 -> 192.168.1.250.25
      9 192.168.1.253.54112 -> 192.168.1.250.25
      3 192.168.1.253.54110 -> 192.168.1.250.25
      3 192.168.1.250.25 -> 192.168.1.253.54117
      6 192.168.1.250.25 -> 192.168.1.253.54115
      4 192.168.1.250.25 -> 192.168.1.253.54114
      8 192.168.1.250.25 -> 192.168.1.253.54112
      2 192.168.1.250.25 -> 192.168.1.253.54110
     94 172.31.31.254.40939 -> 172.31.31.252.23
      3 172.31.31.254.25 -> 172.31.31.252.54117
      4 172.31.31.254.25 -> 172.31.31.252.54115
      2 172.31.31.254.25 -> 172.31.31.252.54114
      6 172.31.31.254.25 -> 172.31.31.252.54112
      1 172.31.31.254.25 -> 172.31.31.252.54110
      8 172.31.31.252.54117 -> 172.31.31.254.25
     14 172.31.31.252.54115 -> 172.31.31.254.25
     10 172.31.31.252.54114 -> 172.31.31.254.25
     16 172.31.31.252.54112 -> 172.31.31.254.25
      4 172.31.31.252.54110 -> 172.31.31.254.25
    210 172.31.31.252.23 -> 172.31.31.254.40939