文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>APF的安装与设置

APF的安装与设置

时间:2006-11-24  来源:zjzhouzg

APF的安装与设置

什么是APF?

APF: Advanced Policy Firewall,是 Rf-x Networks 出品的Linux环境下的软件防火墙。APF采用Linux系统默认的 iptables 规则。APF可以算是Linux中最出名的软件防火墙之一。

下载最新版的APF:

Code:

wget http://www.rfxnetworks.com/downloads/apf-current.tar.gz



解压:

Code:

tar -xzvf apf-current.tar.gz



进入APF目录:

Code:

cd apf-版本



安装!

Code:

./install.sh



安装完以后,开始配置APF:

Code:

nano -w /etc/apf/conf.apf



查找(ctrl + w) USE_DS="0" ,将之更改为 USE_DS="1" ;查找 USE_AD="0" ,将之更改为 USE_AD="1" 。

然后开始配置最主要的部分:端口。

以下提供 cPanel, Ensim 和 Plesk 的推荐配置。

Quote:

cPanel
IG_TCP_CPORTS="20,21,22,25,26,53,80,110,143,443,465,993,995,2082,2083,2086,2087,2095,2096"
IG_UDP_CPORTS="21,53,873"

EGF="1"
EG_TCP_CPORTS="21,22,25,26,27,37,43,53,80,110,113,443,465,873,2089"
EG_UDP_CPORTS="20,21,37,53,873"

 

Quote:

Ensim
IG_TCP_CPORTS="21,22,25,53,80,110,143,443,19638"
IG_UDP_CPORTS="53"

EGF=”1″
EG_TCP_CPORTS="21,22,25,53,80,110,443"
EG_UDP_CPORTS="20,21,53"

 

Quote:

Plesk
IG_TCP_CPORTS="20,21,22,25,53,80,110,143,443,465,993,995,8443"
IG_UDP_CPORTS="37,53,873"

EGF="1"
EG_TCP_CPORTS="20,21,22,25,53,37,43,80,113,443,465,873"
EG_UDP_CPORTS="53,873"



下面列出常规的端口,方便大家进行配置:

Quote:

21/tcp ftp
22/tcp ssh
25/tcp smtp
26/tcp 备用smtp端口
80/tcp http
110/tcp pop3
143/tcp imap
443/tcp https
993/tcp imaps
995/tcp pop3s
3306/tcp mysql
5432/tcp postgres
53/udp dns



配置完成后保存退出,并启动APF防火墙:

Code:

/usr/local/sbin/apf -s



请注意,此时防火墙是运行在调试模式,每五分钟重洗配置。这样能避免因为错误的配置而使服务器瘫痪。

确保配置无误后,再次进入配置文件(nano /etc/apf/conf.apf),将 DEVM="1" 更改为 DEVM="0" 。这样APF就会运行在常规模式下。

重启APF(/usr/local/sbin/apf -s)。

注意事项:如果你的Linux内核将iptables直接编译而非模块模式的话,请将配置文件中的 MONOKERN="0" 更改为 MONOKERN="1" 。

可选配置:
APF有个新的功能便是防止DoS攻击(/etc/apf/ad)。其日志文件保存在 /var/log/apfados_log 。

Code:

Enable SYSCTL_SYNCOOKIES in /etc/apf/conf.apf
Enable in /etc/apf/ad/conf.antidos DET_SF=1 and SF_TRIG=12 then do:
# cd /etc/apf/ad/
# ./antidos -a
may take awile to run; also there-after restart apache - may take a few runs of antidos and restarting apache -- you can also cron antidos -a.
To see bans you can check:
# tail /var/log/apfados_log



下面我们将配置APF使其遇到DoS后发送电子邮件给管理员。

打开配置文件:

Code:

nano -w /etc/apf/ad/conf.antidos



查找 [E-Mail Alerts] 。

Code:

CONAME="Your Company"

为你的网站或公司名称。

将 USR_ALERT="0" 更改为 USR_ALERT="0" ,从而使系统发送电子邮件。

USR="[email protected]" 为你的电子邮件地址。

保存并退出,重启APF(/usr/local/sbin/apf -r)。

另外,如果需要让系统每次重新启动后自动运行APF,则执行以下命令:

Code:

chkconfig --level 2345 apf on



需要去除自动启动的话:

Code:

chkconfig --del apf



最后,感谢 Rf-x Networks 给大家带来一款优秀的软件防火墙。也希望大家都能顺利的为自己的Linux架设起一道有效的安全屏障。

 

README


