標題所提到的問題在 lenny 以及更早的版本沒有標準解,一般 Google 到的解法是在 /etc/network/if-up.d/
裡面放一個 script,當介面起來的時候會跑 iptables-restore
把 iptables 的規則倒回去,這是「會動」的方法,但我不喜歡這種 hacking...
剛剛找到 iptables-persistent,在 squeeze 以及 sid 都可以裝,雖然沒有文件,但看了一下程式很快就可以理解他的用法。
在 apt-get install iptables-persistent
安裝完畢之後,理論上就會把 script 裝好,並且把目錄建好,接下來只要跑 iptables-save > /etc/iptables/rules
就可以把目前的 iptables 設定倒進去。
這個方式看起來會是比較好的作法...
有沒有RH系的解法? (拖走
沒打算用 RH 系的系統...
官方建議似乎就是 /etc/network/if-up.d/ 底下自己寫 script,非常彈性,但我覺得這樣太累了。也不喜歡用 iptables-persistent ,Debian 當初把它拿掉就是因為他不夠彈性。
我比較喜歡在 /etc/network/interfaces 中寫
iface eth0 inet static
....
up iptables-restore /etc/iptables/ssh_check.iptables
up iptables-restore --noflush /etc/iptables/broadcast_filter.iptables
up iptables-restore --noflush /etc/iptables/...
這樣可以把 iptables 不同設定分為多個檔案。而且可以彈性的配套到不同的 iface 設定。尤其用在網路環境常常變動的筆電特別適合。
how about shorewall?