IPFW防火墙快速入门指南

  • 发布时间:2021-11-22 09:05:21
  • 阅读次数:2081

IPFW是一款FreeBSD操作系统下的防火墙和包过滤器。这篇快速入门指南列出了一些关于IPFW的常用命令,以便系统管理员快速掌握IPFW的使用方法。

启用并运行IPFW:

# sysrc firewall_enable="YES"
# service ipfw start

列出全部有效规则:

# ipfw list

删除全部规则:

# ipfw -q -f flush

禁用并停止 IPFW:

# service ipfw stop
# sysrc firewall_enable="NO"

允许SSH,禁止其他访问(假设系统本身IP地址为192.0.2.123):

# ipfw -q add allow all from 192.0.2.123 to any out
# ipfw -q add deny log all from any to any out
# ipfw -q add allow tcp from any to any established
# ipfw -q add allow all from any to any frag
# ipfw -q add allow tcp from any to 192.0.2.123 22 setup
# ipfw -q add deny log all from any to any

永久模式和临时模式:

临时模式在执行命令后会立即生效,但是在服务器重启之后,设置则会失效。因此请使用永久模式保存重要的规则,请把规则代码保存到/etc/ipfw.conf文件中,并在/etc/rc.conf文件中增加如下代码。

firewall_enable="YES"
firewall_type="/etc/ipfw.conf"

规则代码文件/etc/ipfw.conf的内容如下。

add allow all from 192.0.2.123 to any out
add deny log all from any to any out
add allow tcp from any to any established
add allow all from any to any frag
add allow tcp from any to 192.0.2.123 22 setup
add deny log all from any to any

更多信息可参考IPFW官方文档。

https://www.freebsd.org/doc/handbook/firewalls-ipfw.html

【全文完】

< 上一篇:IPFilter防火墙快速入门指南 下一篇:nftables防火墙快速入门指南 >