!!!絕對不要遠(yuǎn)程調(diào)試防火墻配置!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
硬件需求:
雙網(wǎng)卡
內(nèi)存 > 64M
硬盤 > 1G
注:
NAT網(wǎng)關(guān)本身效率都很高,所以即使在配置很低的機(jī)器上運(yùn)行效率也是足夠的(仍建議盡可能多的增加內(nèi)存 > 256M),
如果需要記錄日志做分析,則會產(chǎn)生很大的I/O操作并占用大量硬盤空間,建議使用SCSI硬盤并做日志輪循。
假設(shè)2塊網(wǎng)卡分別按照以下網(wǎng)段設(shè)置:
內(nèi)網(wǎng)網(wǎng)卡IP地址:192.168.0.1/255.255.255.0 本身為網(wǎng)關(guān)
外網(wǎng)網(wǎng)卡IP地址:111.222.111.222/255.255.255.192 網(wǎng)關(guān):111.222.111.1
安全策略:
- 作為網(wǎng)關(guān),安全性非常重要,建議除了遠(yuǎn)程登錄用的SSH外,盡可能多的停掉所有不相關(guān)服務(wù)。
- 本安裝文檔只是最簡單的配置,沒有任何安全過濾規(guī)則,更多安全過濾規(guī)則需要根據(jù)實際情況補(bǔ)充。
FreeBSD 4.7上用IPFIREWALL做NAT網(wǎng)關(guān)
安裝FreeBSD系統(tǒng)時包含開發(fā)平臺(gcc工具等),因為內(nèi)核缺省不支持地址轉(zhuǎn)發(fā)和防火墻,所以需要重新編譯內(nèi)核。內(nèi)核編譯
========
由于內(nèi)核缺省不支持地址轉(zhuǎn)發(fā)和防火墻,所以需要重新編譯內(nèi)核:
#cd /usr/src/sys/i386/conf/
#cp GENERIC GATEWAY
#vi GATEWAY
修改后的內(nèi)核配置:修改了名稱和增加了IPFIREWALL的相關(guān)選項:
#diff GATEWAY GENERIC
25c25
< ident GATEWAY
---
> ident GENERIC
62,64d61 加入IPFIREWALL選項
< options IPFIREWALL
< options IPFIREWALL_VERBOSE
< options IPDIVERT
重新編譯:大約需要30分鐘左右
#/usr/sbin/config GATEWAY
#cd ../../compile/GATEWAY/
#make depend; make; make install
重啟機(jī)器一次,確認(rèn)新的KERNEL正常啟動。
修改rc.conf中的相關(guān)配置:假設(shè)內(nèi)網(wǎng)使用網(wǎng)卡fxp0,外網(wǎng)網(wǎng)卡使用xl0
###############################################
gateway_enable="YES"
ifconfig_fxp0="inet 192.168.0.1 netmask 255.255.255.0"
ifconfig_xl0="inet 111.222.111.222 netmask 255.255.255.0"
defaultrouter="111.222.111.1"
natd_enable="YES"
natd_interface="xl0"
firewall_enable="YES"
firewall_type="open"
###############################################
防火墻過濾規(guī)則設(shè)置
==================
ipfw的規(guī)則是通過運(yùn)行/etc/rc.firewall這個腳本生效的,rc.firewall腳本會檢查rc.conf中firewall_type等配置,然后根據(jù)firewall_type定義的模式"open" "client" "simple"等切換到rc.firewall中相應(yīng)部分執(zhí)行。
一個安全的防火墻本身是一個非常復(fù)雜的策略。為了方便配置,可以以rc.firewall文件為基礎(chǔ),在各種缺省模式的基礎(chǔ)上加入自己的規(guī)則。缺省最簡單的防火墻配置是在rc.conf里設(shè)置使用"open"模式,
注意:修改rc.firewall配置建議從最簡單的"open"模式開始,而且讓修改生效前,一定將舊的成功運(yùn)行的配置文件備份成rc.firewall.bak,便于以后的錯誤后恢復(fù),如果防火墻配置錯誤可能導(dǎo)致遠(yuǎn)程無法登陸,因此修改防火墻配置一定要在服務(wù)器終端界面進(jìn)行。
日志記錄
========
文件系統(tǒng)優(yōu)化: 使用異步文件系統(tǒng)提高性能async
vi /etc/fstab
/dev/da0s1f /tmp ufs rw,async 2 2
/dev/da0s1g /usr ufs rw,async 2 2
修改rc.firewall中"open"模式中的配置:打開記錄日志
#${fwcmd} add 65000 pass all from any to any
${fwcmd} add 65000 pass log all from any to any
修改/etc/newsyslog.conf 增加security日志的存儲上限從100k到 10000K
/var/log/security 600 10 10000 * Z
新的配置生效
============
修改防火墻配置后,可以用
#sh /etc/rc.firewall
讓新的配置生效
常用命令
========
ipfw list:顯示目前的配置規(guī)則:
#ipfw list
00050 divert 8668 ip from any to any via xl0
00100 allow ip from any to any via lo0
00200 deny ip from any to 127.0.0.0/8
00300 deny ip from 127.0.0.0/8 to any
65000 allow log ip from any to any
65535 deny ip from any to any
ipfw show:顯示各種規(guī)則的統(tǒng)計信息
# ipfw show
00050 1008267 632203534 divert 8668 ip from any to any via vr0
00100 0 0 allow ip from any to any via lo0
00200 0 0 deny ip from any to 127.0.0.0/8
00300 0 0 deny ip from 127.0.0.0/8 to any
65000 1782079 1257247553 allow ip from any to any
65535 36 31871 deny ip from any to any
RedHat 8上用iptables做NAT網(wǎng)關(guān)
將下列內(nèi)容加入/etc/rc.local文件中:eth0綁內(nèi)網(wǎng)IP eth1綁外網(wǎng)IP################
echo 1 > /proc/sys/net/ipv4/ip_forward
/sbin/modprobe ip_tables
/sbin/modprobe iptable_filter
/sbin/modprobe iptable_nat
/sbin/modprobe ip_conntrack
/sbin/modprobe ip_conntrack_ftp
/sbin/modprobe ip_nat_ftp
/sbin/iptables --flush INPUT
/sbin/iptables --flush FORWARD
/sbin/iptables --flush POSTROUTING --table nat
/sbin/iptables --policy FORWARD DROP
/sbin/iptables --table nat --append POSTROUTING --out-interface eth1 --source 192.168.0.0/24 --jump MASQUERADE
/sbin/iptables --append FORWARD --in-interface eth1 --match state --state ESTABLISHED,RELATED --jump ACCEPT
/sbin/iptables --append FORWARD --source 192.168.0.0/24 --jump ACCEPT
################
iptables --list查看過濾表
參考資料:
王波:FreeBSD使用大全
http://tech.sina.com.cn/focus/FreeBSD/2000-01-19/196.shtml
FreeBSD IPFW-HOWTO
http://www./HOWTO/Ipfw-HOWTO
ipfw的命令參考:
http://www./phpMan.php/man/ipfw
《linux下如何用iptables做NAT上網(wǎng)》原文作者:upkill98
http://it./newSite/Channels/Safety/SysSafety/Safe_Unix/200211/06-094108327.htm
IPTables的日志分析:
http://www./Software/Log_Analyzers/
iptqlog
軟盤防火墻制作:
http://www./floppyfw
http://directory.google.com/Top/Computers/Software/Operating_Systems/Linux/Distributions/Tiny/Floppy_Sized/




