FreeBSD ipfw App配置Examples

作者:佚名 上传时间:2019-05-15 版权申诉

Step # 1: Enabling IPFW

Open /etc/rc.conf file
# vi /etc/rc.conf
Append following settings:
firewall_enable="YES"
firewall_script="/usr/local/etc/ipfw.rules"

Save and close the file..

Step # 2 Write a Firewall Rule Script

You need to place a firewall rules in a script called /usr/local/etc/ipfw.rule :
# vi /usr/local/etc/ipfw.rules
Append following code:

IPF="ipfw -q add"
ipfw -q -f flush
#loopback
$IPF 10 allow all from any to any via lo0
$IPF 20 deny all from any to 127.0.0.0/8
$IPF 30 deny all from 127.0.0.0/8 to any
$IPF 40 deny tcp from any to any frag
# statefull
$IPF 50 check-state
$IPF 60 allow tcp from any to any established
$IPF 70 allow all from any to any out keep-state
$IPF 80 allow icmp from any to any
# open port ftp (20,21), ssh (22), mail (25)
# http (80), dns (53) etc
$IPF 110 allow tcp from any to any 21 in
$IPF 120 allow tcp from any to any 21 out
$IPF 130 allow tcp from any to any 22 in
$IPF 140 allow tcp from any to any 22 out
$IPF 150 allow tcp from any to any 25 in
$IPF 160 allow tcp from any to any 25 out
$IPF 170 allow udp from any to any 53 in
$IPF 175 allow tcp from any to any 53 in
$IPF 180 allow udp from any to any 53 out
$IPF 185 allow tcp from any to any 53 out
$IPF 200 allow tcp from any to any 80 in
$IPF 210 allow tcp from any to any 80 out
# deny and log everything
$IPF 500 deny log all from any to any

Save and close the file.

Step # 3: Start a firewall

You can reboot the box or you could reload these rules by entering on the command line.
# sh /usr/local/etc/ipfw.rules

Task: List all the rules in sequence

Type the following command:
# ipfw list

FreeBSD ipfw App配置Examples FreeBSD ipfw App配置Examples
IPF="ipfw -q add"
ipfw -q -f flush

#loopback
$IPF 10 allow from any to any via lo0
$IPF 20 deny all from any to 127.0.0.0/8
$IPF 30 deny all from 127.0.0.0/8 to any
$IPF 40 deny tcp from any to any frag

#statefull
$IPF 50 check-state
$IPF 60 allow tcp from any to any established
$IPF 70 allow all from any to any out keep-state
$IPF 80 allow icmp from any to any

#open port ftp(20,2),ssh(22),mail(25),http(80),dns(53)
$IPF 110 allow tcp from any to any 21 in
$IPF 120 allow tcp from any to any 21 out
$IPF 130 allow tcp from any to any 22 in
$IPF 140 allow tcp from any to any 22 out
$IPF 150 allow tcp from any to any 25 in
$IPF 160 allow tcp from any to any 25 out
$IPF 170 allow udp from any to any 53 in
$IPF 175 allow tcp from any to any 53 in
$IPF 180 allow udp from any to any 53 out
$IPF 185 allow tcp from any to any 53 out

$IPF 200 allow tcp from any to any 80 in
$IPF 210 allow tcp from any to any 80 out

#deny and log everything
$IPF 500 deny log all from any to any
View Code

修改/etc/rc.conf
Append following settings
firewall_enable="YES"
firewall_script="/usr/local/etc/ipfw.rules"

/etc/rc.d/ipfw restart

FreeBSD ipfw App配置Examples

相对针对debian及Centos 系统 的初始化一个系统的 时候设置的iptables shell (仅放行 22 (或是被修改为别的端口)and 80) 以建立的连接ping 等

FreeBSD ipfw App配置Examples FreeBSD ipfw App配置Examples
#!/bin/bash

iptables -F
iptables -X
/etc/rc.d/init.d/iptables save
service iptables restart


iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP

#iptables -A INPUT -p tcp --dport 22 -j ACCEPT
#iptables -A INPUT -p tcp --dport 25158 -j ACCEPT
iptables -A INPUT -p tcp --dport 19258 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p icmp -j ACCEPT
#from out hosts ping
#iptables -A OUTPUT -p icmp -j ACCEPT
#iptables -A INPUT -p icmp --icmp-type echo-reply -j ACCEPT 

# ping Internet 
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

#Dns 53
#iptables -A OUTPUT -p tcp --sport 53 -j ACCEPT
#iptables -A OUTPUT -p tcp --dport 53 -j ACCEPT
View Code

FreeBSD ipfw App配置Examples

免责申明:文章和图片全部来源于公开网络,如有侵权,请通知删除 server@dude6.com

用户评论
相关推荐
FreeBSD ipfw App配置Examples
Step # 1: Enabling IPFW Open /etc/rc.conf file # vi /etc/rc.conf Append
小规模DDoS用FreebsdIPFW搞定
曾经有一段时间不少用户反映有的服务器访问速度缓慢,甚至不能访问,检查后发现是受到了DDoS攻击(分布式拒绝服务攻击)。
DOC
38KB
2020-11-17 12:36
FreeBSD如何配置IPFW防火墙
IPFW是FreeBSD上一个非常强大的防火墙软件,通过一些简单的配置,可以帮助用户在FreeBSD系统上实现防火墙保护。本示例代码介绍如何在FreeBSD上安装并配置IPFW防火墙。1. 安装IP
FreeBSD 12.2
FreeBSD官方
2023-03-15 05:25
FreeBSD配置IPFW防火墙规则
IPFW(IP FireWall)是FreeBSD操作系统上的一种强大的防火墙工具,用于管理网络流量和设置规则以保护系统。本示例将介绍如何配置IPFW规则以允许或阻止特定的网络流量。# 在FreeB
FreeBSD 12.2
IPFW
2023-10-26 17:42
ipfw中文pdf
作者:来自chinaunix 的lsstarboy 已经习惯了用ipfw,觉得ipfw 其实很不错,但手册上的介绍有些少,所以想弄个中文的man。但 是由于本人英文和计算机都是半路出家,纯属个人爱好而
PDF
0B
2019-01-22 09:27
FreeBSD汉化配置
文档说明:整理 内容:FreeBSD汉化详细配置
DOC
0B
2019-01-02 16:31
freebsd配置namp
在freebsd下配置mysql,php,nginx环境
DOC
0B
2019-05-16 04:06
FreeBSD配置网络
FreeBSD是专门为大型服务器使用的linux操作系统.与redhat相比很多方面还有些许的不同.
TXT
0B
2019-09-23 15:36
FreeBSD网络配置
FreeBSD网络配置
DOCX
12KB
2021-04-16 18:05
FreeBSD下使用IPFW进行端口转发
IPFW是FreeBSD内置的一个防火墙工具,可以用于端口转发。通过对IPFW规则的配置,可以将来自某个端口的数据转发到指定的IP和端口。本示例代码演示了如何在FreeBSD上使用IPFW进行端口转发
FreeBSD 12.0
IPFW
2023-03-21 18:44