FreeBSD 下的 policy routing

昨天弄了一整個下午,差點被搞死...

FreeBSD 下想要依照 source ip 而決定 next hop 可以用 ipfw 或是 pf 達成。

ipfw 的設定會像這樣:

ipfw fwd 192.168.1.1 ip from 192.168.1.0/24 to not 192.168.1.0/24

而 pf 的設定會像這樣:

pass out quick route-to (em0 192.168.1.1) from 192.168.1.0/24 to ! 192.168.1.0/24 no state

最後面的 no state 很重要,找了一下午就是這個關鍵字而已 XD

會使用 pf 是因為現在都跑 FreeBSD amd64,用 FreeBSD 官方的 binary 都已經包含 SSE2 instructions,所以系統都用 freebsd-update 在管理。官方的 binary 並沒有把 ipfw 的 IPFIREWALL_FORWARD 編進去,所以不能用 ipfw fwd,花了一個下午才搞懂 pf 要怎麼設定...

記起來,以後應該會 google 到自己的文章...

3 thoughts on “FreeBSD 下的 policy routing”

  1. 鳥毅 says:

    請問大神,四位兄以前寫的
    http://freebsd.ntut.idv.tw/document/freebsd_pf_shellscript_loadbalance_redundant.html

    現在pf的設法有什麼不同的地方呢?

  2. Yu-lin Chang says:

    那是因為 7.x 變成預設有 state, 理由是查 state table 比跑完整個 rule 要快. 不過 state 比較像一個炸彈, 當 session 多到一個程度的時候, 系統資源沒用完 session table 就先炸了. 其實很多防火牆 (firewall appliance) 對於 UDP 抵抗能力很差也是因為 session. 例如 C 排的大爛貨 FxxM, 把 DNS Server 放它下面就會死很快.

  3. Randy says:

    FreeBSD 7.1 開始有支援 multiple routing tables
    http://www.freebsd.org/releases/7.1R/errata.html

Leave a Reply

Your email address will not be published. Required fields are marked *