APF

What is APF (Advanced Policy Firewall)? APF FirewallAPF 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 format and RPM formats, make APF ideal for deployment in many server environments based on Linux. APF is developed and maintained by R-fx Networks: R-fx Networks – Internet Security Solutions – Projects » APF

This guide will show you how to install and configure APF firewall, one of the better known Linux firewalls available.10

Requirements:– Root SSH access to your server

Lets begin!Login to your server through SSH and su to the root user.

1. cd /root/downloads or another temporary folder where you store your files.

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

3. tar -xvzf apf-current.tar.gz

4. cd apf-0.9.5-1/ or whatever the latest version is.

5. Run the install file: ./install.shYou will receive a message saying it has been installed

6. Lets configure the firewall: pico /etc/apf/conf.apfWe will go over the general configuration to get your firewall running. This isn’t a complete detailed guide of every feature the firewall has. Look through the README and the configuration for an explanation of each feature.We like to use DShield.org’s “block” list of top networks that have exhibitedsuspicious activity.FIND: USE_DS=”0″CHANGE TO: USE_DS=”1″

9. After everything is fine, change the DEV optionStop the firewall from automatically clearing itself every 5 minutes from cron.We recommend changing this back to “0” after you’ve had a chance to ensure everything is working well and tested the server out.

pico /etc/apf/conf.apf

FIND: DEVM=”1″CHANGE TO: DEVM=”0″

10. Configure AntiDOS for APFRelatively new to APF is the new AntiDOS feature which can be found in: /etc/apf/adThe log file will be located at /var/log/apfados_log so you might want to make note of it and watch it!

pico /etc/apf/ad/conf.antidos

There are various things you might want to fiddle with but I’ll get the ones that will alert you by email.# [E-Mail Alerts]Under this heading we have the following:

# Organization name to display on outgoing alert emailsCONAME=”Your Company”Enter your company information name or server name..

# Send out user defined attack alerts [0=off,1=on]USR_ALERT=”0″Change this to 1 to get email alerts

# User for alerts to be mailed toUSR=”your@email.com”Enter your email address to receive the alerts

13. Denying IPs with APF Firewall (Blocking)Now that you have your shiny new firewall you probably want to block a host right, of course you do! With this new version APF now supports comments as well. There are a few ways you can block an IP, I’ll show you 2 of the easier methods.A) /etc/apf/apf -d IPHERE COMMENTHERENOSPACES> The -d flag means DENY the IP address> IPHERE is the IP address you wish to block> COMMENTSHERENOSPACES is obvious, add comments to why the IP is being blockedThese rules are loaded right away into the firewall, so they’re instantly active.Example:

./apf -d 185.14.157.123 TESTING

pico /etc/apf/deny_hosts.rules

Shows the following:

# added 185.14.157.123 on 08/23/05 01:25:55# TESTING185.14.157.123

B) pico /etc/apf/deny_hosts.rulesYou can then just add a new line and enter the IP you wish to block. Before this becomes active though you’ll need to reload the APF ruleset.

/etc/apf/apf -r

14. Allowing IPs with APF Firewall (Unblocking)

I know I know, you added an IP now you need it removed right away! You need to manually remove IPs that are blocked from deny_hosts.rules.A)pico /etc/apf/deny_hosts.rules

Find where the IP is listed and remove the line that has the IP.After this is done save the file and reload apf to make the new changes active.

/etc/apf/apf -r

B) If the IP isn’t already listed in deny_hosts.rules and you wish to allow it, this method adds the entry to allow_hosts.rules

/etc/apf/apf -a IPHERE COMMENTHERENOSPACES> The -a flag means ALLOW the IP address> IPHERE is the IP address you wish to allow> COMMENTSHERENOSPACES is obvious, add comments to why the IP is being removed These rules are loaded right away into the firewall, so they’re instantly active.Example: