2012-02-28

NAT 設定

網路架構
                                                                  eth0
                                                                    |
                                                                    |
HINET -----  ADSL Modem ------ ppp0 ----- eth1 (192.168.200.1)
                                                                    |
                                                                    |
                                                                  eth2 (192.168.100.1)
                                                                         \-->  192.168.100.0/24

  • /etc/network/interfaces
   1:  ################################

   2:  # ADSL which bind to eth1

   3:  ################################

   4:  auto dsl-provider

   5:  iface dsl-provider inet ppp

   6:  pre-up /sbin/ifconfig eth1 up # line maintained by pppoeconf

   7:  provider dsl-provider

   8:   

   9:  auto eth1

  10:  iface eth1 inet static

  11:  address 192.168.200.200

  12:  netmask 255.255.255.0

  13:   

  14:  auto eth2

  15:  iface eth2 inet static

  16:  address 192.168.100.1

  17:  netmask 255.255.255.0






eth2 不確定是否需增加 gateway設定





  • iptables

iptable rule 參考 iptable.rule

需注意的是 EXTIF介面為ppp0



打開ip 分享功能似乎在debian下運作並不成功,因此獨立至rc.local執行:
iptables -t nat -A POSTROUTING -s $innet -o $EXTIF -j MASQUERADE





若需要debian風格的啟動設定,可安裝iptables-persistent套件,

執行 invoke.rc iptables-persistent save可以將目前的iptable rules保留至/etc/iptables-persistent/iprules.v4 or v6