作者 主題: Debian - 防火牆 script  (閱讀 11475 次)

0 會員 與 1 訪客 正在閱讀本文。

被騎上班的老

  • 區域板主
  • 活潑的大學生
  • *****
  • 文章數: 360
    • 檢視個人資料
Debian - 防火牆 script
« 於: 2012-03-01 08:59 »
最近發現一個設立防火牆的好東西叫做 arno-iptables-firewall,簡稱 AIF。我在本站搜尋沒有發現,所以特地貼上給大家參考參考。

http://rocky.eld.leidenuniv.nl/joomla/

這位 arno 先生的東西大多數用 shell script 寫成,簡直到了爐火純青的地步。想學 shell script 可以參考他的其他作品。

我是用 Debian 裝的,裝完之後回答一些問題就裝好了。就算沒回答好也沒關係,它的設定檔不到十行。

/etc/arno-iptables-firewall/debconf.cfg

DC_EXT_IF="eth0" 外部網卡
DC_EXT_IF_DHCP_IP=0 外網 IP 是不是 DHCP 取得
DC_OPEN_TCP="21,25 ... 其他你想開的埠"
DC_OPEN_UDP="53,111,138 ...其他你想開的埠 "
DC_INT_IF="eth1" 內部網卡
DC_NAT=1 要不要 nat
DC_INTERNAL_NET="192.168.100.0/24" 內網網段
DC_NAT_INTERNAL_NET="192.168.100.0/24" nat 網段
DC_OPEN_ICMP=0 給不給 ping

改完之後,service arno-iptables-firewall restart 就好了。

唯一的缺點是 ... 大哥,你取的 service 名稱也太長一點了吧!

被騎上班的老

  • 區域板主
  • 活潑的大學生
  • *****
  • 文章數: 360
    • 檢視個人資料
AIF 要封鎖特定 IP 也很簡單,不過 Debian Squeeze 版的 AIF 是 1.9 版,不是最新版 2.0.1 ,所以 /etc/arno-iptables-firewall/firewall.conf 這個檔案有些動作要作。


  • #BLOCK_HOSTS_FILE="/etc/arno-iptables-firewall/blocked-hosts"
    這一行的 "#" 要拿掉。
  • DISABLE_IPTABLES_BATCH=0
    這裡 0 要改為 1

以上兩點我是 google 來的,沒有在作者的 FAQ 裡面。

其他的作者本人的網站有 FAQ,

http://rocky.eld.leidenuniv.nl/joomla/index.php?option=com_content&view=article&id=50&Itemid=81

寫得很清楚,只是用英文寫的。

Q: What's the proper way to use the blocked hosts file?
A: Just put the hostname or IP of the host(s) you want to block in "/etc/iptables-blocked-hosts" (default location). You can use comments (starting with the #-character) but it can only be used when the whole line is a comment!

基本上只要把你要封鎖的 IP 寫在 "/etc/iptables-blocked-hosts" 一個 IP 一行。"#" 起頭的行為註解。寫完之後,重啟服務就好了。

要封鎖一個網段

Q: How can I use IP address ranges in the configuration file and/or the block hosts file?
A: Version 1.8 does NOT support IP ranges (except for the blocked hosts file), and never will. However starting with version 1.9, you can use class C IPv4 ranges like ie. 192.168.1.10-20, which would include all IP's between 192.168.1.10 en 192.168.1.20.

就像這樣啦,你打 192.168.1.10-20 ,它就封鎖 192.168.1.10 到 192.168.1.20.
有沒有簡單?

被騎上班的老

  • 區域板主
  • 活潑的大學生
  • *****
  • 文章數: 360
    • 檢視個人資料
Re: Debian - AIF + OpenVPN
« 回覆 #2 於: 2012-03-01 09:34 »
我是用 OpenVPN 連到公司內網,一開始我還在頭痛,這個要怎麼設啊?

結果這位 Arno 大哥的 FAQ 真的很神,

Q: How can I use OpenVPN with your firewall?
A: Here's how you should do it.
You need to configure the following variables:
  • TRUSTED_IF="tun+"
  • OPEN_UDP="1194"

首先,在 /etc/arno-iptables-firewall/custom-rules 加上TRUSTED_IF="tun+"
為甚麼要加在這呢?因為 debconf.cfg 會被設定的 script 重寫。如果你又重新設定時,這個設定 script 沒有寫到 vpn 的設定,所以會被蓋掉。

你寫在 custom-rules 就不會被蓋掉了。

至於 OPEN_UDP="1194" ,我是寫在 debconf.cfg 裡面,跟其他開放的 UDP port 寫在一起。

被騎上班的老

  • 區域板主
  • 活潑的大學生
  • *****
  • 文章數: 360
    • 檢視個人資料
Re: Debian - 防火牆 script
« 回覆 #3 於: 2012-03-01 09:41 »
昨天設好之後,今天早上就一大堆老鼠。我不是 Firewall 的專家,請專家看看這是不是攻擊?

   From 61.220.4.17 - 2 packets to udp(53)
   From 61.220.4.18 - 1 packet to udp(53)
   From 61.220.4.19 - 1 packet to udp(53)
   From 61.220.4.20 - 3 packets to udp(53)
   From 61.220.4.22 - 1 packet to udp(53)
   From 61.220.4.23 - 1 packet to udp(53)
   From 61.220.4.24 - 2 packets to udp(53)
   From 61.220.4.25 - 1 packet to udp(53)
   From 61.220.4.29 - 7 packets to udp(53)
   From 61.220.4.30 - 1 packet to udp(53)
   From 61.220.4.31 - 1 packet to udp(53)
   From 61.220.4.32 - 5 packets to udp(53)
   From 61.220.4.34 - 3 packets to udp(53)
   From 61.220.4.35 - 2 packets to udp(53)
   From 61.220.4.37 - 2 packets to udp(53)
   From 61.220.4.38 - 1 packet to udp(53)
   From 61.220.4.39 - 3 packets to udp(53)
   From 61.220.4.40 - 9 packets to udp(53)
   From 61.220.4.41 - 2 packets to udp(53)
   From 61.220.4.42 - 2 packets to udp(53)
   From 61.220.4.43 - 7 packets to udp(53)
   From 61.220.4.45 - 7 packets to udp(53)
   From 61.220.4.47 - 2 packets to udp(53)
   From 61.220.4.48 - 2 packets to udp(53)
   From 61.220.4.49 - 2 packets to udp(53)

twu2

  • 管理員
  • 俺是博士!
  • *****
  • 文章數: 5417
  • 性別: 男
    • 檢視個人資料
    • http://blog.teatime.com.tw/1
Re: Debian - 防火牆 script
« 回覆 #4 於: 2012-03-01 09:52 »
53 是 dns 用的.
如果你有架設 DNS (給外頭用的, 不是內部用的), 就會有外頭來的 query, 那... 應該是要打開這個才對.

被騎上班的老

  • 區域板主
  • 活潑的大學生
  • *****
  • 文章數: 360
    • 檢視個人資料
Re: Debian - 防火牆 script
« 回覆 #5 於: 2012-03-01 10:44 »
其實我也不是太瞭解,但是 TCP 53 跟 UDP 53 我都有開。
我設定的防火牆的方法是用 nmap 跟 nmap -sU 掃出自己有開的 port ,然後把這些加到 AIF 的 open 設定檔裡面。

令我起疑的是這一整個 C class網段,還有相鄰幾個 C class網段都有這個紀錄。我想我的網站應該沒有這麼紅,所以我才有這樣的疑惑。