Ipfirewall(即IPFW)是一个FreeBSD操作系统下的IP数据包过滤和通信记录工具。IPFW作为一个独立的运行时刻可装载模块,就包含在基本的FreeBSD安装包中。在rc.conf中含有语句“firewall_enable=YES”时,系统会动态地装载内核模块。
1、启用防火墙:firewall_enable="YES" 加入到 rc.conf 中并重新启动系统,eg
vim /etc/rc.conf firewall_enable="YES"
defaultrouter="192.168.0.1"
#ssh
sshd_enable="YES"
#fiewall
firewall_enable="YES"
firewall_script="/etc/ipfw.rules"
hostname="Aladin11.example.com"
ifconfig_em0="inet 192.168.0.80 netmask 255.255.255.0"
2、配置防火墙启动脚本 /etc/ipfw.rules
注意需要在rc.conf中启用防火墙启动脚本配置 加eg:
firewall_script="YES" #启动
firewall_script="/etc/ipfw.rules" #可自定义指定脚本路径
3、配置ipfw.rules
00200 check-state #暂时不清楚check-state和keep-state
00240 allow tcp from me to any keep-state
00260 allow udp from me to any keep-state
00300 allow ip from 192.168.0.0/24 to any keep-state #内网全通
00320 allow ip from 192.168.0.49 to any keep-state #允许单个IP访问
05999 allow tcp from 126.126.126.126,126.126.126.127 to any keep-state#允许多个IP访问
05000 allow icmp from 192.168.0.49 to me
05001 allow icmp from 192.168.0.45,192.168.0.50 to me #开启icmp
05002 allow icmp from any to any icmptypes 0,3,11 #暂时我也不知道,谁看到就给个评论回答下
06000 deny tcp from any to any dst-port 2500 in #拒绝连接我的2500端口
07000 deny tcp from any to any dst-port 3000-4000 in #拒绝连接我的3000到4000之间的端口
65535 deny ip from any to any #默认拒绝所有
4、防火墙服务管理
停止防火墙:ipfw disable firewall /etc/rc.d/ipfw stop
开启防火墙: ipfw enable firewall /etc/rc.d/ipfw start
重读防火墙策略 :source /etc/ipfw.rules
防火墙启动配置目录:vim /etc/rc.conf
防火墙策略脚本:vim /etc/ipfwrules.sh