APF (Advanced Policy Firewall) - 0.9.6 [[email protected]]
Copyright (C) 1999-2004, R-fx Networks <[email protected]>
Copyright (C) 2004, Ryan MacDonald <[email protected]>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Contents:
1 ............. Introduction
2 ............. Configuration
2.1 ........... APF @ Boot
3 ............. Usage
4 ............. License
5 ............. Support

1) Introduction:
APF is a policy based iptables firewall system designed for ease of use and
configuration. It employs a subset of features to satisfy the veteran
Linux user and the novice alike. Packaged in tar.gz and RPM formats, APF is
ideal for deployment in any linux server environment.

Summary of features:
- simple & well commented configuration files
- layered firewall with independent ingress and egress filtering system
- uid based egress filtering via simple configuration variables
- global tcp/udp ports & icmp types configurtion
- configurable policies for each ip on the system with convenience vars
- prerouting rules for optimal network responce; TOS (type of service)
- icmp based rate limiting to prevent common icmp 'dos' abuses
- antidos subsystem to stop attacks before they become a significant threat
- dshield.org block list support to ban networks exhibiting suspicious activity
- advanced set of sysctl parameters for tcp/ip stack hardening
- advanced set of filter rules to remove undesired traffic
- advanced use of kernel features such as abort_on_overflow & tcp syncookies
- easy to use firewall managment script
- trust based rule files (allow/deny); with advanced syntax support
- 3rd party addon projects that compliment APF features
- and much more...

2) Configuration:
The configuration file for APF is for the most part, simple. It contains
many comments and should not be hard to navigate.

APF uses a policy rules structure; the main ethernet adapter [e.g: eth0]
is configurable via /etc/apf/main.rules, where-as alias adapters are
configurable via /etc/apf/vnet/1.1.1.1.rules [1.1.1.1 being the ip]. The
policy files are all structured to give custom rules presidence to the
conf.apf configurable ports that are global to all server ip's/adapters.

Required iptable modules that must be compiled-in or module compiled:
ip_conntrack
ip_conntrack_ftp
ip_conntrack_irc
iptable_filter
iptable_mangle
ip_tables
ipt_limit
ipt_LOG
ipt_multiport
ipt_REJECT
ipt_state
ipt_TOS

APF's main configuration file is located at:
/etc/apf/conf.apf

You will need to go through it and configure options you feel meet your
environment settings. Below is a definition breakdown of each feature in
the conf.apf file (except misc. options), listed in the format of Option
(config option and default value) followed by definition.

Option: DEVM="1"
Definition: APF comes default in dev. mode; meaning the firewall rules
will be flushed every 5 minutes. This is intended to prevent you from
being locked out of your system in the event of undesired results from APF.
Set the DEVM="1" option to zero (0) once APF is operating as desired.
Do NOT! leave this option enabled on a permanet basis, or you defeat
the purpose of using a firewall.

Option: LGATE_MAC=""
Definition: Local gateway mac address [optional]; when a value is present, only traffic
from the local gateway will be permitted. It is quite trivial to forge a MAC address and
as such this is provided as another layer of route verification.

Option: LGATE_LOG="0"
Definition: Log all forign gateway traffic. [0 = Disabled / 1 = Enabled]

Option: EN_VNET="0"
Definition: Enable virtual network subsystem; creats independent policy ruleset for each
ip on a system (pulls data from 'ip addr list') to /etc/apf/vnet/ip.rules; Template is
located in the vnet/ folder for rule files. This feature can reduce apf start/stop performance
and is not recommend for systems with more than 255 (/24) ip's. [0 = Disabled / 1 = Enabled]

Option: FWPATH="/etc/apf"
Definition: Absolute install path to APF; should not be changed usualy.

Option: IF="eth0"
Definition: Network interface visable too the Internet/Intranet.

Option: NET=`ifconfig $IF | grep inet | cut -d : -f 2 | cut -d \ -f 1`
Definition: IP Address that $IF holds; either define the IP in this value
or leave it as-is to autodetect.

Option: TIF=""
Definition: Trusted Network interface(s); all traffic on defined interface(s) will by-pass
ALL firewall rules (white space or comma seperated list; e.g: TIF="eth1 eth2").

Option: APF_LOG="/var/log/apf_log"
Definition: Location that APF should log status information to.

Option: DROP_LOG="1"
Definition: Control toggle to enable/disable netfilter kernel log chains.
These chains appear in the default syslog kernel log; /var/log/messages.

Option: LOG_RATE="60"
Definition: Limiting toggle to increase or decrease the max iptables
logging events per/minute. This should be left high but may be decreased
to preserve disk space and logging overhead.

Option: IG_TCP_CPORTS="22"
Definition: Common inbound ports; used to open TCP ports across all
ip addresses on an APF system. The values are comma seperated, port range
supported with underscore (_) seperator.
e.g: TCP_CPORTS="21,22,25,53,80,443,110,143,6000_7000"

Option: IG_UDP_CPORTS=""
Definition: Common inbound ports; used to open UDP ports across all
ip addresses on an APF system. The values are comma seperated, port range
supported with underscore (_) seperator.
e.g: UDP_CPORTS="53,1024_65535"

Option: EGF="0"
Definition: Toggle on or off the egress packet filtering; when off APF will
operate as traditional older versions did with just input filtering.
[0 = Disabled / 1 = Enabled]

Option: EG_TCP_CPORTS="22"
Definition: Common outbound ports; used to open TCP ports across all
ip addresses on an APF system. The values are comma seperated, port range
supported with underscore (_) seperator.
e.g: TCP_CPORTS="21,22,25,53,80,443,110,143,6000_7000"

Option: EG_UDP_CPORTS=""
Definition: Common outbound ports; used to open UDP ports across all
ip addresses on an APF system. The values are comma seperated, port range
supported with underscore (_) seperator.
e.g: UDP_CPORTS="53,1024_65535"

Option: USE_DS="0"
Definition: DShield.org's "block" list of top networks that have exhibited
suspicious activity. [0 = Disabled / 1 = Enabled]

Option: USE_AD="0"
Definition: Enable the inclusion of antidos issued bans when APF starts. If
enabled, /etc/apf/ad/conf.antidos is parsed for further antidos specific
options. Check README.antidos for more information.
[0 = Disabled / 1 = Enabled]

2.1) APF @ Boot:
To have APF start during boot you can do one of two options...
One either setup APF in the init system with chkconfig, as detailed
below:

chkconfig --add apf
chkconfig --level 345 apf on

Or, secondly you can add the following string too the bottom of the
/etc/rc.local file:

sh -c "/etc/apf/apf -s" &

It is not recommended that you use both of these startup methods together,
for most systems the init script via chkconfig should be fine.

3) Usage:
In all accounts APF is very simple to operate. The main 'apf' script has a few
operations built in to ease the use of your firewall.

usage: /usr/local/sbin/apf
-start Load firewall policies
-restart Flsuh & Load firewall
-flush Flush firewall
-list List chain rules
-status Firewall status

APF can also be started from the init script located at /etc/init.d/apf,
standard start|stop|restart arguments are accepted by this script. APF does not
operate as a service, as some conclude if there is an init script.

- Other Features
APF comes packaged with two trust based files for the inclusion of IP's. These
files allow two trust levels that are, allow and deny.

The allow and deny trust files are located at:
/etc/apf/allow_hosts.rules
/etc/apf/deny_hosts.rules

The format of these files are line-seperated addresses, IP masking is supported.
Example:
24.202.16.11
24.202.11.0/24

Advanced trust usage; The trust rules can be made in advanced format with 4
options (proto:flow:port:ip);
1) protocol: [packet protocol tcp/udp]
2) flow in/out: [packet direction, inbound or outbound]
3) s/d=port: [packet source or destination port]
4) s/d=ip(/xx) [packet source or destination address, masking supported]

Flow assumed as Input if not defined. Protocol assumed as TCP if not defined.
When defining rules with protocol, flow is required.

Syntax:
proto:flow:[s/d]=port:[s/d]=ip(/mask)
s - source , d - destination , flow - packet flow in/out

Examples:
inbound to destination port 22 from 24.202.16.11
tcp:in:d=22:s=24.202.16.11

outbound to destination port 23 to destination host 24.2.11.9
out:d=23:d=24.2.11.9

inbound to destination port 3306 from 24.202.11.0/24
d=3306:s=24.202.11.0/24

4) License:
APF is developed and supported on a volunteer basis by Ryan MacDonald
[[email protected]]

APF (Advanced policy firewall) is distributed under the GNU General Public
License (GPL) without restrictions on usage or redistribution. The APF
copyright statement, and GNU GPL, "COPYING.GPL" are included in the top-level
directory of the distribution. Credit must be given for derivative works as
required under GNU GPL.

5) Support:
All inquiries relating to APF should be directed to [email protected] and/or check
the APF homepage at:
http://www.r-fx.org/apf.php
相关阅读 更多 +
排行榜 更多 +
少女爱换装

少女爱换装

休闲益智 下载
百变英雄射击

百变英雄射击

飞行射击 下载
魔灵契约

魔灵契约

休闲益智 下载